uint2.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2011 Bryce Lelbach
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #include "uint.hpp"
  8. int
  9. main()
  10. {
  11. using spirit_test::test;
  12. using spirit_test::test_attr;
  13. ///////////////////////////////////////////////////////////////////////////
  14. // unsigned integer literal tests
  15. ///////////////////////////////////////////////////////////////////////////
  16. {
  17. using boost::spirit::lit;
  18. unsigned i = 123456;
  19. BOOST_TEST( test("123456", lit(123456U)));
  20. BOOST_TEST(!test("123456", lit(0U)));
  21. BOOST_TEST( test("123456", lit(i)));
  22. BOOST_TEST(!test("123456", lit(unsigned(i - 1))));
  23. }
  24. ///////////////////////////////////////////////////////////////////////////
  25. // unsigned long long literal tests
  26. ///////////////////////////////////////////////////////////////////////////
  27. #ifdef BOOST_HAS_LONG_LONG
  28. {
  29. using boost::spirit::lit;
  30. using boost::ulong_long_type;
  31. ulong_long_type ll = 1234567890123456789ULL;
  32. BOOST_TEST( test("1234567890123456789", lit(1234567890123456789ULL)));
  33. BOOST_TEST(!test("1234567890123456789", lit(0ULL)));
  34. BOOST_TEST( test("1234567890123456789", lit(ll)));
  35. BOOST_TEST(!test("1234567890123456789", lit(ulong_long_type(ll - 1))));
  36. }
  37. #endif
  38. ///////////////////////////////////////////////////////////////////////////
  39. // ushort_ and ulong_ literal tests
  40. ///////////////////////////////////////////////////////////////////////////
  41. {
  42. using boost::spirit::lit;
  43. unsigned short s = 12345;
  44. unsigned long l = 1234567890L;
  45. BOOST_TEST( test("12345", lit(s)));
  46. BOOST_TEST(!test("12345", lit(s - 1)));
  47. BOOST_TEST( test("1234567890", lit(1234567890UL)));
  48. BOOST_TEST(!test("1234567890", lit(98765321UL)));
  49. BOOST_TEST( test("1234567890", lit(l)));
  50. BOOST_TEST(!test("1234567890", lit(l - 1)));
  51. }
  52. ///////////////////////////////////////////////////////////////////////////
  53. // literal lazy tests
  54. ///////////////////////////////////////////////////////////////////////////
  55. {
  56. using boost::phoenix::ref;
  57. using boost::spirit::qi::lit;
  58. unsigned n = 123, m = 321;
  59. BOOST_TEST(test("123", lit(ref(n))));
  60. BOOST_TEST(!test("123", lit(ref(m))));
  61. }
  62. return boost::report_errors();
  63. }