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