First non-passing grammar test
parent
6981a1229d
commit
12791737e0
|
@ -46,7 +46,7 @@ TEST( Class, OverloadingMethod ) {
|
||||||
EXPECT_LONGS_EQUAL(1, cls.method(name).nrOverloads());
|
EXPECT_LONGS_EQUAL(1, cls.method(name).nrOverloads());
|
||||||
|
|
||||||
// add an overload w different argument list
|
// add an overload w different argument list
|
||||||
args.push_back(Argument(Qualified("Vector",Qualified::EIGEN),"v"));
|
args.push_back(Argument(Qualified("Vector", Qualified::EIGEN), "v"));
|
||||||
cls.addMethod(verbose, is_const, name, args, retVal, tmplate);
|
cls.addMethod(verbose, is_const, name, args, retVal, tmplate);
|
||||||
EXPECT_LONGS_EQUAL(1, cls.nrMethods());
|
EXPECT_LONGS_EQUAL(1, cls.nrMethods());
|
||||||
EXPECT_LONGS_EQUAL(2, cls.method(name).nrOverloads());
|
EXPECT_LONGS_EQUAL(2, cls.method(name).nrOverloads());
|
||||||
|
@ -82,6 +82,112 @@ TEST( Class, TemplatedMethods ) {
|
||||||
EXPECT(cls.exists(name+"Point3"));
|
EXPECT(cls.exists(name+"Point3"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
|
||||||
|
struct ClassGrammar: public classic::grammar<ClassGrammar> {
|
||||||
|
|
||||||
|
Class& result_; ///< successful parse will be placed in here
|
||||||
|
|
||||||
|
/// Construct type grammar and specify where result is placed
|
||||||
|
ClassGrammar(Class& result) :
|
||||||
|
result_(result) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Definition of type grammar
|
||||||
|
template<typename ScannerT>
|
||||||
|
struct definition {
|
||||||
|
|
||||||
|
classic::rule<ScannerT> class_p;
|
||||||
|
|
||||||
|
definition(ClassGrammar const& self) {
|
||||||
|
using namespace classic;
|
||||||
|
|
||||||
|
class_p = str_p("class");
|
||||||
|
}
|
||||||
|
|
||||||
|
classic::rule<ScannerT> const& start() const {
|
||||||
|
return class_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
// ClassGrammar
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST( wrap, Small ) {
|
||||||
|
|
||||||
|
using classic::space_p;
|
||||||
|
|
||||||
|
// Create type grammar that will place result in cls
|
||||||
|
Class cls;
|
||||||
|
ClassGrammar g(cls);
|
||||||
|
|
||||||
|
string markup(
|
||||||
|
string("class Point2 { \n") +
|
||||||
|
string(" double x() const; \n") + // Method 1
|
||||||
|
string(" Matrix returnMatrix() const; \n") + // Method 2
|
||||||
|
string(" Point2 returnPoint2() const; \n") + // Method 3
|
||||||
|
string(" static Vector returnVector(); \n") + // Static Method 1
|
||||||
|
string("};\n"));
|
||||||
|
|
||||||
|
EXPECT(parse(markup.c_str(), g, space_p).full);
|
||||||
|
|
||||||
|
// check return types
|
||||||
|
EXPECT(assert_equal("Point2", cls.name()));
|
||||||
|
EXPECT(!cls.isVirtual);
|
||||||
|
EXPECT(cls.namespaces().empty());
|
||||||
|
LONGS_EQUAL(3, cls.nrMethods());
|
||||||
|
LONGS_EQUAL(1, cls.static_methods.size());
|
||||||
|
|
||||||
|
// Method 1
|
||||||
|
Method m1 = cls.method("x");
|
||||||
|
EXPECT(assert_equal("x", m1.name()));
|
||||||
|
EXPECT(m1.isConst());
|
||||||
|
LONGS_EQUAL(1, m1.nrOverloads());
|
||||||
|
|
||||||
|
ReturnValue rv1 = m1.returnValue(0);
|
||||||
|
EXPECT(!rv1.isPair);
|
||||||
|
EXPECT(!rv1.type1.isPtr);
|
||||||
|
EXPECT(assert_equal("double", rv1.type1.name()));
|
||||||
|
EXPECT_LONGS_EQUAL(ReturnType::BASIS, rv1.type1.category);
|
||||||
|
|
||||||
|
// Method 2
|
||||||
|
Method m2 = cls.method("returnMatrix");
|
||||||
|
EXPECT(assert_equal("returnMatrix", m2.name()));
|
||||||
|
EXPECT(m2.isConst());
|
||||||
|
LONGS_EQUAL(1, m2.nrOverloads());
|
||||||
|
|
||||||
|
ReturnValue rv2 = m2.returnValue(0);
|
||||||
|
EXPECT(!rv2.isPair);
|
||||||
|
EXPECT(!rv2.type1.isPtr);
|
||||||
|
EXPECT(assert_equal("Matrix", rv2.type1.name()));
|
||||||
|
EXPECT_LONGS_EQUAL(ReturnType::EIGEN, rv2.type1.category);
|
||||||
|
|
||||||
|
// Method 3
|
||||||
|
Method m3 = cls.method("returnPoint2");
|
||||||
|
EXPECT(assert_equal("returnPoint2", m3.name()));
|
||||||
|
EXPECT(m3.isConst());
|
||||||
|
LONGS_EQUAL(1, m3.nrOverloads());
|
||||||
|
|
||||||
|
ReturnValue rv3 = m3.returnValue(0);
|
||||||
|
EXPECT(!rv3.isPair);
|
||||||
|
EXPECT(!rv3.type1.isPtr);
|
||||||
|
EXPECT(assert_equal("Point2", rv3.type1.name()));
|
||||||
|
EXPECT_LONGS_EQUAL(ReturnType::CLASS, rv3.type1.category);
|
||||||
|
|
||||||
|
// Static Method 1
|
||||||
|
// static Vector returnVector();
|
||||||
|
StaticMethod sm1 = cls.static_methods.at("returnVector");
|
||||||
|
EXPECT(assert_equal("returnVector", sm1.name()));
|
||||||
|
LONGS_EQUAL(1, sm1.nrOverloads());
|
||||||
|
|
||||||
|
ReturnValue rv4 = sm1.returnValue(0);
|
||||||
|
EXPECT(!rv4.isPair);
|
||||||
|
EXPECT(!rv4.type1.isPtr);
|
||||||
|
EXPECT(assert_equal("Vector", rv4.type1.name()));
|
||||||
|
EXPECT_LONGS_EQUAL(ReturnType::EIGEN, rv4.type1.category);
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
int main() {
|
int main() {
|
||||||
TestResult tr;
|
TestResult tr;
|
||||||
|
|
Loading…
Reference in New Issue