MCPcopy Create free account
hub / github.com/boostorg/parser / main

Function main

test/parser_attributes.cpp:22–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20BOOST_PARSER_DEFINE_RULES(seq1, seq2);
21
22int main()
23{
24 // These are just some assorted cases that have, or seemed likely to,
25 // cause problems when an internal failure in an alternative wipes out an
26 // existing result. This covers all the cases where "if (!success)"
27 // causes the attribute to be overwritten with a default-constructed
28 // value.
29
30 {
31 auto const parser =
32 bp::string("FOO") >> -(bp::string("bar") | bp::string("foo"));
33
34 auto result = bp::parse("FOOfoo", parser);
35 BOOST_TEST(result);
36 BOOST_TEST(bp::get(*result, bp::llong<0>{}) == std::string("FOO"));
37 BOOST_TEST(bp::get(*result, bp::llong<1>{}) == std::string("foo"));
38 }
39
40 {
41 auto const parser = bp::merge
42 [bp::string("FOO") >> (bp::string("bar") | bp::string("foo"))];
43
44 auto result = bp::parse("FOOfoo", parser);
45 BOOST_TEST(result);
46 BOOST_TEST(*result == std::string("FOOfoo"));
47 }
48
49 {
50 auto const parser = bp::merge
51 [(bp::attr(std::vector<std::string>({"FOO"})) | bp::eps) >>
52 (bp::repeat(1)[bp::string("foo")] | bp::eps)];
53
54 auto result = bp::parse("", parser);
55 BOOST_TEST(result);
56 BOOST_TEST(*result);
57 BOOST_TEST(*result == std::vector<std::string>({"FOO"}));
58 }
59
60 {
61 auto const parser = bp::merge[seq1 >> (seq2 | seq1)];
62
63 auto result = bp::parse("7a9a", parser);
64 BOOST_TEST(result);
65 BOOST_TEST(*result == (bp::tuple<int, char>(9, 'a')));
66 }
67
68 return boost::report_errors();
69}

Callers

nothing calls this directly

Calls 5

attrFunction · 0.85
repeatFunction · 0.85
stringClass · 0.50
parseFunction · 0.50
getFunction · 0.50

Tested by

no test coverage detected