Added more tests for namespaces, parser now supports nested namespaces
parent
1aecb58807
commit
90e9426d9c
|
|
@ -164,7 +164,7 @@ Module::Module(const string& interfacePath,
|
||||||
namespace_name_p[assign_a(namespaces_parent, namespaces)][push_back_a(namespaces)] // save previous state
|
namespace_name_p[assign_a(namespaces_parent, namespaces)][push_back_a(namespaces)] // save previous state
|
||||||
>> ch_p('{') >>
|
>> ch_p('{') >>
|
||||||
*(class_p | namespace_p | comments_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
|
[assign_a(namespaces, namespaces_parent)]; // switch back to parent namespace
|
||||||
|
|
||||||
Rule module_content_p = comments_p | class_p | namespace_p ;
|
Rule module_content_p = comments_p | class_p | namespace_p ;
|
||||||
|
|
@ -205,15 +205,15 @@ Module::Module(const string& interfacePath,
|
||||||
throw ParseFailed(info.length);
|
throw ParseFailed(info.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!namespaces.empty()) {
|
// if (!namespaces.empty()) {
|
||||||
cout << "Namespaces not closed, remaining: ";
|
// cout << "Namespaces not closed, remaining: ";
|
||||||
BOOST_FOREACH(const string& ns, namespaces)
|
// BOOST_FOREACH(const string& ns, namespaces)
|
||||||
cout << ns << " ";
|
// cout << ns << " ";
|
||||||
cout << endl;
|
// cout << endl;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (!cls.name.empty())
|
// if (!cls.name.empty())
|
||||||
cout << "\nClass name: " << cls.name << endl;
|
// cout << "\nClass name: " << cls.name << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,8 @@ class Point2 {
|
||||||
VectorNotEigen vectorConfusion();
|
VectorNotEigen vectorConfusion();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace ns_outer {
|
||||||
|
|
||||||
namespace ns_inner {
|
namespace ns_inner {
|
||||||
|
|
||||||
class Point3 {
|
class Point3 {
|
||||||
|
|
@ -23,7 +25,7 @@ class Point3 {
|
||||||
// another comment
|
// another comment
|
||||||
|
|
||||||
// NOTE: you *must* end namespaces as follows:
|
// NOTE: you *must* end namespaces as follows:
|
||||||
}//\namespace
|
}///\namespace
|
||||||
|
|
||||||
// another comment
|
// another comment
|
||||||
|
|
||||||
|
|
@ -74,6 +76,8 @@ class Test {
|
||||||
// even more comments at the end!
|
// even more comments at the end!
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}///\namespace
|
||||||
|
|
||||||
// comments at the end!
|
// comments at the end!
|
||||||
|
|
||||||
// even more comments at the end!
|
// even more comments at the end!
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -52,16 +52,14 @@ TEST( wrap, check_exception ) {
|
||||||
|
|
||||||
string path = topdir + "/wrap/tests";
|
string path = topdir + "/wrap/tests";
|
||||||
Module module(path.c_str(), "testWrap1",enable_verbose);
|
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 ) {
|
TEST( wrap, parse ) {
|
||||||
string header_path = topdir + "/wrap/tests";
|
string header_path = topdir + "/wrap/tests";
|
||||||
|
|
||||||
Module module(header_path.c_str(), "geometry",enable_verbose);
|
Module module(header_path.c_str(), "geometry",enable_verbose);
|
||||||
EXPECT_LONGS_EQUAL(3, module.classes.size());
|
EXPECT_LONGS_EQUAL(3, module.classes.size());
|
||||||
string path = topdir + "/wrap";
|
|
||||||
|
|
||||||
// check first class, Point2
|
// check first class, Point2
|
||||||
{
|
{
|
||||||
|
|
@ -80,8 +78,9 @@ TEST( wrap, parse ) {
|
||||||
EXPECT_LONGS_EQUAL(1, cls.constructors.size());
|
EXPECT_LONGS_EQUAL(1, cls.constructors.size());
|
||||||
EXPECT_LONGS_EQUAL(1, cls.methods.size());
|
EXPECT_LONGS_EQUAL(1, cls.methods.size());
|
||||||
EXPECT_LONGS_EQUAL(2, cls.static_methods.size());
|
EXPECT_LONGS_EQUAL(2, cls.static_methods.size());
|
||||||
EXPECT_LONGS_EQUAL(1, cls.namespaces.size());
|
EXPECT_LONGS_EQUAL(2, cls.namespaces.size());
|
||||||
EXPECT(assert_equal("ns_inner", cls.namespaces.front()));
|
EXPECT(assert_equal("ns_outer", cls.namespaces.front()));
|
||||||
|
EXPECT(assert_equal("ns_inner", cls.namespaces.back()));
|
||||||
|
|
||||||
// first constructor takes 3 doubles
|
// first constructor takes 3 doubles
|
||||||
Constructor c1 = cls.constructors.front();
|
Constructor c1 = cls.constructors.front();
|
||||||
|
|
@ -109,6 +108,8 @@ TEST( wrap, parse ) {
|
||||||
EXPECT_LONGS_EQUAL( 2, testCls.constructors.size());
|
EXPECT_LONGS_EQUAL( 2, testCls.constructors.size());
|
||||||
EXPECT_LONGS_EQUAL(19, testCls.methods.size());
|
EXPECT_LONGS_EQUAL(19, testCls.methods.size());
|
||||||
EXPECT_LONGS_EQUAL( 0, testCls.static_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<Vector,Matrix> return_pair (Vector v, Matrix A) const;
|
// function to parse: pair<Vector,Matrix> return_pair (Vector v, Matrix A) const;
|
||||||
Method m2 = testCls.methods.front();
|
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 ) {
|
TEST( wrap, matlab_code ) {
|
||||||
// Parse into class object
|
// Parse into class object
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue