7 #define BOOST_TEST_MODULE (document test) 9 #include "boost/test/unit_test.hpp" 26 using namespace fhicl;
29 BOOST_AUTO_TEST_SUITE(document_test)
35 BOOST_TEST(pset.is_empty());
43 BOOST_TEST(!pset.is_empty());
44 BOOST_TEST(pset.get<
int>(
"a") == 1);
45 BOOST_TEST(pset.get<
int>(
"b") == 2);
46 BOOST_TEST(pset.get<
unsigned>(
"a") == 1u);
47 BOOST_TEST(pset.get<
unsigned>(
"b") == 2u);
48 BOOST_TEST(pset.get<
string>(
"a") ==
"1");
49 BOOST_TEST(pset.get<
string>(
"b") ==
"2");
58 BOOST_TEST(!pset.is_empty());
61 BOOST_TEST(pset.get<
int>(
"x.a") == 1);
62 BOOST_TEST(pset.get<
int>(
"x.b") == 2);
63 BOOST_TEST(pset.get<
unsigned>(
"x.a") == 1u);
64 BOOST_TEST(pset.get<
unsigned>(
"x.b") == 2u);
65 BOOST_TEST(pset.get<
string>(
"x.a") ==
"1");
66 BOOST_TEST(pset.get<
string>(
"x.b") ==
"2");
88 BOOST_TEST(pset.get<
int>(
"a") == 2);
91 BOOST_TEST(pset.get<
int>(
"t.a") == 12);
107 BOOST_TEST(tbl.exists(
"c"));
134 BOOST_TEST(pset.get<
int>(
"a") == 6);
135 BOOST_TEST(pset.get<
int>(
"b") == 5);
136 BOOST_TEST(pset.get<
int>(
"c") == 4);
149 BOOST_TEST(pset.get<
int>(
"t.a") == 6);
150 BOOST_TEST(pset.get<
int>(
"t.b") == 5);
151 BOOST_TEST(pset.get<
int>(
"t.c") == 4);
167 using nil_t = std::nullptr_t;
168 BOOST_TEST(pset.get<nil_t>(
"a") == nil_t{});
169 BOOST_TEST(pset.get<nil_t>(
"t.a") == nil_t{});
174 BOOST_TEST(pset.get<
string>(
"b") ==
"nil");
175 BOOST_TEST(pset.get<
string>(
"t.b") ==
"nil");
176 BOOST_TEST(pset.get<
string>(
"c") ==
"@nil");
177 BOOST_TEST(pset.get<
string>(
"t.c") ==
"@nil");
178 BOOST_TEST(pset.get<
string>(
"d") ==
"nil");
179 BOOST_TEST(pset.get<
string>(
"t.d") ==
"nil");
190 "b: { x: 7 y: 12 }\n" 191 "c: { x: 7 y: 12 x: @erase }\n" 195 BOOST_TEST(tbl.exists(
"x"));
196 BOOST_TEST(!tbl.exists(
"z"));
197 BOOST_TEST(!tbl.exists(
"a"));
198 BOOST_TEST(tbl.exists(
"b"));
199 BOOST_TEST(!tbl.exists(
"b.x"));
200 BOOST_TEST(tbl.exists(
"b.y"));
201 BOOST_TEST(tbl.exists(
"c"));
202 BOOST_TEST(!tbl.exists(
"c.x"));
203 BOOST_TEST(tbl.exists(
"c.y"));
209 "A: { B: { x: foo } }\n" 214 " B:{ @table::A.B x:bar }\n" 224 "fred: { bill: twelve charlie: 27 }\n" 225 "y: { @table::fred bill: \"one dozen\" }\n" 227 "x: { ethel: 14 bill: 12 @table::fred }\n" 231 BOOST_TEST(tbl.exists(
"x.ethel"));
232 BOOST_TEST(tbl.exists(
"x.charlie"));
233 BOOST_TEST(tbl.exists(
"bill"));
234 BOOST_TEST(tbl.exists(
"charlie"));
235 BOOST_TEST(tbl.exists(
"y.bill"));
236 BOOST_TEST(tbl.exists(
"y.charlie"));
245 "fred: [ three, four, five ]\n" 247 "bill: [ one, two, @sequence::fred, six ]\n" 248 "charlie: @local::fred\n" 249 "ethel: [ @sequence::fred, six ]\n";
251 BOOST_TEST(tbl.exists(
"fred"));
252 BOOST_TEST(tbl.exists(
"bill"));
253 BOOST_TEST(tbl.exists(
"charlie"));
254 BOOST_TEST(tbl.exists(
"ethel"));
258 BOOST_TEST(pset.get<std::vector<std::string>>(
"charlie").size() == 3ul);
260 std::vector<std::string>
const billref{
261 "one",
"two",
"three",
"four",
"five",
"six"};
262 std::vector<std::string>
const ethelref{
"three",
"four",
"five",
"six"};
264 auto cmp = [](std::vector<std::string>
const& seq,
265 std::vector<std::string>
const& ref) {
266 BOOST_TEST(seq.size() == ref.size());
267 for (
auto i = seq.cbegin(),
e = seq.cend(), iref = ref.cbegin(); i !=
e;
269 BOOST_TEST(*i == *iref);
273 cmp(pset.get<std::vector<std::string>>(
"bill"), billref);
274 cmp(pset.get<std::vector<std::string>>(
"ethel"), ethelref);
304 "f: [ @sequence::bad ]\n";
314 std::vector<std::string> refs{
317 "s2: [ 1, 2, @sequence::s ]\n",
318 "a: @id::0001020304050607080910111213141516171819\n",
319 "t1: { t2: @local::t }\n",
320 "t1: { @table::t }\n",
321 "t1: { s1: [ 1, 2, 3, @sequence::s ] }\n",
322 "t1: { a: @id::0001020304050607080910111213141516171819 }\n",
324 for (
auto const& ref : refs) {
326 auto const cpos = ref.find(
"::");
330 bad1.insert(cpos,
" ");
332 bad2.insert(cpos + 2,
" ");
343 BOOST_TEST(tbl.get<std::size_t>(
"x") == 29ul);
349 "x @protect_ignore: 29\n" 354 BOOST_TEST(tbl.get<std::size_t>(
"x") == 37ul);
360 "x @protect_ignore: 29\n" 362 "x @protect_ignore: 33\n" 365 BOOST_TEST(tbl.get<std::size_t>(
"x") == 33ul);
368 #define PV_EXCEPTION \ 369 BOOST_CHECK_EXCEPTION(parse_document(doc), \ 371 [](fhicl::exception const& e) -> bool { \ 372 return e.categoryCode() == \ 373 fhicl::error::parse_error && \ 374 e.root_cause() == "Protection violation"; \ 380 "x @protect_ignore: 33\n";
382 BOOST_TEST(tbl.get<std::size_t>(
"x") == 29ul);
388 "x @protect_ignore: 29\n" 389 "x @protect_ignore: 33\n" 392 BOOST_TEST(tbl.get<std::size_t>(
"x") == 29ul);
401 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 29ul);
407 "a: { x @protect_ignore: 29 }\n" 412 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 37ul);
419 "a: { x @protect_ignore: 29 } \n" 421 "a.x @protect_ignore: 33\n" 424 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 33ul);
430 "a.x @protect_ignore: 33\n";
432 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 29ul);
438 "a: { x @protect_ignore: 29 }\n" 439 "a.x @protect_ignore: 33\n" 442 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 29ul);
451 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 29ul);
457 "a @protect_ignore: { x: 29 }\n" 462 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 37ul);
468 "a @protect_ignore: { x: 29 }\n" 470 "a @protect_ignore: { x: 33 }\n" 473 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 33ul);
479 "a @protect_ignore: { x: 33 }\n";
481 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 29ul);
487 "a @protect_ignore: { x: 29 }\n" 488 "a @protect_ignore: { x: 33 }\n" 491 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 29ul);
500 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 29ul);
506 "a: { b @protect_ignore: { x: 29 } }\n" 509 "a: { b @protect_ignore: { x: 37 } }\n" 512 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 37ul);
518 "a: { b @protect_ignore: { x: 29 } }\n" 520 "a: { b @protect_ignore: { x: 33 } }\n" 523 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 33ul);
529 "a: { b @protect_ignore: { x: 33 } }\n";
531 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 33ul);
537 "a: { b @protect_ignore: { x: 29 } }\n" 538 "a: { b @protect_ignore: { x: 33 } }\n" 541 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 33ul);
547 "a.x @protect_ignore: 33\n";
555 "a.x @protect_ignore: 33\n" 567 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 29ul);
575 "x @protect_error: 29\n" 584 "x @protect_error: 29\n" 588 BOOST_TEST(tbl.get<std::size_t>(
"x") == 33ul);
594 "x @protect_error: 29\n" 596 "x @protect_error: 33\n" 604 "x @protect_ignore: 29\n" 605 "x @protect_error: 33\n" 613 "x @protect_error: 33\n";
620 "a: { x @protect_error: 33 }\n";
622 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 33ul);
628 "a: { x @protect_error: 29 }\n" 629 "a: { x @protect_error: 33 }\n" 632 BOOST_TEST(tbl.get<std::size_t>(
"a.x") == 33ul);
638 "a: { x @protect_error: 29 }\n" 654 "a: { b: { x @protect_error: 29 } } \n" 663 "a: { b @protect_error: { x: 29 } }\n" 674 BOOST_TEST(tbl.empty());
684 BOOST_TEST(tbl.empty());
692 BOOST_TEST(tbl.get<std::size_t>(
"x") == 29ul);
707 BOOST_TEST(tbl.empty());
715 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 29ul);
723 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 29ul);
728 std::string const doc =
"a: { b @protect_ignore: { c: { x: 29 } } }\n" 731 BOOST_TEST(tbl.get<std::size_t>(
"a.b.c.x") == 29ul);
736 std::string const doc =
"a: { b @protect_error: { c: { x: 29 } } }\n" 743 std::string const doc =
"a: { b @protect_error: { c: { x: 29 } } }\n" 753 BOOST_TEST(tbl.empty());
770 BOOST_TEST(tbl.get<std::size_t>(
"b") == 42ul);
780 BOOST_TEST(tbl.get<std::size_t>(
"b") == 43ul);
789 BOOST_TEST(tbl.get<std::size_t>(
"b") == 43ul);
795 "x @protect_ignore: 27\n" 796 "a: { b: { x: @local::x } }\n" 801 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 29ul);
808 "x @protect_ignore: 27\n" 809 "a: { b: { x: @local::x } }\n" 811 "a @protect_error: @local::a\n" 819 "x @protect_ignore: 27\n" 820 "a: { b: { x: @local::x } }\n" 822 "a @protect_ignore: @local::a\n" 825 BOOST_TEST(tbl.get<std::size_t>(
"a.b.x") == 27ul);
837 static std::regex
const RE(
838 "detected at or near line (\\d+), character (\\d+)");
841 result = std::regex_search(match_string, sm, RE) &&
848 #define PARSE_ERROR(line, charpos) \ 849 BOOST_CHECK_EXCEPTION( \ 850 parse_document(doc), \ 852 std::bind(&is_parse_error_at, std::placeholders::_1, line, charpos)); 881 BOOST_AUTO_TEST_SUITE_END()
static ParameterSet make(intermediate_table const &tbl)
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
std::string to_string(Protection p)
#define PARSE_ERROR(line, charpos)
std::ostream & boost_test_print_type(std::ostream &os, ParameterSet const &pset)
BOOST_AUTO_TEST_CASE(empty_document)
intermediate_table parse_document(std::string const &filename, cet::filepath_maker &maker)
void line(double t, double *p, double &x, double &y, double &z)
std::string to_string(ModuleType const mt)
cet::coded_exception< error, detail::translate > exception