|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56218 - trunk/libs/spirit/test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-09-15 13:00:14
Author: hkaiser
Date: 2009-09-15 13:00:12 EDT (Tue, 15 Sep 2009)
New Revision: 56218
URL: http://svn.boost.org/trac/boost/changeset/56218
Log:
Spirit: all generators now accept a boost::optional holding the attribute and will fail if this is not initialized, fixed tests to cover this
Text files modified:
trunk/libs/spirit/test/karma/alternative.cpp | 9 ++++++
trunk/libs/spirit/test/karma/binary.cpp | 58 ++++++++++++++++++++++++++++++++++++++++
trunk/libs/spirit/test/karma/char.cpp | 29 ++++++++++++++++++++
trunk/libs/spirit/test/karma/int_numerics.cpp | 12 ++++++++
trunk/libs/spirit/test/karma/real_numerics.cpp | 11 +++++++
trunk/libs/spirit/test/karma/stream.cpp | 7 ++++
6 files changed, 126 insertions(+), 0 deletions(-)
Modified: trunk/libs/spirit/test/karma/alternative.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/alternative.cpp (original)
+++ trunk/libs/spirit/test/karma/alternative.cpp 2009-09-15 13:00:12 EDT (Tue, 15 Sep 2009)
@@ -121,6 +121,15 @@
BOOST_TEST(test("[5, 5, 5]", '[' << (int_ % ", ") << ']' | "[]", v));
}
+ {
+ boost::optional<int> v;
+ BOOST_TEST(test("error", int_ | "error" << omit[-int_], v));
+ BOOST_TEST(test("error", int_ | "error" << omit[int_], v));
+ v = 1;
+ BOOST_TEST(test("1", int_ | "error" << omit[-int_], v));
+ BOOST_TEST(test("1", int_ | "error" << omit[int_], v));
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/binary.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/binary.cpp (original)
+++ trunk/libs/spirit/test/karma/binary.cpp 2009-09-15 13:00:12 EDT (Tue, 15 Sep 2009)
@@ -122,5 +122,63 @@
#endif
}
+ { // test native endian binaries
+ boost::optional<boost::uint8_t> v8;
+ boost::optional<boost::uint16_t> v16;
+ boost::optional<boost::uint32_t> v32;
+
+#ifdef BOOST_LITTLE_ENDIAN
+
+ BOOST_TEST(!binary_test("", 1, byte_, v8));
+ BOOST_TEST(!binary_test("", 2, word, v16));
+ BOOST_TEST(!binary_test("", 4, dword, v32));
+#ifdef BOOST_HAS_LONG_LONG
+ boost::optional<boost::uint64_t> v64;
+ BOOST_TEST(!binary_test("", 8, qword, v64));
+#endif
+
+#else // BOOST_LITTLE_ENDIAN
+
+ BOOST_TEST(!binary_test("", 1, byte_, v8));
+ BOOST_TEST(!binary_test("", 2, word, v16));
+ BOOST_TEST(!binary_test("", 4, dword, v32));
+#ifdef BOOST_HAS_LONG_LONG
+ boost::optional<boost::uint64_t> v64;
+ BOOST_TEST(!binary_test("", 8, qword, v64));
+#endif
+
+#endif
+ }
+
+ { // test native endian binaries
+
+#ifdef BOOST_LITTLE_ENDIAN
+ boost::optional<boost::uint8_t> v8 (0x01);
+ BOOST_TEST(binary_test("\x01", 1, byte_, v8));
+ boost::optional<boost::uint16_t> v16 (0x0201);
+ BOOST_TEST(binary_test("\x01\x02", 2, word, v16));
+ boost::optional<boost::uint32_t> v32 (0x04030201);
+ BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword, v32));
+#ifdef BOOST_HAS_LONG_LONG
+ boost::optional<boost::uint64_t> v64 (0x0807060504030201LL);
+ BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, qword, v64));
+#endif
+
+#else // BOOST_LITTLE_ENDIAN
+
+ boost::optional<boost::uint8_t> v8 (0x01);
+ BOOST_TEST(!binary_test("\x01", 1, byte_, v8));
+ boost::optional<boost::uint16_t> v16 (0x0102);
+ BOOST_TEST(!binary_test("\x01\x02", 2, word, v16));
+ boost::optional<boost::uint32_t> v32 (0x01020304);
+ BOOST_TEST(!binary_test("\x01\x02\x03\x04", 4, dword, v32));
+#ifdef BOOST_HAS_LONG_LONG
+ boost::optional<boost::uint64_t> v64 (0x0102030405060708LL);
+ BOOST_TEST(!binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, qword, v64));
+#endif
+
+#endif
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/char.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/char.cpp (original)
+++ trunk/libs/spirit/test/karma/char.cpp 2009-09-15 13:00:12 EDT (Tue, 15 Sep 2009)
@@ -252,5 +252,34 @@
BOOST_TEST((!test(L"", wide::char_(val(L'y')), L'x')));
}
+ {
+ namespace ascii = boost::spirit::ascii;
+ namespace wide = boost::spirit::standard_wide;
+
+ boost::optional<char> v;
+ boost::optional<wchar_t> w;
+
+ BOOST_TEST(!test("", ascii::char_, v));
+ BOOST_TEST(!test(L"", wide::char_, w));
+
+ BOOST_TEST(!test("", ascii::char_('x'), v));
+ BOOST_TEST(!test(L"", wide::char_(L'x'), w));
+ }
+
+ {
+ namespace ascii = boost::spirit::ascii;
+ namespace wide = boost::spirit::standard_wide;
+
+ boost::optional<char> v ('x');
+ boost::optional<wchar_t> w (L'x');
+
+ BOOST_TEST(test("x", ascii::char_, v));
+ BOOST_TEST(test(L"x", wide::char_, w));
+ BOOST_TEST(test("x", ascii::char_('x'), v));
+ BOOST_TEST(test(L"x", wide::char_(L'x'), w));
+ BOOST_TEST(!test("", ascii::char_('y'), v));
+ BOOST_TEST(!test(L"", wide::char_(L'y'), w));
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/int_numerics.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/int_numerics.cpp (original)
+++ trunk/libs/spirit/test/karma/int_numerics.cpp 2009-09-15 13:00:12 EDT (Tue, 15 Sep 2009)
@@ -78,6 +78,18 @@
// action tests
BOOST_TEST(test(expected_maxval, gen[_1 = val(maxval)]));
BOOST_TEST(test(expected_minval, gen[_1 = val(minval)]));
+
+ // optional tests
+ boost::optional<T> optmin, optmax(maxval);
+
+ BOOST_TEST(!test("", gen, optmin));
+ BOOST_TEST(!test("", gen(minval), optmin));
+
+ optmin = minval;
+ BOOST_TEST(test(expected_minval, gen, optmin));
+ BOOST_TEST(test(expected_maxval, gen, optmax));
+ BOOST_TEST(test(expected_minval, gen(minval), optmin));
+ BOOST_TEST(test(expected_maxval, gen(maxval), optmax));
}
};
Modified: trunk/libs/spirit/test/karma/real_numerics.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/real_numerics.cpp (original)
+++ trunk/libs/spirit/test/karma/real_numerics.cpp 2009-09-15 13:00:12 EDT (Tue, 15 Sep 2009)
@@ -522,5 +522,16 @@
BOOST_TEST(test("-2.2250738585072014e-308",
bordercase(-2.2250738585072014e-308))); // -DBL_MIN
}
+
+ {
+ boost::optional<double> v;
+ BOOST_TEST(!test("", double_, v));
+ BOOST_TEST(!test("", double_(1.0), v));
+
+ v = 1.0;
+ BOOST_TEST(test("1.0", double_, v));
+ BOOST_TEST(test("1.0", double_(1.0), v));
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/stream.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/stream.cpp (original)
+++ trunk/libs/spirit/test/karma/stream.cpp 2009-09-15 13:00:12 EDT (Tue, 15 Sep 2009)
@@ -159,5 +159,12 @@
BOOST_TEST((test(L"abc", wstream(phx::ref(ws)))));
}
+ {
+ boost::optional<char> c;
+ BOOST_TEST(!test("", stream, c));
+ c = 'x';
+ BOOST_TEST(test("x", stream, c));
+ }
+
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk