diff --git a/wrap/Module.cpp b/wrap/Module.cpp index bc2bc5afe..2b6c6ffe2 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -164,7 +164,7 @@ Module::Module(const string& interfacePath, namespace_name_p[assign_a(namespaces_parent, namespaces)][push_back_a(namespaces)] // save previous state >> ch_p('{') >> *(class_p | namespace_p | comments_p) >> - str_p("}//\\namespace") // end namespace, avoid confusion with classes + str_p("}///\\namespace") // end namespace, avoid confusion with classes [assign_a(namespaces, namespaces_parent)]; // switch back to parent namespace Rule module_content_p = comments_p | class_p | namespace_p ; @@ -205,15 +205,15 @@ Module::Module(const string& interfacePath, throw ParseFailed(info.length); } - if (!namespaces.empty()) { - cout << "Namespaces not closed, remaining: "; - BOOST_FOREACH(const string& ns, namespaces) - cout << ns << " "; - cout << endl; - } - - if (!cls.name.empty()) - cout << "\nClass name: " << cls.name << endl; +// if (!namespaces.empty()) { +// cout << "Namespaces not closed, remaining: "; +// BOOST_FOREACH(const string& ns, namespaces) +// cout << ns << " "; +// cout << endl; +// } +// +// if (!cls.name.empty()) +// cout << "\nClass name: " << cls.name << endl; } /* ************************************************************************* */ diff --git a/wrap/tests/geometry.h b/wrap/tests/geometry.h index c6d770e5e..b8427faa3 100644 --- a/wrap/tests/geometry.h +++ b/wrap/tests/geometry.h @@ -9,6 +9,8 @@ class Point2 { VectorNotEigen vectorConfusion(); }; +namespace ns_outer { + namespace ns_inner { class Point3 { @@ -23,7 +25,7 @@ class Point3 { // another comment // NOTE: you *must* end namespaces as follows: -}//\namespace +}///\namespace // another comment @@ -74,6 +76,8 @@ class Test { // even more comments at the end! }; +}///\namespace + // comments at the end! // even more comments at the end! diff --git a/wrap/tests/testNamespaces.h b/wrap/tests/testNamespaces.h new file mode 100644 index 000000000..59c80201c --- /dev/null +++ b/wrap/tests/testNamespaces.h @@ -0,0 +1,31 @@ +/** + * This is a wrap header to verify permutations on namespaces + */ + +namespace ns1 { + +class ClassA { + +}; + +class ClassB { + +}; + +}///\namespace + +namespace ns2 { + +class ClassA { +}; + +namespace ns3 { + +class ClassB { +}; + +}///\namespace + +}///\namespace + + diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index e49fb88d9..9241a8ec6 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -52,16 +52,14 @@ TEST( wrap, check_exception ) { string path = topdir + "/wrap/tests"; Module module(path.c_str(), "testWrap1",enable_verbose); -// CHECK_EXCEPTION(module.matlab_code("actual", "", "mexa64", "-O5"), DependencyMissing); + CHECK_EXCEPTION(module.matlab_code("actual", "", "mexa64", "-O5"), DependencyMissing); } /* ************************************************************************* */ TEST( wrap, parse ) { string header_path = topdir + "/wrap/tests"; - Module module(header_path.c_str(), "geometry",enable_verbose); EXPECT_LONGS_EQUAL(3, module.classes.size()); - string path = topdir + "/wrap"; // check first class, Point2 { @@ -80,8 +78,9 @@ TEST( wrap, parse ) { EXPECT_LONGS_EQUAL(1, cls.constructors.size()); EXPECT_LONGS_EQUAL(1, cls.methods.size()); EXPECT_LONGS_EQUAL(2, cls.static_methods.size()); - EXPECT_LONGS_EQUAL(1, cls.namespaces.size()); - EXPECT(assert_equal("ns_inner", cls.namespaces.front())); + EXPECT_LONGS_EQUAL(2, cls.namespaces.size()); + EXPECT(assert_equal("ns_outer", cls.namespaces.front())); + EXPECT(assert_equal("ns_inner", cls.namespaces.back())); // first constructor takes 3 doubles Constructor c1 = cls.constructors.front(); @@ -109,6 +108,8 @@ TEST( wrap, parse ) { EXPECT_LONGS_EQUAL( 2, testCls.constructors.size()); EXPECT_LONGS_EQUAL(19, testCls.methods.size()); EXPECT_LONGS_EQUAL( 0, testCls.static_methods.size()); + EXPECT_LONGS_EQUAL( 1, testCls.namespaces.size()); + EXPECT(assert_equal("ns_outer", testCls.namespaces.front())); // function to parse: pair return_pair (Vector v, Matrix A) const; Method m2 = testCls.methods.front(); @@ -118,6 +119,34 @@ TEST( wrap, parse ) { } } +/* ************************************************************************* */ +TEST( wrap, parse_namespaces ) { + string header_path = topdir + "/wrap/tests"; + Module module(header_path.c_str(), "testNamespaces",enable_verbose); + EXPECT_LONGS_EQUAL(4, module.classes.size()); + + Class cls1 = module.classes.at(0); + EXPECT(assert_equal("ClassA", cls1.name)); + EXPECT_LONGS_EQUAL(1, cls1.namespaces.size()); + EXPECT(assert_equal("ns1", cls1.namespaces.front())); + + Class cls2 = module.classes.at(1); + EXPECT(assert_equal("ClassB", cls2.name)); + EXPECT_LONGS_EQUAL(1, cls2.namespaces.size()); + EXPECT(assert_equal("ns1", cls2.namespaces.front())); + + Class cls3 = module.classes.at(2); + EXPECT(assert_equal("ClassA", cls3.name)); + EXPECT_LONGS_EQUAL(1, cls3.namespaces.size()); + EXPECT(assert_equal("ns2", cls3.namespaces.front())); + + Class cls4 = module.classes.at(3); + EXPECT(assert_equal("ClassB", cls4.name)); + EXPECT_LONGS_EQUAL(2, cls4.namespaces.size()); + EXPECT(assert_equal("ns2", cls4.namespaces.front())); + EXPECT(assert_equal("ns3", cls4.namespaces.back())); +} + /* ************************************************************************* */ TEST( wrap, matlab_code ) { // Parse into class object