Added test for Parser’s cursor position.

This commit is contained in:
Patrick Lühne 2016-05-30 12:32:13 +02:00
parent 67c9e2148d
commit 8f705b0737

View File

@ -83,6 +83,65 @@ TEST(UtilsTests, ParseEndOfFile)
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST(UtilsTests, ParserPosition)
{
std::stringstream s("123\n4\ntest1\n test2\ntest3 \n\n\n\n\n");
plasp::utils::Parser p(s);
ASSERT_EQ(p.row(), 1u);
ASSERT_EQ(p.column(), 1u);
ASSERT_EQ(p.currentCharacter(), '1');
p.advance();
ASSERT_EQ(p.row(), 1u);
ASSERT_EQ(p.column(), 2u);
ASSERT_EQ(p.currentCharacter(), '2');
p.advance();
ASSERT_EQ(p.row(), 1u);
ASSERT_EQ(p.column(), 3u);
ASSERT_EQ(p.currentCharacter(), '3');
p.advance();
ASSERT_EQ(p.row(), 1u);
ASSERT_EQ(p.column(), 4u);
ASSERT_EQ(p.currentCharacter(), '\n');
p.advance();
ASSERT_EQ(p.row(), 2u);
ASSERT_EQ(p.column(), 1u);
ASSERT_EQ(p.currentCharacter(), '4');
p.advance();
p.expect<std::string>("test1");
ASSERT_EQ(p.row(), 3u);
ASSERT_EQ(p.column(), 6u);
p.expect<std::string>("test2");
ASSERT_EQ(p.row(), 4u);
ASSERT_EQ(p.column(), 7u);
p.expect<std::string>("test3");
ASSERT_EQ(p.row(), 5u);
ASSERT_EQ(p.column(), 6u);
p.skipWhiteSpace();
ASSERT_TRUE(p.atEndOfFile());
ASSERT_EQ(p.row(), 10u);
ASSERT_EQ(p.column(), 1u);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST(UtilsTests, EscapeASP)
{
const std::string predicate = "action(stack_on(block-1, block-2, value@3, value@4))";