diff options
author | Daniel Burrows <dburrows@debian.org> | 2010-03-20 22:48:37 -0700 |
---|---|---|
committer | Daniel Burrows <dburrows@debian.org> | 2010-03-20 22:48:37 -0700 |
commit | a7fe75b6e07e602772c796a062339bdf9f792693 (patch) | |
tree | 718eabee4fed925586700f703845d02ca0edcbef /tests/test_parsers.cc | |
parent | 818500a6772a1266f80a81f328bdb4a97a5065d8 (diff) | |
download | aptitude-a7fe75b6e07e602772c796a062339bdf9f792693.tar.gz |
Test the failure case for both foreach and many.
As it turns out, foreach is buggy and doesn't fail.
Diffstat (limited to 'tests/test_parsers.cc')
-rw-r--r-- | tests/test_parsers.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/test_parsers.cc b/tests/test_parsers.cc index 295fc660..fb5045b3 100644 --- a/tests/test_parsers.cc +++ b/tests/test_parsers.cc @@ -69,6 +69,7 @@ class ParsersTest : public CppUnit::TestFixture CPPUNIT_TEST(testForeachEmptyEndEOF); CPPUNIT_TEST(testForeachNotEmptyEndNotEOF); CPPUNIT_TEST(testForeachNotEmptyEndEOF); + CPPUNIT_TEST(testForeachFailure); CPPUNIT_TEST(testSkipEmptyEndNotEOF); CPPUNIT_TEST(testSkipEmptyEndEOF); CPPUNIT_TEST(testSkipNotEmptyEndNotEOF); @@ -81,6 +82,7 @@ class ParsersTest : public CppUnit::TestFixture CPPUNIT_TEST(testManyEmptyEndEOF); CPPUNIT_TEST(testManyNotEmptyEndNotEOF); CPPUNIT_TEST(testManyNotEmptyEndEOF); + CPPUNIT_TEST(testManyFailure); CPPUNIT_TEST(testOrFirstBranchMatches); CPPUNIT_TEST(testOrFirstBranchFailsAndConsumesInput); CPPUNIT_TEST(testOrSecondBranchMatches); @@ -603,6 +605,19 @@ public: CPPUNIT_ASSERT_EQUAL((iter_difftype)5, begin - input.begin()); } + void testForeachFailure() + { + std::string input = "2345 1234 234jf "; + std::string::const_iterator begin = input.begin(), end = input.end(); + + std::vector<int> result; + + CPPUNIT_ASSERT_THROW(foreach(integer() >> ch(' '), + push_back_a(result)).parse(begin, end), ParseException); + CPPUNIT_ASSERT_EQUAL((iter_difftype)14, begin - input.begin()); + } + + void testSkipEmptyEndNotEOF() { alpha_p letter = alpha(); @@ -751,6 +766,15 @@ public: CPPUNIT_ASSERT_EQUAL((iter_difftype)5, begin - input.begin()); } + void testManyFailure() + { + std::string input = "2345 1234 234jf "; + std::string::const_iterator begin = input.begin(), end = input.end(); + + CPPUNIT_ASSERT_THROW(many(integer() >> ch(' ')).parse(begin, end), ParseException); + CPPUNIT_ASSERT_EQUAL((iter_difftype)13, begin - input.begin()); + } + void testOrFirstBranchMatches() { str ab("ab"), a("a"); |