// Copyright (c) 2001-2010 Hartmut Kaiser // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include #include #include #include #include #include #include "test.hpp" namespace html { namespace spirit = boost::spirit; namespace repo = boost::spirit::repository; /////////////////////////////////////////////////////////////////////////////// // define a HTML tag helper generator namespace traits { template struct confix_spec : spirit::result_of::terminal {}; } template inline typename traits::confix_spec::type confix_spec(Prefix const& prefix, Suffix const& suffix) { return repo::confix(prefix, suffix); } /////////////////////////////////////////////////////////////////////////// template inline typename traits::confix_spec< std::basic_string >::type tag (std::basic_string const& tagname) { typedef std::basic_string string_type; return confix_spec(string_type("<") + tagname + ">" , string_type(""); } inline traits::confix_spec::type tag (char const* tagname) { return tag(std::string(tagname)); } /////////////////////////////////////////////////////////////////////////// typedef traits::confix_spec::type html_tag_type; html_tag_type const ol = tag("ol"); } /////////////////////////////////////////////////////////////////////////////// int main() { using namespace spirit_test; using namespace boost::spirit; using namespace boost::spirit::repository; { using namespace boost::spirit::ascii; BOOST_TEST((test("a", confix("", "")[char_('a')]))); BOOST_TEST((test("a", confix("", "")[char_], 'a'))); BOOST_TEST((test("// some C++ comment\n", confix(string("//"), eol)[" some C++ comment"]))); BOOST_TEST((test("// some C++ comment\n", confix(string("//"), eol)[string], " some C++ comment"))); BOOST_TEST((test("
    some text
", html::ol["some text"]))); BOOST_TEST((test("
    some text
", html::ol[string], "some text"))); } { using namespace boost::spirit::standard_wide; BOOST_TEST((test(L"a", confix(L"", L"")[char_(L'a')]))); BOOST_TEST((test(L"// some C++ comment\n", confix(string(L"//"), eol)[L" some C++ comment"]))); BOOST_TEST((test(L"
    some text
", html::ol[L"some text"]))); } { using namespace boost::spirit::ascii; BOOST_TEST((test_delimited(" a ", confix("", "")[char_('a')], space))); BOOST_TEST((test_delimited("// some C++ comment \n ", confix(string("//"), eol)["some C++ comment"], space))); BOOST_TEST((test_delimited("
    some text
", html::ol["some text"], space))); } { using namespace boost::spirit::standard_wide; BOOST_TEST((test_delimited(L" a ", confix(L"", L"")[char_(L'a')], space))); BOOST_TEST((test_delimited(L"// some C++ comment \n ", confix(string(L"//"), eol)[L"some C++ comment"], space))); BOOST_TEST((test_delimited(L"
    some text
", html::ol[L"some text"], space))); } return boost::report_errors(); }