diff options
author | Daniel Burrows <dburrows@debian.org> | 2010-03-20 23:02:12 -0700 |
---|---|---|
committer | Daniel Burrows <dburrows@debian.org> | 2010-03-20 23:02:12 -0700 |
commit | 805eea5ec6306cb00a0cc35dd65fede2766d021b (patch) | |
tree | bc133cede4a98e4d20017792d673c7e9d3341b37 /tests/test_parsers.cc | |
parent | fdd2347d8723cd8bdcbf23b6d2d98f57d3a7a1e9 (diff) | |
download | aptitude-805eea5ec6306cb00a0cc35dd65fede2766d021b.tar.gz |
Write a lexeme convenience wrapper that adds "drop trailing whitespace" to anything in the obvious way.
Diffstat (limited to 'tests/test_parsers.cc')
-rw-r--r-- | tests/test_parsers.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test_parsers.cc b/tests/test_parsers.cc index 685b5426..dcb835f1 100644 --- a/tests/test_parsers.cc +++ b/tests/test_parsers.cc @@ -114,6 +114,8 @@ class ParsersTest : public CppUnit::TestFixture CPPUNIT_TEST(testSepByFailureInFirstElement); CPPUNIT_TEST(testSepByFailureInSeparator); CPPUNIT_TEST(testSepByFailureInSecondElement); + CPPUNIT_TEST(testLexemeSuccess); + CPPUNIT_TEST(testLexemeFailure); CPPUNIT_TEST_SUITE_END(); @@ -1323,6 +1325,35 @@ public: CPPUNIT_ASSERT_EQUAL((iter_difftype)6, begin - input.begin()); } } + + void testLexemeSuccess() + { + { + std::string input = "abcd ef"; + std::string::const_iterator begin = input.begin(), end = input.end(); + + boost::shared_ptr<std::string> result; + CPPUNIT_ASSERT_NO_THROW(result = lexeme(many_string(alpha())).parse(begin, end)); + CPPUNIT_ASSERT_EQUAL(std::string("abcd"), *result); + // Unlike in many parsers, this test is NOT purely cosmetic; it + // verifies that we really consumed the whitespace (which is, + // y'know, the whole point). + CPPUNIT_ASSERT_EQUAL((iter_difftype)8, begin - input.begin()); + } + } + + void testLexemeFailure() + { + // Just check that a failure really is propagated out of the + // lexeme parser. + { + std::string input = "ab43 "; + std::string::const_iterator begin = input.begin(), end = input.end(); + + CPPUNIT_ASSERT_THROW(lexeme(alpha() >> alpha() >> alpha()).parse(begin, end), ParseException); + CPPUNIT_ASSERT_EQUAL((iter_difftype)2, begin - input.begin()); + } + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ParsersTest); |