Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81003 - trunk/libs/spirit/example/qi/json
From: joel_at_[hidden]
Date: 2012-10-17 00:02:04


Author: djowel
Date: 2012-10-17 00:02:03 EDT (Wed, 17 Oct 2012)
New Revision: 81003
URL: http://svn.boost.org/trac/boost/changeset/81003

Log:
added test case
Added:
   trunk/libs/spirit/example/qi/json/test.cpp (contents, props changed)

Added: trunk/libs/spirit/example/qi/json/test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/json/test.cpp 2012-10-17 00:02:03 EDT (Wed, 17 Oct 2012)
@@ -0,0 +1,78 @@
+/**
+ * Copyright (C) 2012 ciere consulting, ciere.com
+ * Copyright (C) 2010, 2011 Object Modeling Designs
+ */
+
+#include <boost/detail/lightweight_test.hpp>
+#include "value.hpp"
+#include "io.hpp"
+#include "parser/grammar.hpp"
+#include "parser/grammar_def.hpp"
+
+
+int main()
+{
+ boost::spirit::ascii::space_type space;
+
+ {
+ typedef std::string::const_iterator iter_t;
+ typedef ciere::json::parser::grammar<iter_t> grammar_t;
+
+ std::string test_input(
+ "{"
+ " \"value\" : 12.34,"
+ " \"on\" : false,"
+ " \"jump\" : null,"
+ " \"result\" : [1,34.5,{},\"Sosa did fine.\\u263A\",\"Snowman: \\u2603\"]"
+ "}"
+ );
+
+ grammar_t grammar;
+ ciere::json::value value;
+
+ std::cout << "test input: " << test_input << std::endl;
+
+ iter_t iter = test_input.begin();
+ iter_t end = test_input.end();
+
+ BOOST_TEST( boost::spirit::qi::phrase_parse( iter, end, grammar, space, value ) );
+ BOOST_TEST( iter == end );
+
+ std::cout << "ast : " << value << std::endl;
+ }
+
+ {
+ typedef std::string::const_iterator iter_t;
+ typedef ciere::json::parser::grammar<iter_t> grammar_t;
+
+ std::string test_input(
+ "{"
+ " \"foo\":123.456,"
+ " \"the_value\": 42,"
+ " \"bar\":[1,\"some test \", {\"on\":false,\"object\":null}],"
+ " \"gorp\":\"how about this mom\""
+ "}"
+ );
+
+ grammar_t grammar;
+ ciere::json::value value;
+
+ std::cout << "test input: " << test_input << std::endl;
+
+ iter_t iter = test_input.begin();
+ iter_t end = test_input.end();
+
+ BOOST_TEST( boost::spirit::qi::phrase_parse( iter, end, grammar, space, value ) );
+ BOOST_TEST( iter == end );
+
+ std::cout << "ast : " << value << std::endl;
+ value["bar"].erase(1);
+ std::cout << "ast post erase : " << value << std::endl;
+ value.erase("bar");
+ std::cout << "ast post erase : " << value << std::endl;
+ }
+
+ BOOST_TEST(0); // show some output
+ 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