tweaks, clarification to line numbers

This commit is contained in:
Lee Thomason
2016-12-24 07:34:39 -08:00
parent 002713856b
commit e90e901041
3 changed files with 55 additions and 50 deletions

View File

@@ -65,7 +65,7 @@ bool XMLTest (const char* testString, const char* expected, const char* found, b
bool XMLTest(const char* testString, XMLError expected, XMLError found, bool echo = true, bool extraNL = false)
{
return XMLTest(testString, XMLDocument::ErrorName(expected), XMLDocument::ErrorName(found), echo, extraNL);
return XMLTest(testString, XMLDocument::ErrorIDToName(expected), XMLDocument::ErrorIDToName(found), echo, extraNL);
}
bool XMLTest(const char* testString, bool expected, bool found, bool echo = true, bool extraNL = false)
@@ -1647,7 +1647,7 @@ int main( int argc, const char ** argv )
// ----------- Line Number Tracking --------------
{
struct Functor: XMLVisitor
struct TestUtil: XMLVisitor
{
void TestParseError(const char *testString, const char *docStr, XMLError expected_error, int expectedLine)
{
@@ -1725,46 +1725,50 @@ int main( int argc, const char ** argv )
str.Push(0);
XMLTest(testString, expectedLines, str.Mem());
}
} T;
} tester;
T.TestParseError("ErrorLine-Parsing", "\n<root>\n foo \n<unclosed/>", XML_ERROR_PARSING, 2);
T.TestParseError("ErrorLine-Declaration", "<root>\n<?xml version=\"1.0\"?>", XML_ERROR_PARSING_DECLARATION, 2);
T.TestParseError("ErrorLine-Mismatch", "\n<root>\n</mismatch>", XML_ERROR_MISMATCHED_ELEMENT, 2);
T.TestParseError("ErrorLine-CData", "\n<root><![CDATA[ \n foo bar \n", XML_ERROR_PARSING_CDATA, 2);
T.TestParseError("ErrorLine-Text", "\n<root>\n foo bar \n", XML_ERROR_PARSING_TEXT, 3);
T.TestParseError("ErrorLine-Comment", "\n<root>\n<!-- >\n", XML_ERROR_PARSING_COMMENT, 3);
T.TestParseError("ErrorLine-Declaration", "\n<root>\n<? >\n", XML_ERROR_PARSING_DECLARATION, 3);
T.TestParseError("ErrorLine-Unknown", "\n<root>\n<! \n", XML_ERROR_PARSING_UNKNOWN, 3);
T.TestParseError("ErrorLine-Element", "\n<root>\n<unclosed \n", XML_ERROR_PARSING_ELEMENT, 3);
T.TestParseError("ErrorLine-Attribute", "\n<root>\n<unclosed \n att\n", XML_ERROR_PARSING_ATTRIBUTE, 4);
T.TestParseError("ErrorLine-ElementClose", "\n<root>\n<unclosed \n/unexpected", XML_ERROR_PARSING_ELEMENT, 3);
tester.TestParseError("ErrorLine-Parsing", "\n<root>\n foo \n<unclosed/>", XML_ERROR_PARSING, 2);
tester.TestParseError("ErrorLine-Declaration", "<root>\n<?xml version=\"1.0\"?>", XML_ERROR_PARSING_DECLARATION, 2);
tester.TestParseError("ErrorLine-Mismatch", "\n<root>\n</mismatch>", XML_ERROR_MISMATCHED_ELEMENT, 2);
tester.TestParseError("ErrorLine-CData", "\n<root><![CDATA[ \n foo bar \n", XML_ERROR_PARSING_CDATA, 2);
tester.TestParseError("ErrorLine-Text", "\n<root>\n foo bar \n", XML_ERROR_PARSING_TEXT, 3);
tester.TestParseError("ErrorLine-Comment", "\n<root>\n<!-- >\n", XML_ERROR_PARSING_COMMENT, 3);
tester.TestParseError("ErrorLine-Declaration", "\n<root>\n<? >\n", XML_ERROR_PARSING_DECLARATION, 3);
tester.TestParseError("ErrorLine-Unknown", "\n<root>\n<! \n", XML_ERROR_PARSING_UNKNOWN, 3);
tester.TestParseError("ErrorLine-Element", "\n<root>\n<unclosed \n", XML_ERROR_PARSING_ELEMENT, 3);
tester.TestParseError("ErrorLine-Attribute", "\n<root>\n<unclosed \n att\n", XML_ERROR_PARSING_ATTRIBUTE, 4);
tester.TestParseError("ErrorLine-ElementClose", "\n<root>\n<unclosed \n/unexpected", XML_ERROR_PARSING_ELEMENT, 3);
T.TestStringLines(
tester.TestStringLines(
"LineNumbers-String",
"<?xml version=\"1.0\"?>\n"
"<root a='b' \n"
"c='d'> d <blah/> \n"
"newline in text \n"
"and second <zxcv/><![CDATA[\n"
" cdata test ]]><!-- comment -->\n"
"<! unknown></root>",
"<?xml version=\"1.0\"?>\n" // 1 Doc, DecL
"<root a='b' \n" // 2 Element Attribute
"c='d'> d <blah/> \n" // 3 Attribute Text Element
"newline in text \n" // 4 Text
"and second <zxcv/><![CDATA[\n" // 5 Element Text
" cdata test ]]><!-- comment -->\n" // 6 Comment
"<! unknown></root>", // 7 Unknown
"D01L01E02A02A03T03E03T04E05T05C06U07");
T.TestStringLines(
tester.TestStringLines(
"LineNumbers-CRLF",
"\r\n"
"<?xml version=\"1.0\"?>\n"
"<root>\r\n"
"\n"
"text contining new line \n"
" and also containing crlf \r\n"
"<sub><![CDATA[\n"
"cdata containing new line \n"
" and also containing cflr\r\n"
"]]></sub><sub2/></root>",
"\r\n" // 1 Doc (arguably should be line 2)
"<?xml version=\"1.0\"?>\n" // 2 DecL
"<root>\r\n" // 3 Element
"\n" // 4
"text contining new line \n" // 5 Text
" and also containing crlf \r\n" // 6
"<sub><![CDATA[\n" // 7 Element Text
"cdata containing new line \n" // 8
" and also containing cflr\r\n" // 9
"]]></sub><sub2/></root>", // 10 Element
"D01L02E03T05E07T07E10");
T.TestFileLines(
tester.TestFileLines(
"LineNumbers-File",
"resources/utf8test.xml",
"D01L01E02E03A03A03T03E04A04A04T04E05A05A05T05E06A06A06T06E07A07A07T07E08A08A08T08E09T09E10T10");