• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3     Copyright (c) 2001-2011 Hartmut Kaiser
4     Copyright (c) 2011      Bryce Lelbach
5 
6     Distributed under the Boost Software License, Version 1.0. (See accompanying
7     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 
10 #include "int.hpp"
11 
12 int
main()13 main()
14 {
15     using spirit_test::test;
16     using spirit_test::test_attr;
17 
18     ///////////////////////////////////////////////////////////////////////////
19     //  signed integer literal tests
20     ///////////////////////////////////////////////////////////////////////////
21     {
22         using boost::spirit::lit;
23         int i = 123456;
24 
25         BOOST_TEST( test("123456", lit(123456)));
26         BOOST_TEST(!test("123456", lit(0)));
27         BOOST_TEST( test("123456", lit(i)));
28         BOOST_TEST(!test("123456", lit(-i)));
29         BOOST_TEST( test("+425", lit(425)));
30         BOOST_TEST(!test("+425", lit(17)));
31         BOOST_TEST( test("-2000", lit(-2000)));
32         BOOST_TEST(!test("-2000", lit(2000)));
33         BOOST_TEST( test(max_int, lit(INT_MAX)));
34         BOOST_TEST(!test(max_int, lit(INT_MIN)));
35 
36         BOOST_TEST( test(min_int, lit(INT_MIN)));
37         BOOST_TEST(!test(min_int, lit(INT_MAX)));
38 
39         BOOST_TEST(!test("-", lit(8451)));
40         BOOST_TEST(!test("+", lit(8451)));
41 
42         // with leading zeros
43         BOOST_TEST(test("000000000098765", lit(98765)));
44     }
45 
46     ///////////////////////////////////////////////////////////////////////////
47     //  long long literal tests
48     ///////////////////////////////////////////////////////////////////////////
49 #ifdef BOOST_HAS_LONG_LONG
50     {
51         using boost::spirit::lit;
52         boost::long_long_type ll = 1234567890123456789LL;
53 
54         BOOST_TEST( test("1234567890123456789", lit(1234567890123456789LL)));
55         BOOST_TEST(!test("1234567890123456789", lit(-19LL)));
56         BOOST_TEST( test("1234567890123456789", lit(ll)));
57         BOOST_TEST(!test("1234567890123456789", lit(-ll)));
58         BOOST_TEST( test("-100000000000000", lit(-100000000000000LL)));
59         BOOST_TEST(!test("-100000000000000", lit(3243515525263LL)));
60         BOOST_TEST( test(max_long_long, lit(LONG_LONG_MAX)));
61         BOOST_TEST(!test(max_long_long, lit(LONG_LONG_MIN)));
62 
63         BOOST_TEST( test(min_long_long, lit(LONG_LONG_MIN)));
64         BOOST_TEST(!test(min_long_long, lit(LONG_LONG_MAX)));
65     }
66 #endif
67 
68     ///////////////////////////////////////////////////////////////////////////
69     //  short_ and long_ literal tests
70     ///////////////////////////////////////////////////////////////////////////
71     {
72         using boost::spirit::lit;
73         short s = 12345;
74         long l = 1234567890L;
75 
76         BOOST_TEST( test("12345",  lit(12345)));
77         BOOST_TEST(!test("12345",  lit(-12345)));
78         BOOST_TEST( test("12345",  lit(s)));
79         BOOST_TEST(!test("12345",  lit(-s)));
80         BOOST_TEST( test("-12345", lit(-12345)));
81         BOOST_TEST(!test("-12345", lit(12345)));
82         BOOST_TEST( test("-12345", lit(-s)));
83         BOOST_TEST(!test("-12345", lit(s)));
84 
85         BOOST_TEST( test("1234567890",  lit(1234567890)));
86         BOOST_TEST(!test("1234567890",  lit(-1234567890)));
87         BOOST_TEST( test("1234567890",  lit(l)));
88         BOOST_TEST(!test("1234567890",  lit(-l)));
89         BOOST_TEST( test("-1234567890", lit(-1234567890)));
90         BOOST_TEST(!test("-1234567890", lit(1234567890)));
91         BOOST_TEST( test("-1234567890", lit(-l)));
92         BOOST_TEST(!test("-1234567890", lit(l)));
93     }
94 
95     ///////////////////////////////////////////////////////////////////////////
96     //  literal lazy tests
97     ///////////////////////////////////////////////////////////////////////////
98     {
99         using boost::phoenix::ref;
100         using boost::spirit::qi::lit;
101         int n = 123, m = 321;
102 
103         BOOST_TEST(test("123", lit(ref(n))));
104         BOOST_TEST(!test("123", lit(ref(m))));
105     }
106 
107     return boost::report_errors();
108 }
109