diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/plugins/css/CSSParserTest.cpp | 46 | ||||
-rw-r--r-- | test/plugins/xml/XmlParserTest.cpp | 17 |
2 files changed, 34 insertions, 29 deletions
diff --git a/test/plugins/css/CSSParserTest.cpp b/test/plugins/css/CSSParserTest.cpp index 99e6424..e47d364 100644 --- a/test/plugins/css/CSSParserTest.cpp +++ b/test/plugins/css/CSSParserTest.cpp @@ -28,9 +28,8 @@ namespace parser { namespace css { TEST(CSSParser, testParseSelectors) { - // create a string describing a SelectorTree as input. - std::stringstream input; - input << "A>B,A B:r, C#a A[bla=\"blub\"], A::g(4,2,3)"; + // create a string describing a SelectorTree + std::string data{"A>B,A B:r, C#a A[bla=\"blub\"], A::g(4,2,3)"}; /* This should describe the tree: * root_____ * | \ \ @@ -42,9 +41,9 @@ TEST(CSSParser, testParseSelectors) // initialize an empty parser context. StandaloneParserContext ctx; - // parse the input. + // parse the data. CSSParser instance; - Rooted<SelectorNode> root = instance.parse(input, ctx).cast<SelectorNode>(); + Rooted<SelectorNode> root = instance.parse(data, ctx).cast<SelectorNode>(); // we expect three children of the root node overall. ASSERT_EQ(3, root->getEdges().size()); @@ -153,7 +152,9 @@ TEST(CSSParser, testParseCSS) // parse the input. CSSParser instance; - Rooted<SelectorNode> root = instance.parse(input, ctx).cast<SelectorNode>(); + CharReader reader{input}; + Rooted<SelectorNode> root = + instance.parse(reader, ctx).cast<SelectorNode>(); // we expect three children of the root node overall. ASSERT_EQ(3, root->getEdges().size()); @@ -261,26 +262,25 @@ TEST(CSSParser, testParseCSS) void assertException(std::string css) { - std::stringstream input; - input << css; - // initialize a parser context. + CharReader reader(css); TerminalLogger logger(std::cerr, true); - Scope scope(nullptr); - Registry registry(logger); - Manager manager; - ParserContext ctx{scope, registry, logger, manager}; + { + ScopedLogger sl(logger, "test.css", SourceLocation{}, + CharReader::contextCallback, &reader); + Scope scope(nullptr); + Registry registry(logger); + Manager manager; + ParserContext ctx{scope, registry, logger, manager}; - bool seenException = false; - // parse the input. - CSSParser instance; - try { - instance.parse(input, ctx).cast<SelectorNode>(); - } - catch (LoggableException ex) { - logger.log(ex); - seenException = true; + CSSParser instance; + try { + instance.parse(reader, ctx).cast<SelectorNode>(); + } + catch (LoggableException ex) { + logger.log(ex); + } + ASSERT_TRUE(logger.hasError()); } - ASSERT_TRUE(seenException); } TEST(CSSParser, testParseExceptions) diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp index c5a7b10..886cccc 100644 --- a/test/plugins/xml/XmlParserTest.cpp +++ b/test/plugins/xml/XmlParserTest.cpp @@ -40,7 +40,7 @@ TEST(XmlParser, mismatchedTagException) p.parse("<document>\n</document2>", ctx); } catch (LoggableException ex) { - ASSERT_EQ(2U, ex.loc.line); + ASSERT_EQ(2, ex.loc.line); hadException = true; } ASSERT_TRUE(hadException); @@ -66,11 +66,16 @@ TEST(XmlParser, namespaces) { StandaloneParserContext ctx(logger); XmlParser p; - - try { - p.parse(TEST_DATA, ctx); - } catch(LoggableException ex) { - logger.log(ex); + CharReader reader(TEST_DATA); + { + ScopedLogger sl(logger, "test.oxd", SourceLocation{}, + CharReader::contextCallback, &reader); + try { + p.parse(TEST_DATA, ctx); + } + catch (LoggableException ex) { + logger.log(ex); + } } } } |