8 #define STATIC_ARRAY_SIZE(array) (sizeof((array))/sizeof((array[0])))
13 Context ctx = Context::Data();
15 const char* const ROUNDTRIP_TESTS[] = {
23 "> + CMPD1.CMPD2 > ~",
24 "> + CMPD1.CMPD2 CMPD3.CMPD4 > ~",
25 "+ CMPD1 CMPD2 ~ CMPD3 + CMPD4 > CMPD5 > ~"
30 static Complex_Selector* createComplexSelector(std::string src) {
31 std::string temp(src);
33 return (*Parser::from_c_str(temp.c_str(), ctx, "", Position()).parse_selector_list())[0];
37 void roundtripTest(const char* toTest) {
39 // Create the initial selector
41 Complex_Selector* pOrigSelector = NULL;
43 pOrigSelector = createComplexSelector(toTest);
46 std::string expected(pOrigSelector ? pOrigSelector->to_string() : "NULL");
49 // Roundtrip the selector into a node and back
51 Node node = complexSelectorToNode(pOrigSelector, ctx);
53 std::stringstream nodeStringStream;
54 nodeStringStream << node;
55 std::string nodeString = nodeStringStream.str();
56 cout << "ASNODE: " << node << endl;
58 Complex_Selector* pNewSelector = nodeToComplexSelector(node, ctx);
62 std::string result(pNewSelector ? pNewSelector->to_string() : "NULL");
64 cout << "SELECTOR: " << expected << endl;
65 cout << "NEW SELECTOR: " << result << endl;
68 // Test that they are equal using the equality operator
70 assert( (!pOrigSelector && !pNewSelector ) || (pOrigSelector && pNewSelector) );
72 assert( *pOrigSelector == *pNewSelector );
76 // Test that they are equal by comparing the string versions of the selectors
78 assert(expected == result);
84 for (int index = 0; index < STATIC_ARRAY_SIZE(ROUNDTRIP_TESTS); index++) {
85 const char* const toTest = ROUNDTRIP_TESTS[index];
86 cout << "\nINPUT STRING: " << (toTest ? toTest : "NULL") << endl;
87 roundtripTest(toTest);
90 cout << "\nTesting Done.\n";