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