]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/karma/symbols1.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / spirit / test / karma / symbols1.cpp
1 // Copyright (c) 2001-2011 Hartmut Kaiser
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/spirit/include/karma_auxiliary.hpp>
7 #include <boost/spirit/include/karma_char.hpp>
8 #include <boost/spirit/include/karma_string.hpp>
9 #include <boost/spirit/include/karma_operator.hpp>
10 #include <boost/spirit/include/karma_directive.hpp>
11 #include <boost/spirit/include/karma_generate.hpp>
12 #include <boost/spirit/include/karma_nonterminal.hpp>
13
14 #include <boost/core/lightweight_test.hpp>
15 #include <boost/core/lightweight_test_trait.hpp>
16
17 #include "test.hpp"
18
19 namespace fusion = boost::fusion;
20
21 template <typename T>
22 inline std::vector<T>
23 make_vector(T const& t1, T const& t2)
24 {
25 std::vector<T> v;
26 v.push_back(t1);
27 v.push_back(t2);
28 return v;
29 }
30
31 int main()
32 {
33 using spirit_test::test;
34 using boost::spirit::karma::symbols;
35
36 { // basics
37 symbols<char, std::string> sym;
38
39 sym.add
40 ('j', "Joel")
41 ('h', "Hartmut")
42 ('t', "Tom")
43 ('k', "Kim")
44 ;
45
46 BOOST_TEST_TRAIT_TRUE((
47 boost::spirit::traits::is_generator<
48 symbols<char, std::string> >));
49
50 BOOST_TEST((test("Joel", sym, 'j')));
51 BOOST_TEST((test("Hartmut", sym, 'h')));
52 BOOST_TEST((test("Tom", sym, 't')));
53 BOOST_TEST((test("Kim", sym, 'k')));
54 BOOST_TEST((!test("", sym, 'x')));
55
56 // test copy
57 symbols<char, std::string> sym2;
58 sym2 = sym;
59 BOOST_TEST((test("Joel", sym2, 'j')));
60 BOOST_TEST((test("Hartmut", sym2, 'h')));
61 BOOST_TEST((test("Tom", sym2, 't')));
62 BOOST_TEST((test("Kim", sym2, 'k')));
63 BOOST_TEST((!test("", sym2, 'x')));
64
65 // make sure it plays well with other generators
66 BOOST_TEST((test("Joelyo", sym << "yo", 'j')));
67
68 sym.remove
69 ('j')
70 ('h')
71 ;
72
73 BOOST_TEST((!test("", sym, 'j')));
74 BOOST_TEST((!test("", sym, 'h')));
75 }
76
77 { // lower/upper handling
78 using namespace boost::spirit::ascii;
79 using boost::spirit::karma::lower;
80 using boost::spirit::karma::upper;
81
82 symbols<char, std::string> sym;
83 sym.add
84 ('j', "Joel")
85 ('h', "Hartmut")
86 ('t', "Tom")
87 ('k', "Kim")
88 ;
89
90 BOOST_TEST((test("joel", lower[sym], 'j')));
91 BOOST_TEST((test("hartmut", lower[sym], 'h')));
92 BOOST_TEST((test("tom", lower[sym], 't')));
93 BOOST_TEST((test("kim", lower[sym], 'k')));
94
95 BOOST_TEST((test("JOEL", upper[sym], 'j')));
96 BOOST_TEST((test("HARTMUT", upper[sym], 'h')));
97 BOOST_TEST((test("TOM", upper[sym], 't')));
98 BOOST_TEST((test("KIM", upper[sym], 'k')));
99
100 // make sure it plays well with other generators
101 BOOST_TEST((test("joelyo", lower[sym] << "yo", 'j')));
102 BOOST_TEST((test("JOELyo", upper[sym] << "yo", 'j')));
103 }
104
105 return boost::report_errors();
106 }