Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52687 - in trunk/libs/spirit: . repository repository/doc repository/example repository/example/karma repository/example/lex repository/example/qi repository/test repository/test/karma repository/test/qi test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-04-30 13:14:05


Author: hkaiser
Date: 2009-04-30 13:14:04 EDT (Thu, 30 Apr 2009)
New Revision: 52687
URL: http://svn.boost.org/trac/boost/changeset/52687

Log:
Spirit: Started to add repository of reusable Spirit components, added repository::karma::confix and some related tests
Added:
   trunk/libs/spirit/repository/
   trunk/libs/spirit/repository/doc/
   trunk/libs/spirit/repository/example/
   trunk/libs/spirit/repository/example/karma/
   trunk/libs/spirit/repository/example/lex/
   trunk/libs/spirit/repository/example/qi/
   trunk/libs/spirit/repository/test/
   trunk/libs/spirit/repository/test/karma/
   trunk/libs/spirit/repository/test/karma/confix.cpp (contents, props changed)
   trunk/libs/spirit/repository/test/karma/test.hpp (contents, props changed)
   trunk/libs/spirit/repository/test/qi/
Removed:
   trunk/libs/spirit/test/karma/confix.cpp
Properties modified:
   trunk/libs/spirit/ (props changed)

Added: trunk/libs/spirit/repository/test/karma/confix.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/repository/test/karma/confix.cpp 2009-04-30 13:14:04 EDT (Thu, 30 Apr 2009)
@@ -0,0 +1,125 @@
+// Copyright (c) 2001-2008 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 <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/karma_auxiliary.hpp>
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_string.hpp>
+#include <boost/spirit/include/karma_generate.hpp>
+
+#include <boost/spirit/repository/karma.hpp>
+
+#include <iostream>
+#include "test.hpp"
+
+namespace html
+{
+ namespace spirit = boost::spirit;
+ namespace repo = boost::spirit::repository;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // define a HTML tag helper generator
+ namespace traits
+ {
+ template <typename Prefix, typename Suffix = Prefix>
+ struct confix_spec
+ {
+ typedef typename spirit::result_of::terminal<
+ repo::tag::confix(Prefix, Suffix)>::type type;
+ };
+ };
+
+ template <typename Prefix, typename Suffix>
+ inline typename traits::confix_spec<Prefix, Suffix>::type
+ confix_spec(Prefix const& prefix, Suffix const& suffix)
+ {
+ return repo::confix(prefix, suffix);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Traits, typename Allocator>
+ inline typename traits::confix_spec<
+ std::basic_string<Char, Traits, Allocator>
+ >::type
+ tag (std::basic_string<Char, Traits, Allocator> const& tagname)
+ {
+ typedef std::basic_string<Char, Traits, Allocator> string_type;
+ return confix_spec(string_type("<") + tagname + ">"
+ , string_type("</") + tagname + ">");
+ }
+
+ inline traits::confix_spec<std::string>::type
+ tag (char const* tagname)
+ {
+ return tag(std::string(tagname));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ typedef traits::confix_spec<std::string>::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("<tag>a</tag>",
+ confix("<tag>", "</tag>")[char_('a')])));
+ BOOST_TEST((test("<tag>a</tag>",
+ confix("<tag>", "</tag>")[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("<ol>some text</ol>", html::ol["some text"])));
+ BOOST_TEST((test("<ol>some text</ol>", html::ol[string], "some text")));
+ }
+
+ {
+ using namespace boost::spirit::standard_wide;
+
+ BOOST_TEST((test(L"<tag>a</tag>",
+ confix(L"<tag>", L"</tag>")[char_(L'a')])));
+ BOOST_TEST((test(L"// some C++ comment\n",
+ confix(string(L"//"), eol)[L" some C++ comment"])));
+
+ BOOST_TEST((test(L"<ol>some text</ol>", html::ol[L"some text"])));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST((test_delimited("<tag> a </tag> ",
+ confix("<tag>", "</tag>")[char_('a')], space)));
+ BOOST_TEST((test_delimited("// some C++ comment \n ",
+ confix(string("//"), eol)["some C++ comment"], space)));
+
+ BOOST_TEST((test_delimited("<ol> some text </ol> ",
+ html::ol["some text"], space)));
+ }
+
+ {
+ using namespace boost::spirit::standard_wide;
+
+ BOOST_TEST((test_delimited(L"<tag> a </tag> ",
+ confix(L"<tag>", L"</tag>")[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"<ol> some text </ol> ",
+ html::ol[L"some text"], space)));
+ }
+
+ return boost::report_errors();
+}

Added: trunk/libs/spirit/repository/test/karma/test.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/repository/test/karma/test.hpp 2009-04-30 13:14:04 EDT (Thu, 30 Apr 2009)
@@ -0,0 +1,276 @@
+// Copyright (c) 2001-2009 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)
+
+#if !defined(BOOST_SPIRIT_KARMA_TEST_FEB_23_2007_1221PM)
+#define BOOST_SPIRIT_KARMA_TEST_FEB_23_2007_1221PM
+
+#include <cstring>
+#include <string>
+#include <iterator>
+#include <iostream>
+#include <typeinfo>
+
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_what.hpp>
+
+namespace spirit_test
+{
+ ///////////////////////////////////////////////////////////////////////////
+ struct display_type
+ {
+ template<typename T>
+ void operator()(T const &) const
+ {
+ std::cout << typeid(T).name() << std::endl;
+ }
+
+ template<typename T>
+ static void print()
+ {
+ std::cout << typeid(T).name() << std::endl;
+ }
+ };
+
+ display_type const display = {};
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char>
+ struct output_iterator
+ {
+ typedef std::basic_string<Char> string_type;
+ typedef std::back_insert_iterator<string_type> type;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator>
+ inline bool test(Char const *expected, Generator const& g)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g);
+
+ return result && generated == expected;
+ }
+
+ template <typename Char, typename Generator>
+ inline bool test(std::basic_string<Char> const& expected, Generator const& g)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g);
+
+ return result && generated == expected;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator, typename Attribute>
+ inline bool test(Char const *expected, Generator const& g,
+ Attribute const &attr)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g, attr);
+
+ return result && generated == expected;
+ }
+
+ template <typename Char, typename Generator, typename Attribute>
+ inline bool test(std::basic_string<Char> const& expected, Generator const& g,
+ Attribute const &attr)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g, attr);
+
+ return result && generated == expected;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator, typename Delimiter>
+ inline bool test_delimited(Char const *expected, Generator const& g,
+ Delimiter const& d)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d);
+
+ return result && generated == expected;
+ }
+
+ template <typename Char, typename Generator, typename Delimiter>
+ inline bool test_delimited(std::basic_string<Char> const& expected,
+ Generator const& g, Delimiter const& d)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d);
+
+ return result && generated == expected;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator, typename Attribute,
+ typename Delimiter>
+ inline bool test_delimited(Char const *expected, Generator const& g,
+ Attribute const &attr, Delimiter const& d)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d, attr);
+
+ return result && generated == expected;
+ }
+
+ template <typename Char, typename Generator, typename Attribute,
+ typename Delimiter>
+ inline bool test_delimited(std::basic_string<Char> const& expected,
+ Generator const& g, Attribute const &attr, Delimiter const& d)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d, attr);
+
+ return result && generated == expected;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Generator>
+ inline bool
+ binary_test(char const *expected, std::size_t size,
+ Generator const& g)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g);
+
+ return result && !std::memcmp(generated.c_str(), expected, size);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Generator, typename Attribute>
+ inline bool
+ binary_test(char const *expected, std::size_t size,
+ Generator const& g, Attribute const &attr)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g, attr);
+
+ return result && !std::memcmp(generated.c_str(), expected, size);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Generator, typename Delimiter>
+ inline bool
+ binary_test_delimited(char const *expected, std::size_t size,
+ Generator const& g, Delimiter const& d)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d);
+
+ return result && !std::memcmp(generated.c_str(), expected, size);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Generator, typename Attribute, typename Delimiter>
+ inline bool
+ binary_test_delimited(char const *expected, std::size_t size,
+ Generator const& g, Attribute const &attr, Delimiter const& d)
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d, attr);
+
+ return result && !std::memcmp(generated.c_str(), expected, size);
+ }
+
+} // namespace spirit_test
+
+#endif // !BOOST_SPIRIT_KARMA_TEST_FEB_23_2007_1221PM

