extend grammar for XSLT matches - added some parse tests

This commit is contained in:
jez_higgins 2005-12-16 19:09:57 +00:00
parent be0dcae896
commit 9485917c42
3 changed files with 148 additions and 0 deletions

113
test/XPath/match_test.hpp Normal file
View file

@ -0,0 +1,113 @@
#ifndef XPATHIC_MATCH_TEST_HPP
#define XPATHIC_MATCH_TEST_HPP
#include "../CppUnit/framework/TestCase.h"
#include "../CppUnit/framework/TestSuite.h"
#include "../CppUnit/framework/TestCaller.h"
#include <XPath/XPath.hpp>
#include <DOM/Simple/DOMImplementation.h>
template<class string_type, class string_adaptor>
class MatchTest : public TestCase
{
Arabica::XPath::XPath<string_type> parser;
typedef string_adaptor SA;
public:
MatchTest(std::string name) : TestCase(name)
{
} // MatchTest
void setUp()
{
} // setUp
void testParse()
{
using namespace Arabica::XPath;
assertTrue(compileThis("/"));
assertTrue(compileThis("/element"));
assertTrue(compileThis("//element"));
assertTrue(compileThis("node()"));
assertTrue(compileThis("text()"));
assertTrue(compileThis("element"));
assertTrue(compileThis("element/child"));
assertTrue(compileThis("/element/child"));
assertTrue(compileThis("//element/child"));
assertTrue(compileThis("/element//child"));
assertTrue(compileThis("//element//child"));
assertTrue(compileThis("element/child/child"));
assertTrue(compileThis("/element/child/child"));
assertTrue(compileThis("//element/child/child"));
assertTrue(compileThis("/element//child/child"));
assertTrue(compileThis("//element//child/child"));
assertTrue(compileThis("//element//child//child"));
assertTrue(compileThis("element[@ref]"));
assertTrue(compileThis("element[@type]|element[complexType]|attribute"));
assertTrue(compileThis("node()|@*"));
assertTrue(compileThis("hello"));
assertTrue(compileThis("@hello"));
assertTrue(compileThis("child::hello"));
assertTrue(compileThis("attribute::hello"));
assertTrue(compileThis("node()|attribute::*"));
} // testParse
void testParseFails()
{
std::cerr << "\n\n\ntestParseFails";
using namespace Arabica::XPath;
assertTrue(dontCompileThis("boolean(../hello)"));
assertTrue(dontCompileThis("../hello"));
assertTrue(dontCompileThis("following-sibling::hello"));
assertTrue(dontCompileThis("descendant::hello"));
assertTrue(dontCompileThis("ancestor-or-self::hello"));
assertTrue(dontCompileThis("///"));
assertTrue(dontCompileThis("test///test"));
assertTrue(dontCompileThis("descendant-or-self::element"));
assertTrue(dontCompileThis("//element/following-sibling::trousers"));
} // testParseFails
bool dontCompileThis(const char* path)
{
try {
parser.compile_match(SA::construct_from_utf8(path));
return false;
}
catch(const Arabica::XPath::SyntaxException& ex) {
std::cerr << ex.what() << std::endl;
}
return true;
} // dontCompileThis
bool compileThis(const char* path)
{
try {
parser.compile_match(SA::construct_from_utf8(path));
return true;
}
catch(const Arabica::XPath::UnsupportedException&) {
return true;
}
catch(const Arabica::XPath::SyntaxException& ex) {
std::cerr << ex.what() << std::endl;
}
return false;
} // compileThis
}; // class MatchTest
template<class string_type, class string_adaptor>
TestSuite* MatchTest_suite()
{
TestSuite *suiteOfTests = new TestSuite;
suiteOfTests->addTest(new TestCaller<MatchTest<string_type, string_adaptor> >("testParse", &MatchTest<string_type, string_adaptor>::testParse));
suiteOfTests->addTest(new TestCaller<MatchTest<string_type, string_adaptor> >("testParseFail", &MatchTest<string_type, string_adaptor>::testParseFails));
return suiteOfTests;
} // MatchTest_suite
#endif

View file

@ -15,6 +15,7 @@
#include "step_test.hpp"
#include "execute_test.hpp"
#include "expression_test.hpp"
#include "match_test.hpp"
template<class string_type, class string_adaptor>
@ -32,6 +33,7 @@ void XPath_test_suite(int argc, const char** argv)
runner.addTest("ParseTest", ParseTest_suite<string_type, string_adaptor>());
runner.addTest("ExecuteTest", ExecuteTest_suite<string_type, string_adaptor>());
runner.addTest("ExpressionTest", ExpressionTest_suite<string_type, string_adaptor>());
runner.addTest("MatchTest", MatchTest_suite<string_type, string_adaptor>());
runner.run(argc, argv);
} // XPath_test_suite

View file

@ -133,6 +133,39 @@
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\arithmetic_test.hpp">
</File>
<File
RelativePath=".\axis_enumerator_test.hpp">
</File>
<File
RelativePath=".\execute_test.hpp">
</File>
<File
RelativePath=".\expression_test.hpp">
</File>
<File
RelativePath=".\logical_test.hpp">
</File>
<File
RelativePath=".\match_test.hpp">
</File>
<File
RelativePath=".\node_test_test.hpp">
</File>
<File
RelativePath=".\parse_test.hpp">
</File>
<File
RelativePath=".\relational_test.hpp">
</File>
<File
RelativePath=".\step_test.hpp">
</File>
<File
RelativePath=".\value_test.hpp">
</File>
<File
RelativePath=".\xpath_test_suite.hpp">
</File>