]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/repository/test/karma/confix.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / spirit / repository / test / karma / confix.cpp
CommitLineData
7c673cae
FG
1// Copyright (c) 2001-2010 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/config/warning_disable.hpp>
7#include <boost/detail/lightweight_test.hpp>
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_generate.hpp>
12
13#include <boost/spirit/repository/include/karma_confix.hpp>
14
15#include <iostream>
16#include "test.hpp"
17
18namespace html
19{
20 namespace spirit = boost::spirit;
21 namespace repo = boost::spirit::repository;
22
23 ///////////////////////////////////////////////////////////////////////////////
24 // define a HTML tag helper generator
25 namespace traits
26 {
27 template <typename Prefix, typename Suffix = Prefix>
28 struct confix_spec
29 : spirit::result_of::terminal<repo::tag::confix(Prefix, Suffix)>
30 {};
11fdf7f2 31 }
7c673cae
FG
32
33 template <typename Prefix, typename Suffix>
34 inline typename traits::confix_spec<Prefix, Suffix>::type
35 confix_spec(Prefix const& prefix, Suffix const& suffix)
36 {
37 return repo::confix(prefix, suffix);
38 }
39
40 ///////////////////////////////////////////////////////////////////////////
41 template <typename Char, typename Traits, typename Allocator>
42 inline typename traits::confix_spec<
43 std::basic_string<Char, Traits, Allocator>
44 >::type
45 tag (std::basic_string<Char, Traits, Allocator> const& tagname)
46 {
47 typedef std::basic_string<Char, Traits, Allocator> string_type;
48 return confix_spec(string_type("<") + tagname + ">"
49 , string_type("</") + tagname + ">");
50 }
51
52 inline traits::confix_spec<std::string>::type
53 tag (char const* tagname)
54 {
55 return tag(std::string(tagname));
56 }
57
58 ///////////////////////////////////////////////////////////////////////////
59 typedef traits::confix_spec<std::string>::type html_tag_type;
60
61 html_tag_type const ol = tag("ol");
62}
63
64///////////////////////////////////////////////////////////////////////////////
65int main()
66{
67 using namespace spirit_test;
68 using namespace boost::spirit;
69 using namespace boost::spirit::repository;
70
71 {
72 using namespace boost::spirit::ascii;
73
74 BOOST_TEST((test("<tag>a</tag>",
75 confix("<tag>", "</tag>")[char_('a')])));
76 BOOST_TEST((test("<tag>a</tag>",
77 confix("<tag>", "</tag>")[char_], 'a')));
78 BOOST_TEST((test("// some C++ comment\n",
79 confix(string("//"), eol)[" some C++ comment"])));
80 BOOST_TEST((test("// some C++ comment\n",
81 confix(string("//"), eol)[string], " some C++ comment")));
82
83 BOOST_TEST((test("<ol>some text</ol>", html::ol["some text"])));
84 BOOST_TEST((test("<ol>some text</ol>", html::ol[string], "some text")));
85 }
86
87 {
88 using namespace boost::spirit::standard_wide;
89
90 BOOST_TEST((test(L"<tag>a</tag>",
91 confix(L"<tag>", L"</tag>")[char_(L'a')])));
92 BOOST_TEST((test(L"// some C++ comment\n",
93 confix(string(L"//"), eol)[L" some C++ comment"])));
94
95 BOOST_TEST((test(L"<ol>some text</ol>", html::ol[L"some text"])));
96 }
97
98 {
99 using namespace boost::spirit::ascii;
100
101 BOOST_TEST((test_delimited("<tag> a </tag> ",
102 confix("<tag>", "</tag>")[char_('a')], space)));
103 BOOST_TEST((test_delimited("// some C++ comment \n ",
104 confix(string("//"), eol)["some C++ comment"], space)));
105
106 BOOST_TEST((test_delimited("<ol> some text </ol> ",
107 html::ol["some text"], space)));
108 }
109
110 {
111 using namespace boost::spirit::standard_wide;
112
113 BOOST_TEST((test_delimited(L"<tag> a </tag> ",
114 confix(L"<tag>", L"</tag>")[char_(L'a')], space)));
115 BOOST_TEST((test_delimited(L"// some C++ comment \n ",
116 confix(string(L"//"), eol)[L"some C++ comment"], space)));
117
118 BOOST_TEST((test_delimited(L"<ol> some text </ol> ",
119 html::ol[L"some text"], space)));
120 }
121
122 return boost::report_errors();
123}