Deleted: trunk/libs/spirit/test/karma/confix.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/confix.cpp 2009-04-30 13:14:04 EDT (Thu, 30 Apr 2009)
+++ (empty file)
@@ -1,83 +0,0 @@
-// Copyright (c) 2001-2008 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 <boost/config/warning_disable.hpp>
-#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/karma_auxiliary.hpp>
-#include <boost/spirit/include/karma_char.hpp>
-#include <boost/spirit/include/karma_string.hpp>
-#include <boost/spirit/include/karma_generate.hpp>
-
-#include <iostream>
-#include "test.hpp"
-
-namespace html
-{
- ///////////////////////////////////////////////////////////////////////////////
- // define a HTML tag helper generator
- template <typename Char, typename Traits, typename Allocator>
- inline boost::spirit::confix_spec<std::basic_string<Char, Traits, Allocator> >
- tag (std::basic_string<Char, Traits, Allocator> const& tagname)
- {
- typedef std::basic_string<Char, Traits, Allocator> string_type;
- return boost::spirit::confix_spec<string_type>(
- string_type("<") + tagname + ">", string_type("</") + tagname + ">");
- }
-
- inline boost::spirit::confix_spec<std::string>
- tag (char const* tagname)
- {
- return tag(std::string(tagname));
- }
-
- typedef boost::spirit::confix_spec<std::string> html_tag_type;
-
- html_tag_type const ol = tag("ol");
-}
-
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- using namespace spirit_test;
- using namespace boost::spirit;
- using namespace boost::spirit::ascii;
-
- {
- BOOST_TEST((test("<tag>a</tag>",
- confix("<tag>", "</tag>")[char_('a')])));
- BOOST_TEST((test("// some C++ comment\n",
- confix(lit("//"), eol)[" some C++ comment"])));
- BOOST_TEST((test("<ol>some text</ol>", html::ol["some text"])));
- }
-
- {
- BOOST_TEST((test(L"<tag>a</tag>",
- confix(L"<tag>", L"</tag>")[wchar(L'a')])));
- BOOST_TEST((test(L"// some C++ comment\n",
- confix(wlit(L"//"), eol)[L" some C++ comment"])));
- BOOST_TEST((test(L"<ol>some text</ol>", html::ol[L"some text"])));
- }
-
- {
- BOOST_TEST((test_delimited("<tag> a </tag> ",
- confix("<tag>", "</tag>")[char_('a')], space)));
- BOOST_TEST((test_delimited("// some C++ comment \n ",
- confix(lit("//"), eol)["some C++ comment"], space)));
- BOOST_TEST((test_delimited("<ol> some text </ol> ",
- html::ol["some text"], space)));
- }
-
- {
- BOOST_TEST((test_delimited(L"<tag> a </tag> ",
- confix(L"<tag>", L"</tag>")[wchar(L'a')], space)));
- BOOST_TEST((test_delimited(L"// some C++ comment \n ",
- confix(wlit(L"//"), eol)[L"some C++ comment"], space)));
- BOOST_TEST((test_delimited(L"<ol> some text </ol> ",
- html::ol[L"some text"], space)));
- }
-
- return boost::report_errors();
-}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk