diff --git a/test/generate_scalar_tests.cpp b/test/generate_scalar_tests.cpp deleted file mode 100644 index bf90690f..00000000 --- a/test/generate_scalar_tests.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright (C) 2010, 2011 Object Modeling Designs - */ - -#include "../yaml/generator/scalar_def.hpp" -#include - -namespace -{ - /////////////////////////////////////////////////////////////////////////// - template - struct output_iterator - { - typedef std::basic_string string_type; - typedef std::back_insert_iterator type; - }; - - /////////////////////////////////////////////////////////////////////////// - template - void print_if_failed(char const* func, bool result - , std::basic_string const& generated, T const& expected) - { - if (!result) - std::cerr << "in " << func << ": result is false" << std::endl; - else if (generated != expected) - std::cerr << "in " << func << ": generated \"" - << std::string(generated.begin(), generated.end()) - << "\"" << std::endl; - } - - /////////////////////////////////////////////////////////////////////////// - template - inline bool test(Char const *expected, Generator const& g, Attr const& attr) - { - namespace karma = boost::spirit::karma; - typedef std::basic_string string_type; - - string_type generated; - std::back_insert_iterator outit(generated); - bool result = karma::generate(outit, g, attr); - - print_if_failed("test", result, generated, expected); - return result && generated == expected; - } -} - -int main() -{ - using omd::generator::scalar; - using omd::ast::value_t; - using omd::ast::null_t; - - scalar::type> g; - - BOOST_TEST(test("12345", g, value_t(12345))); - BOOST_TEST(test("true", g, value_t(true))); - BOOST_TEST(test("false", g, value_t(false))); - BOOST_TEST(test("123.45", g, value_t(123.45))); - BOOST_TEST(test("123.456789012", g, value_t(123.456789012))); - BOOST_TEST(test("null", g, value_t(null_t()))); - BOOST_TEST(test("\"Hello, World\"", g, value_t(std::string("Hello, World")))); - - return boost::report_errors(); -} - diff --git a/test/parse_json_test.cpp b/test/parse_json_test.cpp deleted file mode 100644 index 7931a939..00000000 --- a/test/parse_json_test.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright (C) 2010, 2011 Object Modeling Designs - */ - -//~ #define BOOST_SPIRIT_DEBUG - -#include "../yaml/parser/flow_def.hpp" -#include "../yaml/parser/scalar_def.hpp" - -#include -#include - -#include -#include - -namespace -{ - template - bool parse( - std::basic_istream& is, - omd::ast::value_t& result, - std::string const& source_file = "") - { - std::string file; // We will read the contents here. - is.unsetf(std::ios::skipws); // No white space skipping! - std::copy( - std::istream_iterator(is), - std::istream_iterator(), - std::back_inserter(file)); - - typedef std::string::const_iterator base_iterator_type; - base_iterator_type sfirst(file.begin()); - base_iterator_type slast(file.end()); - - typedef boost::spirit::classic::position_iterator - iterator_type; - iterator_type first(sfirst, slast); - iterator_type last; - first.set_tabchars(1); - - int indent = 0; - omd::parser::flow p(indent, source_file); - omd::parser::white_space ws; - - using boost::spirit::qi::phrase_parse; - return phrase_parse(first, last, p, ws, result); - } -} - -/////////////////////////////////////////////////////////////////////////////// -// Main program -/////////////////////////////////////////////////////////////////////////////// -int main(int argc, char **argv) -{ - char const* filename = NULL; - if (argc > 1) - { - filename = argv[1]; - } - else - { - std::cerr << "Error: No input file provided." << std::endl; - return 1; - } - - std::ifstream in(filename, std::ios_base::in); - - if (!in) - { - std::cerr << "Error: Could not open input file: " - << filename << std::endl; - return 1; - } - - // Ignore the BOM marking the beginning of a UTF-8 file in Windows - char c = in.peek(); - if (c == '\xef') - { - char s[4]; - in >> s[0] >> s[1] >> s[2]; - s[3] = '\0'; - if (s != std::string("\xef\xbb\xbf")) - { - std::cerr << "Error: Unexpected characters from input file: " - << filename << std::endl; - return 1; - } - } - - using omd::ast::value_t; - namespace qi = boost::spirit::qi; - - value_t result; - if (parse(in, result, filename)) - { - std::cout << "success: \n"; - omd::ast::print_json(std::cout, result); - std::cout << std::endl; - } - else - { - std::cout << "parse error" << std::endl; - } - - return 0; -} \ No newline at end of file diff --git a/test/parse_scalar_tests.cpp b/test/parse_scalar_tests.cpp deleted file mode 100644 index 9f5f042f..00000000 --- a/test/parse_scalar_tests.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (C) 2010, 2011 Object Modeling Designs - */ - -#include "../yaml/parser/scalar_def.hpp" -#include - -namespace -{ - template - bool test_attr(Char const* in, Parser const& p - , Attr& attr, bool full_match = true) - { - Char const* last = in; - while (*last) - last++; - return boost::spirit::qi::parse(in, last, p, attr) - && (!full_match || (in == last)); - } -} - -#define SCALAR_TEST(input, type, expected) \ - { \ - BOOST_TEST(test_attr(input, g, attr)); \ - BOOST_TEST(boost::get(attr.get()) == expected); \ - } \ - /***/ - -int main() -{ - using omd::parser::scalar; - using omd::ast::value_t; - using omd::ast::null_t; - - int indent = 0; - scalar g(indent); - value_t attr; - - SCALAR_TEST("12345", int, 12345); - SCALAR_TEST("true", bool, true); - SCALAR_TEST("False", bool, false); - SCALAR_TEST("On", bool, true); - SCALAR_TEST("123.45", double, 123.45); - SCALAR_TEST("0x4D2", int, 0x4D2); - SCALAR_TEST("02333", int, 02333); - SCALAR_TEST("~", null_t, null_t()); - SCALAR_TEST("null", null_t, null_t()); - - SCALAR_TEST("\"Hello, World\"", std::string, "Hello, World"); - SCALAR_TEST("\"this is a unicode \u20AC string\"", - std::string, "this is a unicode € string"); - - return boost::report_errors(); -} - diff --git a/test/test_files/gold.txt b/test/test_files/gold.txt index 9914838c..971d3e4b 100644 --- a/test/test_files/gold.txt +++ b/test/test_files/gold.txt @@ -21,18 +21,23 @@ success: C:\dev\yaml_spirit\test\test_files>C:\dev\compile\parse_yaml_test.exe C:\dev\yaml_spirit\test\test_files\scalar.yaml success: -booleans : [true, false] +booleans1 : [true, false] +booleans2 : [true, false] +booleans3 : [true, false] canonical-f : 1230.15 canonical-i : 12345 control : "\b1998\t1999\t2000\n" decimal : 12345 exponential : 1230.15 fixed : 1230.15 +hex : 1234 hex esc : "\r\n is \r\n" hexadecimal : 12 negative infinity : -.inf not a number : .NaN -null : null +null1 : null +null2 : null +oct : 1243 octal : 12 plain : "This unquoted scalar spans many lines." quoted : "So does this\n quoted scalar.\n" diff --git a/test/test_files/scalar.yaml b/test/test_files/scalar.yaml index 388d6072..3eafaea1 100644 --- a/test/test_files/scalar.yaml +++ b/test/test_files/scalar.yaml @@ -24,8 +24,13 @@ fixed: 1230.15 negative infinity: -.inf not a number: .NaN -null: -booleans: [ true, false ] +null1: +null2: ~ +booleans1: [ true, false ] +booleans2: [ True, False ] +booleans3: [ On, Off ] +hex: 0x4D2 +oct: 02333 string: '012345' ## $$$ JDG FIXME UNIMPLEMENTED $$$ ## diff --git a/yaml/generator/scalar.hpp b/yaml/generator/scalar.hpp deleted file mode 100644 index a915c0e8..00000000 --- a/yaml/generator/scalar.hpp +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (C) 2010, 2011 Object Modeling Designs - */ - -#if !defined(OMD_GENERATOR_SCALAR_HPP) -#define OMD_GENERATOR_SCALAR_HPP - -#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS - -#include - -#include - -#include "../ast.hpp" // our AST - -namespace omd { namespace generator -{ - namespace karma = boost::spirit::karma; - namespace ascii = boost::spirit::ascii; - - typedef boost::uint32_t uchar; // a unicode code point - - template - struct scalar : karma::grammar - { - scalar(); - - karma::rule value; - karma::rule null_value; - karma::rule string_value; - }; -}} - -#endif diff --git a/yaml/generator/scalar_def.hpp b/yaml/generator/scalar_def.hpp deleted file mode 100644 index f3c69e08..00000000 --- a/yaml/generator/scalar_def.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (C) 2010, 2011 Object Modeling Designs - */ - -#if !defined(OMD_GENERATOR_SCALAR_DEF_HPP) -#define OMD_GENERATOR_SCALAR_DEF_HPP - -#include "scalar.hpp" - -#include -#include - -namespace boost { namespace spirit { namespace traits -{ - // this specialization tells Spirit that omd::ast::value_t is a variant- - // like type - template <> - struct not_is_variant - : mpl::false_ - {}; - - // this specialization tells Spirit how to extract the type of the value - // stored in the given omd::ast::value_t node - template <> - struct variant_which - { - static int call(omd::ast::value_t const& v) - { - return v.get().which(); - } - }; -}}} - -namespace omd { namespace generator -{ - /////////////////////////////////////////////////////////////////////////// - template - struct max_precision_policy : boost::spirit::karma::real_policies - { - static unsigned int precision(T) - { - return 6; // same as std C++ library default - } - }; - - typedef karma::real_generator > - max_precision_double_type; - max_precision_double_type const max_precision_double = - max_precision_double_type(); - - /////////////////////////////////////////////////////////////////////////// - template - scalar::scalar() - : scalar::base_type(value) - { - karma::int_type int_; - karma::bool_type bool_; - karma::char_type char_; - karma::lit_type lit; - using boost::spirit::attr_cast; - - value = - max_precision_double - | int_ - | bool_ - | string_value - | null_value - ; - - null_value = attr_cast(lit("null")); - - string_value = '"' << *(&char_('"') << "\\\"" | char_) << '"'; - } -}} - -#endif