diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp index f0e7e37..c235776 100644 --- a/tests/TestUtils.cpp +++ b/tests/TestUtils.cpp @@ -6,34 +6,17 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// -TEST(UtilsTests, ParseSimple) +TEST(UtilsTests, Parse) { - std::stringstream s("identifier 5 \n-51\t 0 1 expected unexpected"); + std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400"); plasp::utils::Parser<> p("input", s); - // TODO: reimplement - //ASSERT_TRUE(p.isCaseSensitive()); - ASSERT_EQ(p.parse(), "identifier"); ASSERT_EQ(p.parse(), 5u); ASSERT_EQ(p.parse(), -51); ASSERT_EQ(p.parse(), false); ASSERT_EQ(p.parse(), true); - ASSERT_NO_THROW(p.expect("expected")); - ASSERT_THROW(p.expect("expected"), plasp::utils::ParserException); - - // TODO: test case-insensitive input - // TODO: test probing -} - -//////////////////////////////////////////////////////////////////////////////////////////////////// - -TEST(UtilsTests, ParseUnsignedNumbers) -{ - std::stringstream s("100 200 -300 -400"); - plasp::utils::Parser<> p("input", s); - ASSERT_EQ(p.parse(), 100); ASSERT_EQ(p.parse(), 200u); ASSERT_EQ(p.parse(), -300); @@ -42,6 +25,49 @@ TEST(UtilsTests, ParseUnsignedNumbers) //////////////////////////////////////////////////////////////////////////////////////////////////// +TEST(UtilsTests, ParserExpect) +{ + std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400"); + plasp::utils::Parser<> p("input", s); + + ASSERT_NO_THROW(p.expect("identifier")); + ASSERT_NO_THROW(p.expect(5u)); + ASSERT_NO_THROW(p.expect(-51)); + ASSERT_NO_THROW(p.expect(false)); + ASSERT_NO_THROW(p.expect(true)); + + ASSERT_NO_THROW(p.expect(100)); + ASSERT_NO_THROW(p.expect(200u)); + ASSERT_NO_THROW(p.expect(-300)); + ASSERT_THROW(p.expect(-400), plasp::utils::ParserException); + + p.seek(0); + ASSERT_THROW(p.expect("error"), plasp::utils::ParserException); + + p.seek(14); + ASSERT_THROW(p.expect(6u), plasp::utils::ParserException); + + p.seek(17); + ASSERT_THROW(p.expect(-50), plasp::utils::ParserException); + + p.seek(24); + ASSERT_THROW(p.expect(true), plasp::utils::ParserException); + + p.seek(26); + ASSERT_THROW(p.expect(false), plasp::utils::ParserException); + + p.seek(28); + ASSERT_THROW(p.expect(101), plasp::utils::ParserException); + + p.seek(31); + ASSERT_THROW(p.expect(201), plasp::utils::ParserException); + + p.seek(34); + ASSERT_THROW(p.expect(-299), plasp::utils::ParserException); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + TEST(UtilsTests, ParseEndOfFile) { std::stringstream s1("test");