]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/example/x3/rexpr/rexpr_full/test/parse_rexpr_test.cpp
4361564e8502414b2d77219968495a82040f6116
1 /*=============================================================================
2 Copyright (c) 2001-2015 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
12 #include "../rexpr/ast.hpp"
13 #include "../rexpr/rexpr.hpp"
14 #include "../rexpr/error_handler.hpp"
15 #include "../rexpr/config.hpp"
16 #include "../rexpr/printer.hpp"
18 #include "testing.hpp"
20 namespace fs
= boost::filesystem
;
21 namespace testing
= boost::spirit::x3::testing
;
23 auto parse
= [](std::string
const& source
, fs::path input_path
)-> std::string
25 std::stringstream out
;
27 using rexpr::parser::iterator_type
;
28 iterator_type
iter(source
.begin());
29 iterator_type
const end(source
.end());
32 rexpr::ast::rexpr ast
;
35 using boost::spirit::x3::with
;
36 using rexpr::parser::error_handler_type
;
37 using rexpr::parser::error_handler_tag
;
38 error_handler_type
error_handler(iter
, end
, out
, input_path
.string()); // Our error handler
42 // we pass our error handler to the parser so we can access
43 // it later on in our on_error and on_sucess handlers
44 with
<error_handler_tag
>(std::ref(error_handler
))
49 // Go forth and parse!
50 using boost::spirit::x3::ascii::space
;
51 bool success
= phrase_parse(iter
, end
, parser
, space
, ast
);
56 error_handler(iter
, "Error! Expecting end of input here: ");
58 rexpr::ast::rexpr_printer
{out
}(ast
);
64 int num_files_tested
= 0;
65 int num_tests_failed
= 0;
66 auto compare
= [](fs::path input_path
, fs::path expect_path
)
68 if (!testing::compare(input_path
, expect_path
, parse
))
73 int main(int argc
, char* argv
[])
77 std::cout
<< "usage: " << fs::path(argv
[0]).filename() << " path/to/test/files" << std::endl
;
81 std::cout
<< "===================================================================================================" << std::endl
;
82 std::cout
<< "Testing: " << fs::absolute(fs::path(argv
[1])) << std::endl
;
83 int r
= testing::for_each_file(fs::path(argv
[1]), compare
);
85 std::cout
<< num_files_tested
<< " files tested." << std::endl
;
86 std::cout
<< "===================================================================================================" << std::endl
;
87 return num_tests_failed
;