intermediate_table_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (intermediate_table_t)
2 #include "boost/test/unit_test.hpp"
3 
6 
7 #include <string>
8 #include <vector>
9 
10 using namespace fhicl;
11 
12 BOOST_AUTO_TEST_SUITE(intermediate_table_t)
13 
15 {
16  intermediate_table table;
19  table.put("string1", "string");
20  table.put("string2", std::string("string"));
21  table.put("complex", std::complex<double>(-3, -0.5));
22  table.put("sequence", std::vector<int>{5, 10, 15, 20, 25});
23  table.put("double", 28.5);
24  table.put("sequence[6]", 35);
25  table.put("table.val1", 92);
26  table.put("table.t1.val", "oops");
27  BOOST_CHECK_NO_THROW(table.erase("table.t1.waldo"));
28  BOOST_CHECK_NO_THROW(table.erase("table.t1.val"));
29  BOOST_TEST(!table.exists("table.t1.val"));
30  BOOST_CHECK_THROW(table.erase("table.val1.valX"), fhicl::exception);
31  BOOST_TEST(table.get<std::string>("string1") == "string");
32  BOOST_TEST(table.get<std::string>("string2") == "string");
33  BOOST_TEST(table.get<std::complex<double>>("complex") ==
34  std::complex<double>(-3, -0.5));
35  BOOST_TEST(table.get<sequence_t const&>("sequence").size() == 7u);
36  BOOST_TEST(table.get<int>("sequence[3]") == 20);
37  BOOST_CHECK_THROW(table.get<int>("sequence[5]"), fhicl::exception); // Nil
38  BOOST_TEST(table.get<table_t const&>("table").size() == 2u);
39  BOOST_TEST(table.get<table_t const&>("table.t1").size() == 0u);
40 }
41 
42 BOOST_AUTO_TEST_CASE(prolog_erase_nested)
43 {
44  char const* cfg = R"(BEGIN_PROLOG
45 w: { x: { y: { z: { a: 2 b: 3 } } } }
46 END_PROLOG
47 q: { @table::w.x.y })";
48  auto const pset = ParameterSet::make(cfg);
49  BOOST_TEST(pset.has_key("q.z"));
50  BOOST_TEST(!pset.has_key("w"));
51 }
52 
53 BOOST_AUTO_TEST_CASE(prolog_erase_dotted)
54 {
55  char const* cfg = R"(BEGIN_PROLOG
56 w.x.y: { z: { a: 2 b: 3 } }
57 END_PROLOG
58 q: { @table::w.x.y })";
59  auto const pset = ParameterSet::make(cfg);
60  BOOST_TEST(pset.has_key("q.z"));
61  BOOST_TEST(!pset.has_key("w"));
62 }
63 
64 BOOST_AUTO_TEST_CASE(prolog_nested_partial_dup_nested)
65 {
66  char const* cfg = R"(BEGIN_PROLOG
67 w: { x: { y: 7 } }
68 END_PROLOG
69 w: { b: { c: 6 } })";
70  auto const pset = ParameterSet::make(cfg);
71  BOOST_TEST(pset.has_key("w.b"));
72  BOOST_TEST(!pset.has_key("w.x"));
73 }
74 
75 BOOST_AUTO_TEST_CASE(prolog_nested_partial_dup_dotted)
76 {
77  char const* cfg = R"(BEGIN_PROLOG
78 w: { x: { y: 7 } }
79 END_PROLOG
80 w.b.c: 6)";
81  auto const pset = ParameterSet::make(cfg);
82  BOOST_TEST(pset.has_key("w.b"));
83  BOOST_TEST(!pset.has_key("w.x"));
84 }
85 
86 BOOST_AUTO_TEST_CASE(prolog_dotted_partial_dup_nested)
87 {
88  char const* cfg = R"(BEGIN_PROLOG
89 w.x.y: 7
90 END_PROLOG
91 w: { b: { c: 6 } })";
92  auto const pset = ParameterSet::make(cfg);
93  BOOST_TEST(pset.has_key("w.b"));
94  BOOST_TEST(!pset.has_key("w.x"));
95 }
96 
97 BOOST_AUTO_TEST_CASE(prolog_dotted_partial_dup_dotted)
98 {
99  char const* cfg = R"(BEGIN_PROLOG
100 w.x.y: 7
101 END_PROLOG
102 w.b.c: 6)";
103  auto const pset = ParameterSet::make(cfg);
104  BOOST_TEST(pset.has_key("w.b"));
105  BOOST_TEST(!pset.has_key("w.x"));
106 }
107 
108 BOOST_AUTO_TEST_CASE(prolog_nested_dup_nested)
109 {
110  char const* cfg = R"(BEGIN_PROLOG
111 w: { x: { y: 7 } }
112 END_PROLOG
113 w: { x: { c: 6 } })";
114  auto const pset = ParameterSet::make(cfg);
115  BOOST_TEST(pset.has_key("w.x.c"));
116  BOOST_TEST(!pset.has_key("w.x.y"));
117 }
118 
119 BOOST_AUTO_TEST_CASE(prolog_nested_dup_dotted)
120 {
121  char const* cfg = R"(BEGIN_PROLOG
122 w: { x: { y: 7 } }
123 END_PROLOG
124 w.x.c: 6)";
125  auto const pset = ParameterSet::make(cfg);
126  BOOST_TEST(pset.has_key("w.x.c"));
127  BOOST_TEST(!pset.has_key("w.x.y"));
128 }
129 
130 BOOST_AUTO_TEST_CASE(prolog_dotted_dup_nested)
131 {
132  char const* cfg = R"(BEGIN_PROLOG
133 w.x.y: 7
134 END_PROLOG
135 w: { x: { c: 6 } })";
136  auto const pset = ParameterSet::make(cfg);
137  BOOST_TEST(pset.has_key("w.x.c"));
138  BOOST_TEST(!pset.has_key("w.x.y"));
139 }
140 
141 BOOST_AUTO_TEST_CASE(prolog_dotted_dup_dotted)
142 {
143  char const* cfg = R"(BEGIN_PROLOG
144 w.x.y: 7
145 END_PROLOG
146 w.x.c: 6)";
147  auto const pset = ParameterSet::make(cfg);
148  BOOST_TEST(pset.has_key("w.x.c"));
149  BOOST_TEST(!pset.has_key("w.x.y"));
150 }
151 
152 BOOST_AUTO_TEST_SUITE_END()
size_type size() const
Definition: stdmap_shims.h:282
std::string string
Definition: nybbler.cc:12
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
extended_value::sequence_t sequence_t
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
extended_value::table_t table_t
bool exists(std::string const &key) const
fhicl::extended_value::sequence_t sequence_t
void erase(std::string const &key, bool in_prolog=false)
T get(std::string const &name)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE(main)