51 using LERR_(INDEX_BOUNDS);
52 using LERR_(BOTTOM_VALUE);
56 using Seq = vector<string>;
61 contents (IT
const& it)
64 append_all (it, collected);
69 contents (
RecS const& rec_of_strings)
71 return contents (rec_of_strings.
begin());
76 strings (std::initializer_list<X>
const& con)
80 collected.push_back(elm);
145 RecS enterprise(
"starship" 146 , strings ({
"Name = USS Enterprise" 147 ,
"Registry = NCC-1701-D" 149 ,
"Owner = United Federation of Planets" 150 ,
"Operator= Starfleet" 153 , strings ({
"Picard",
"Riker",
"Data",
"Troi",
"Worf",
"Crusher",
"La Forge"})
156 CHECK (enterprise.getType() ==
"starship");
157 CHECK (enterprise.get(
"Registry") ==
"NCC-1701-D");
158 CHECK (enterprise.child(0) ==
"Picard");
159 CHECK (enterprise.child(2) ==
"Data");
161 CHECK (enterprise.hasAttribute(
"Owner"));
162 CHECK (!enterprise.hasAttribute(
"owner"));
163 CHECK (!enterprise.hasAttribute(
"Owner "));
165 CHECK (enterprise.contains(
"Data"));
166 CHECK (!enterprise.contains(
"Woof"));
167 CHECK (util::contains (enterprise,
"Worf"));
172 cout <<
"enterprise = " 173 << enterprise <<endl;
174 for (
string elm : enterprise)
176 cout <<
"--Attributes--"<<endl;
177 for (
string att : enterprise.attribs())
179 cout <<
"--Keys--->" << join (enterprise.keys(),
"<->")<<endl;
180 cout <<
"--Vals--->" << join (enterprise.vals(),
"<->")<<endl;
181 cout <<
"--Crew--->" << join (enterprise.scope(),
" | ")<<endl;
190 CHECK (
"NIL" == nil.getType());
191 CHECK (RecS::TYPE_NIL == nil.getType());
193 CHECK (!nil.begin());
194 CHECK (nil.begin() == nil.end());
198 CHECK (!isnil(untyped));
199 CHECK (
"NIL" == untyped.getType());
200 CHECK (Seq{
"x"} == contents(untyped));
201 CHECK (Seq{
"x"} == contents(untyped.scope()));
202 CHECK (isnil (untyped.attribs()));
204 RecS untyped2({
"x=y",
"z"});
205 CHECK (!isnil(untyped2));
206 CHECK (
"NIL" == untyped2.getType());
207 CHECK (Seq({
"x=y",
"z"}) == contents(untyped2));
208 CHECK (Seq{
"x"} == contents (untyped2.keys()));
209 CHECK (Seq{
"y"} == contents (untyped2.vals()));
210 CHECK (Seq{
"z"} == contents (untyped2.scope()));
213 RecS something({
"a=1",
"type=thing",
"b=2",
"c",
"d"});
214 CHECK (!isnil(something));
215 CHECK (
"thing" == something.getType());
216 CHECK (Seq({
"a=1",
"b=2",
"c",
"d"}) == contents(something));
217 CHECK (Seq({
"a",
"b"}) == contents (something.keys()));
218 CHECK (Seq({
"1",
"2"}) == contents (something.vals()));
219 CHECK (Seq({
"c",
"d"}) == contents (something.scope()));
226 RecS a({
"a=1",
"b=2",
"c",
"d"});
228 CHECK (a.getType() == b.getType());
229 CHECK (contents(a) == contents(b));
230 CHECK (contents(a.attribs()) == contents(b.attribs()));
232 CHECK (!isSameObject (a.get(
"a"), b.get(
"a")));
233 CHECK (!isSameObject (*a.scope(), *b.scope()));
235 string const& c = *b.scope();
241 CHECK (
"2" == bb.get(
"b"));
242 CHECK (isSameObject(c, *bb.scope()));
245 CHECK (!isSameObject(c, *bb.scope()));
246 CHECK ( isSameObject(c, *a.scope()));
251 CHECK (!isSameObject(b.get(
"a"), bb.get(
"a")));
252 CHECK (!isSameObject(*b.scope(), *bb.scope()));
262 RecS ax({
"type=a",
"a"});
263 RecS ay({
"a=a",
"a"});
264 RecS az({
"a =a",
"a"});
266 CHECK (a != aa); CHECK (aa != a);
267 CHECK (aa != aaa); CHECK (aaa != aa);
268 CHECK (a != aaa); CHECK (aaa != a);
269 CHECK (a != ax); CHECK (ax != a);
270 CHECK (a != ay); CHECK (ay != a);
271 CHECK (ax != ay); CHECK (ay != ax);
272 CHECK (aaa != ay); CHECK (ay != aaa);
273 CHECK (ay != az); CHECK (az != ay);
277 CHECK (aa == a2); CHECK (a2 == aa);
279 RecS o1(
"oo", strings({
"a=α",
"b=β"}), strings({
"γ",
"δ",
"ε"}));
280 RecS o2({
"type=oo",
"a=α",
"b=β",
"γ",
"δ",
"ε"});
281 RecS o3({
"type=oO",
"a=α",
"b=β",
"γ",
"δ",
"ε"});
282 RecS o4({
"type=oo",
"a=α",
"b=β",
"c=γ",
"δ",
"ε"});
283 RecS o5({
"type=oo",
"a=α",
"b=β",
"γ",
"ε",
"δ"});
284 RecS o6({
"type=oo",
"a=α",
"b=β",
"γ",
"δ"});
286 CHECK (o1 == o2); CHECK (o2 == o1);
287 CHECK (o2 != o3); CHECK (o3 != o2);
288 CHECK (o3 != o4); CHECK (o4 != o3);
289 CHECK (o4 != o5); CHECK (o5 != o4);
290 CHECK (o5 != o6); CHECK (o6 != o5);
291 CHECK (o1 != o3); CHECK (o3 != o1);
292 CHECK (o1 != o4); CHECK (o4 != o1);
293 CHECK (o1 != o5); CHECK (o5 != o1);
294 CHECK (o1 != o6); CHECK (o6 != o1);
295 CHECK (o2 != o4); CHECK (o4 != o2);
296 CHECK (o2 != o5); CHECK (o5 != o2);
297 CHECK (o2 != o6); CHECK (o6 != o2);
298 CHECK (o3 != o5); CHECK (o5 != o3);
299 CHECK (o3 != o6); CHECK (o6 != o3);
300 CHECK (o4 != o6); CHECK (o6 != o4);
302 RecS o7({
"type=oo",
"b = β",
"a = α",
"γ",
"δ",
"ε"});
303 CHECK (o2 != o7); CHECK (o7 != o2);
314 CHECK (
"NIL" == a.getType());
316 RecS::Mutator mut(a);
318 mut.appendChild(
"a");
323 CHECK (
"u" == aa.getType());
324 CHECK (Seq({
"a = 1",
"a"}) == contents(aa));
325 CHECK (Seq({
"a"}) == contents (aa.keys()));
326 CHECK (Seq({
"1"}) == contents (aa.vals()));
327 CHECK (Seq({
"a"}) == contents (aa.scope()));
331 mut.prependChild(
"⟂");
339 CHECK (Seq({
"a = α",
"b = β",
"⟂",
"a"}) == contents(a));
340 CHECK (Seq({
"a = 1",
"a"}) == contents(aa));
347 RecS oo({
"type = 🌰",
"☿ = mercury",
"♀ = venus",
"♁ = earth",
"♂ = mars",
"♃ = jupiter",
"♄ = saturn"});
350 CHECK (
bool(empty) ==
false);
351 CHECK (
nullptr == empty.get());
356 CHECK (ref.get() == &oo);
359 CHECK (
"🌰" == oor.getType());
360 CHECK (oor.get(
"♄") ==
"saturn");
365 CHECK (r2.get() == ref.get());
366 CHECK (!isSameObject (r2, ref));
369 empty = std::move(r2);
372 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.
Simple 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, bypassing any custom comparison operators.