From 8f705b07371d116316d061e8f1623ee0b695d317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Mon, 30 May 2016 12:32:13 +0200 Subject: [PATCH] =?UTF-8?q?Added=20test=20for=20Parser=E2=80=99s=20cursor?= =?UTF-8?q?=20position.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/TestUtils.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp index f8dbe0f..2788bda 100644 --- a/tests/TestUtils.cpp +++ b/tests/TestUtils.cpp @@ -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("test1"); + + ASSERT_EQ(p.row(), 3u); + ASSERT_EQ(p.column(), 6u); + + p.expect("test2"); + + ASSERT_EQ(p.row(), 4u); + ASSERT_EQ(p.column(), 7u); + + p.expect("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))";