42 using LERR_(INDEX_BOUNDS);
43 using LERR_(BOTTOM_VALUE);
47 using Seq = vector<string>;
52 contents (IT
const& it)
55 append_all (it, collected);
60 contents (
RecS const& rec_of_strings)
62 return contents (rec_of_strings.
begin());
67 strings (std::initializer_list<X>
const& con)
71 collected.push_back(elm);
136 RecS enterprise(
"starship" 137 , strings ({
"Name = USS Enterprise" 138 ,
"Registry = NCC-1701-D" 140 ,
"Owner = United Federation of Planets" 141 ,
"Operator= Starfleet" 144 , strings ({
"Picard",
"Riker",
"Data",
"Troi",
"Worf",
"Crusher",
"La Forge"})
147 CHECK (enterprise.getType() ==
"starship");
148 CHECK (enterprise.get(
"Registry") ==
"NCC-1701-D");
149 CHECK (enterprise.child(0) ==
"Picard");
150 CHECK (enterprise.child(2) ==
"Data");
152 CHECK (enterprise.hasAttribute(
"Owner"));
153 CHECK (!enterprise.hasAttribute(
"owner"));
154 CHECK (!enterprise.hasAttribute(
"Owner "));
156 CHECK (enterprise.contains(
"Data"));
157 CHECK (!enterprise.contains(
"Woof"));
158 CHECK (util::contains (enterprise,
"Worf"));
163 cout <<
"enterprise = " 164 << enterprise <<endl;
165 for (
string elm : enterprise)
167 cout <<
"--Attributes--"<<endl;
168 for (
string att : enterprise.attribs())
170 cout <<
"--Keys--->" << join (enterprise.keys(),
"<->")<<endl;
171 cout <<
"--Vals--->" << join (enterprise.vals(),
"<->")<<endl;
172 cout <<
"--Crew--->" << join (enterprise.scope(),
" | ")<<endl;
181 CHECK (
"NIL" == nil.getType());
182 CHECK (RecS::TYPE_NIL == nil.getType());
184 CHECK (!nil.begin());
185 CHECK (nil.begin() == nil.end());
189 CHECK (!isnil(untyped));
190 CHECK (
"NIL" == untyped.getType());
191 CHECK (Seq{
"x"} == contents(untyped));
192 CHECK (Seq{
"x"} == contents(untyped.scope()));
193 CHECK (isnil (untyped.attribs()));
195 RecS untyped2({
"x=y",
"z"});
196 CHECK (!isnil(untyped2));
197 CHECK (
"NIL" == untyped2.getType());
198 CHECK (Seq({
"x=y",
"z"}) == contents(untyped2));
199 CHECK (Seq{
"x"} == contents (untyped2.keys()));
200 CHECK (Seq{
"y"} == contents (untyped2.vals()));
201 CHECK (Seq{
"z"} == contents (untyped2.scope()));
204 RecS something({
"a=1",
"type=thing",
"b=2",
"c",
"d"});
205 CHECK (!isnil(something));
206 CHECK (
"thing" == something.getType());
207 CHECK (Seq({
"a=1",
"b=2",
"c",
"d"}) == contents(something));
208 CHECK (Seq({
"a",
"b"}) == contents (something.keys()));
209 CHECK (Seq({
"1",
"2"}) == contents (something.vals()));
210 CHECK (Seq({
"c",
"d"}) == contents (something.scope()));
217 RecS a({
"a=1",
"b=2",
"c",
"d"});
219 CHECK (a.getType() == b.getType());
220 CHECK (contents(a) == contents(b));
221 CHECK (contents(a.attribs()) == contents(b.attribs()));
223 CHECK (!isSameObject (a.get(
"a"), b.get(
"a")));
224 CHECK (!isSameObject (*a.scope(), *b.scope()));
226 string const& c = *b.scope();
232 CHECK (
"2" == bb.get(
"b"));
233 CHECK (isSameObject(c, *bb.scope()));
236 CHECK (!isSameObject(c, *bb.scope()));
237 CHECK ( isSameObject(c, *a.scope()));
242 CHECK (!isSameObject(b.get(
"a"), bb.get(
"a")));
243 CHECK (!isSameObject(*b.scope(), *bb.scope()));
253 RecS ax({
"type=a",
"a"});
254 RecS ay({
"a=a",
"a"});
255 RecS az({
"a =a",
"a"});
257 CHECK (a != aa); CHECK (aa != a);
258 CHECK (aa != aaa); CHECK (aaa != aa);
259 CHECK (a != aaa); CHECK (aaa != a);
260 CHECK (a != ax); CHECK (ax != a);
261 CHECK (a != ay); CHECK (ay != a);
262 CHECK (ax != ay); CHECK (ay != ax);
263 CHECK (aaa != ay); CHECK (ay != aaa);
264 CHECK (ay != az); CHECK (az != ay);
268 CHECK (aa == a2); CHECK (a2 == aa);
270 RecS o1(
"oo", strings({
"a=α",
"b=β"}), strings({
"γ",
"δ",
"ε"}));
271 RecS o2({
"type=oo",
"a=α",
"b=β",
"γ",
"δ",
"ε"});
272 RecS o3({
"type=oO",
"a=α",
"b=β",
"γ",
"δ",
"ε"});
273 RecS o4({
"type=oo",
"a=α",
"b=β",
"c=γ",
"δ",
"ε"});
274 RecS o5({
"type=oo",
"a=α",
"b=β",
"γ",
"ε",
"δ"});
275 RecS o6({
"type=oo",
"a=α",
"b=β",
"γ",
"δ"});
277 CHECK (o1 == o2); CHECK (o2 == o1);
278 CHECK (o2 != o3); CHECK (o3 != o2);
279 CHECK (o3 != o4); CHECK (o4 != o3);
280 CHECK (o4 != o5); CHECK (o5 != o4);
281 CHECK (o5 != o6); CHECK (o6 != o5);
282 CHECK (o1 != o3); CHECK (o3 != o1);
283 CHECK (o1 != o4); CHECK (o4 != o1);
284 CHECK (o1 != o5); CHECK (o5 != o1);
285 CHECK (o1 != o6); CHECK (o6 != o1);
286 CHECK (o2 != o4); CHECK (o4 != o2);
287 CHECK (o2 != o5); CHECK (o5 != o2);
288 CHECK (o2 != o6); CHECK (o6 != o2);
289 CHECK (o3 != o5); CHECK (o5 != o3);
290 CHECK (o3 != o6); CHECK (o6 != o3);
291 CHECK (o4 != o6); CHECK (o6 != o4);
293 RecS o7({
"type=oo",
"b = β",
"a = α",
"γ",
"δ",
"ε"});
294 CHECK (o2 != o7); CHECK (o7 != o2);
305 CHECK (
"NIL" == a.getType());
307 RecS::Mutator mut(a);
309 mut.appendChild(
"a");
314 CHECK (
"u" == aa.getType());
315 CHECK (Seq({
"a = 1",
"a"}) == contents(aa));
316 CHECK (Seq({
"a"}) == contents (aa.keys()));
317 CHECK (Seq({
"1"}) == contents (aa.vals()));
318 CHECK (Seq({
"a"}) == contents (aa.scope()));
322 mut.prependChild(
"⟂");
330 CHECK (Seq({
"a = α",
"b = β",
"⟂",
"a"}) == contents(a));
331 CHECK (Seq({
"a = 1",
"a"}) == contents(aa));
338 RecS oo({
"type = 🌰",
"☿ = mercury",
"♀ = venus",
"♁ = earth",
"♂ = mars",
"♃ = jupiter",
"♄ = saturn"});
341 CHECK (
bool(empty) ==
false);
342 CHECK (
nullptr == empty.get());
347 CHECK (ref.get() == &oo);
350 CHECK (
"🌰" == oor.getType());
351 CHECK (oor.get(
"♄") ==
"saturn");
356 CHECK (r2.get() == ref.get());
357 CHECK (!isSameObject (r2, ref));
360 empty = std::move(r2);
363 CHECK (
nullptr == r2.get());
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
iterator begin() const
default iteration exposes all data within this "object", starting with the attributes ...
Implementation namespace for support and library code.
Special collection to represent object-like data.
Simplistic test class runner.
wrapped record reference.
A collection of frequently used helper functions to support unit testing.
object-like record of data.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities. ...