spectests.cpp 31.3 KB
Newer Older
1
#include "spectests.h"
2
3
4
5
#include "specexamples.h"
#include "yaml-cpp/yaml.h"

#define YAML_ASSERT(cond) do { if(!(cond)) return "  Assert failed: " #cond; } while(false)
6

7
8
9
namespace Test
{
	namespace Spec
10
	{
11
		// 2.1
12
13
14
15
16
17
18
19
20
		TEST SeqScalars() {
			YAML::Node doc = YAML::Parse(ex2_1);
			YAML_ASSERT(doc.Type() == YAML::NodeType::Sequence);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].as<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc[1].as<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc[2].as<std::string>() == "Ken Griffey");
			return true;
		}
21
22
		
		// 2.2
23
24
25
26
27
28
29
30
31
		TEST MappingScalarsToScalars() {
			YAML::Node doc = YAML::Parse(ex2_2);
			YAML_ASSERT(doc.Type() == YAML::NodeType::Map);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["hr"].as<std::string>() == "65");
			YAML_ASSERT(doc["avg"].as<std::string>() == "0.278");
			YAML_ASSERT(doc["rbi"].as<std::string>() == "147");
			return true;
		}
32
33
		
		// 2.3
34
35
36
37
38
39
40
41
42
43
44
45
46
47
		TEST MappingScalarsToSequences() {
			YAML::Node doc = YAML::Parse(ex2_3);
			YAML_ASSERT(doc.Type() == YAML::NodeType::Map);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["american"].size() == 3);
			YAML_ASSERT(doc["american"][0].as<std::string>() == "Boston Red Sox");
			YAML_ASSERT(doc["american"][1].as<std::string>() == "Detroit Tigers");
			YAML_ASSERT(doc["american"][2].as<std::string>() == "New York Yankees");
			YAML_ASSERT(doc["national"].size() == 3);
			YAML_ASSERT(doc["national"][0].as<std::string>() == "New York Mets");
			YAML_ASSERT(doc["national"][1].as<std::string>() == "Chicago Cubs");
			YAML_ASSERT(doc["national"][2].as<std::string>() == "Atlanta Braves");
			return true;
		}
48
49
		
		// 2.4
50
51
52
53
54
55
56
57
58
59
60
61
62
		TEST SequenceOfMappings() {
			YAML::Node doc = YAML::Parse(ex2_4);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 3);
			YAML_ASSERT(doc[0]["name"].as<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc[0]["hr"].as<std::string>() == "65");
			YAML_ASSERT(doc[0]["avg"].as<std::string>() == "0.278");
			YAML_ASSERT(doc[1].size() == 3);
			YAML_ASSERT(doc[1]["name"].as<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc[1]["hr"].as<std::string>() == "63");
			YAML_ASSERT(doc[1]["avg"].as<std::string>() == "0.288");
			return true;
		}
63
64
		
		// 2.5
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
		TEST SequenceOfSequences() {
			YAML::Node doc = YAML::Parse(ex2_5);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].size() == 3);
			YAML_ASSERT(doc[0][0].as<std::string>() == "name");
			YAML_ASSERT(doc[0][1].as<std::string>() == "hr");
			YAML_ASSERT(doc[0][2].as<std::string>() == "avg");
			YAML_ASSERT(doc[1].size() == 3);
			YAML_ASSERT(doc[1][0].as<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc[1][1].as<std::string>() == "65");
			YAML_ASSERT(doc[1][2].as<std::string>() == "0.278");
			YAML_ASSERT(doc[2].size() == 3);
			YAML_ASSERT(doc[2][0].as<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc[2][1].as<std::string>() == "63");
			YAML_ASSERT(doc[2][2].as<std::string>() == "0.288");
			return true;
		}
82
83
		
		// 2.6
84
85
86
87
88
89
90
91
92
93
94
		TEST MappingOfMappings() {
			YAML::Node doc = YAML::Parse(ex2_6);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["Mark McGwire"].size() == 2);
			YAML_ASSERT(doc["Mark McGwire"]["hr"].as<std::string>() == "65");
			YAML_ASSERT(doc["Mark McGwire"]["avg"].as<std::string>() == "0.278");
			YAML_ASSERT(doc["Sammy Sosa"].size() == 2);
			YAML_ASSERT(doc["Sammy Sosa"]["hr"].as<std::string>() == "63");
			YAML_ASSERT(doc["Sammy Sosa"]["avg"].as<std::string>() == "0.288");
			return true;
		}
95
96
		
		// 2.7
97
98
99
		TEST TwoDocumentsInAStream() {
			return "  not written yet"; 
		}
100
101
		
		// 2.8
102
103
104
		TEST PlayByPlayFeed() {
			return "  not written yet";
		}
105
106
		
		// 2.9
107
108
109
110
111
112
113
114
115
116
117
		TEST SingleDocumentWithTwoComments() {
			YAML::Node doc = YAML::Parse(ex2_9);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["hr"].size() == 2);
			YAML_ASSERT(doc["hr"][0].as<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc["hr"][1].as<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["rbi"].size() == 2);
			YAML_ASSERT(doc["rbi"][0].as<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["rbi"][1].as<std::string>() == "Ken Griffey");
			return true;
		}
118
119
		
		// 2.10
120
121
122
123
124
125
126
127
128
129
130
		TEST SimpleAnchor() {
			YAML::Node doc = YAML::Parse(ex2_10);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["hr"].size() == 2);
			YAML_ASSERT(doc["hr"][0].as<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc["hr"][1].as<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["rbi"].size() == 2);
			YAML_ASSERT(doc["rbi"][0].as<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["rbi"][1].as<std::string>() == "Ken Griffey");
			return true;
		}
131
132
		
		// 2.11
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
		TEST MappingBetweenSequences() {
			YAML::Node doc = YAML::Parse(ex2_11);

			std::vector<std::string> tigers_cubs;
			tigers_cubs.push_back("Detroit Tigers");
			tigers_cubs.push_back("Chicago cubs");
			
			std::vector<std::string> yankees_braves;
			yankees_braves.push_back("New York Yankees");
			yankees_braves.push_back("Atlanta Braves");
			
			
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[tigers_cubs].size() == 1);
			YAML_ASSERT(doc[tigers_cubs][0].as<std::string>() == "2001-07-23");
			YAML_ASSERT(doc[yankees_braves].size() == 3);
			YAML_ASSERT(doc[yankees_braves][0].as<std::string>() == "2001-07-02");
			YAML_ASSERT(doc[yankees_braves][1].as<std::string>() == "2001-08-12");
			YAML_ASSERT(doc[yankees_braves][2].as<std::string>() == "2001-08-14");
			return true;
		}
154
155
		
		// 2.12
156
157
158
159
160
161
162
163
164
165
166
167
168
169
		TEST CompactNestedMapping() {
			YAML::Node doc = YAML::Parse(ex2_12);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0]["item"].as<std::string>() == "Super Hoop");
			YAML_ASSERT(doc[0]["quantity"].as<int>() == 1);
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1]["item"].as<std::string>() == "Basketball");
			YAML_ASSERT(doc[1]["quantity"].as<int>() == 4);
			YAML_ASSERT(doc[2].size() == 2);
			YAML_ASSERT(doc[2]["item"].as<std::string>() == "Big Shoes");
			YAML_ASSERT(doc[2]["quantity"].as<int>() == 1);
			return true;
		}
170
171
		
		// 2.13
172
173
174
175
176
177
178
		TEST InLiteralsNewlinesArePreserved() {
			YAML::Node doc = YAML::Parse(ex2_13);
			YAML_ASSERT(doc.as<std::string>() ==
						"\\//||\\/||\n"
						"// ||  ||__");
			return true;
		}
179
180
		
		// 2.14
181
182
183
184
185
		TEST InFoldedScalarsNewlinesBecomeSpaces() {
			YAML::Node doc = YAML::Parse(ex2_14);
			YAML_ASSERT(doc.as<std::string>() == "Mark McGwire's year was crippled by a knee injury.");
			return true;
		}
186
187
		
		// 2.15
188
189
190
191
192
193
194
195
196
		TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines() {
			YAML::Node doc = YAML::Parse(ex2_15);
			YAML_ASSERT(doc.as<std::string>() ==
						"Sammy Sosa completed another fine season with great stats.\n\n"
						"  63 Home Runs\n"
						"  0.288 Batting Average\n\n"
						"What a year!");
			return true;
		}
197
198
		
		// 2.16
199
200
201
202
203
204
205
206
		TEST IndentationDeterminesScope() {
			YAML::Node doc = YAML::Parse(ex2_16);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["name"].as<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc["accomplishment"].as<std::string>() == "Mark set a major league home run record in 1998.\n");
			YAML_ASSERT(doc["stats"].as<std::string>() == "65 Home Runs\n0.278 Batting Average\n");
			return true;
		}
207
208
		
		// 2.17
209
210
211
212
213
214
215
216
217
218
219
		TEST QuotedScalars() {
			YAML::Node doc = YAML::Parse(ex2_17);
			YAML_ASSERT(doc.size() == 6);
			YAML_ASSERT(doc["unicode"].as<std::string>() == "Sosa did fine.\xe2\x98\xba");
			YAML_ASSERT(doc["control"].as<std::string>() == "\b1998\t1999\t2000\n");
			YAML_ASSERT(doc["hex esc"].as<std::string>() == "\x0d\x0a is \r\n");
			YAML_ASSERT(doc["single"].as<std::string>() == "\"Howdy!\" he cried.");
			YAML_ASSERT(doc["quoted"].as<std::string>() == " # Not a 'comment'.");
			YAML_ASSERT(doc["tie-fighter"].as<std::string>() == "|\\-*-/|");
			return true;
		}
220
221
		
		// 2.18
222
223
224
225
226
227
228
		TEST MultiLineFlowScalars() {
			YAML::Node doc = YAML::Parse(ex2_18);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["plain"].as<std::string>() == "This unquoted scalar spans many lines.");
			YAML_ASSERT(doc["quoted"].as<std::string>() == "So does this quoted scalar.\n");
			return true;
		}
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
		
		// TODO: 2.19 - 2.22 schema tags
		
		// 2.23
		TEST VariousExplicitTags() { return "  not written yet"; }
		
		// 2.24
		TEST GlobalTags() { return "  not written yet"; }
		
		// 2.25
		TEST UnorderedSets() { return "  not written yet"; }
		
		// 2.26
		TEST OrderedMappings() { return "  not written yet"; }
		
		// 2.27
		TEST Invoice() { return "  not written yet"; }
		
		// 2.28
		TEST LogFile() { return "  not written yet"; }
		
		// TODO: 5.1 - 5.2 BOM
		
		// 5.3
Jesse Beder's avatar
Jesse Beder committed
253
254
255
256
257
258
259
260
261
262
263
		TEST BlockStructureIndicators() {
			YAML::Node doc = YAML::Parse(ex5_3);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["sequence"].size() == 2);
			YAML_ASSERT(doc["sequence"][0].as<std::string>() == "one");
			YAML_ASSERT(doc["sequence"][1].as<std::string>() == "two");
			YAML_ASSERT(doc["mapping"].size() == 2);
			YAML_ASSERT(doc["mapping"]["sky"].as<std::string>() == "blue");
			YAML_ASSERT(doc["mapping"]["sea"].as<std::string>() == "green");
			return true;
		}
264
265
		
		// 5.4
Jesse Beder's avatar
Jesse Beder committed
266
267
268
269
270
271
272
273
274
275
276
		TEST FlowStructureIndicators() {
			YAML::Node doc = YAML::Parse(ex5_4);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["sequence"].size() == 2);
			YAML_ASSERT(doc["sequence"][0].as<std::string>() == "one");
			YAML_ASSERT(doc["sequence"][1].as<std::string>() == "two");
			YAML_ASSERT(doc["mapping"].size() == 2);
			YAML_ASSERT(doc["mapping"]["sky"].as<std::string>() == "blue");
			YAML_ASSERT(doc["mapping"]["sea"].as<std::string>() == "green");
			return true;
		}
277
278
		
		// 5.5
Jesse Beder's avatar
Jesse Beder committed
279
280
281
282
283
		TEST CommentIndicator() {
			YAML::Node doc = YAML::Parse(ex5_5);
			YAML_ASSERT(doc.Type() == YAML::NodeType::Null);
			return true;
		}
284
285
		
		// 5.6
Jesse Beder's avatar
Jesse Beder committed
286
287
288
289
290
291
292
		TEST NodePropertyIndicators() {
			YAML::Node doc = YAML::Parse(ex5_6);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["anchored"].as<std::string>() == "value"); // TODO: assert tag
			YAML_ASSERT(doc["alias"].as<std::string>() == "value");
			return true;
		}
293
294
		
		// 5.7
Jesse Beder's avatar
Jesse Beder committed
295
296
297
298
299
300
301
		TEST BlockScalarIndicators() {
			YAML::Node doc = YAML::Parse(ex5_7);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["literal"].as<std::string>() == "some\ntext\n");
			YAML_ASSERT(doc["folded"].as<std::string>() == "some text\n");
			return true;
		}
302
303
		
		// 5.8
Jesse Beder's avatar
Jesse Beder committed
304
305
306
307
308
309
310
		TEST QuotedScalarIndicators() {
			YAML::Node doc = YAML::Parse(ex5_8);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["single"].as<std::string>() == "text");
			YAML_ASSERT(doc["double"].as<std::string>() == "text");
			return true;
		}
311
312
313
314
315
		
		// TODO: 5.9 directive
		// TODO: 5.10 reserved indicator
		
		// 5.11
Jesse Beder's avatar
Jesse Beder committed
316
317
318
319
320
		TEST LineBreakCharacters() {
			YAML::Node doc = YAML::Parse(ex5_11);
			YAML_ASSERT(doc.as<std::string>() == "Line break (no glyph)\nLine break (glyphed)\n");
			return true;
		}
321
322
		
		// 5.12
Jesse Beder's avatar
Jesse Beder committed
323
324
325
326
327
328
329
330
331
332
		TEST TabsAndSpaces() {
			YAML::Node doc = YAML::Parse(ex5_12);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["quoted"].as<std::string>() == "Quoted\t");
			YAML_ASSERT(doc["block"].as<std::string>() ==
						"void main() {\n"
						"\tprintf(\"Hello, world!\\n\");\n"
						"}");
			return true;
		}
333
334
		
		// 5.13
Jesse Beder's avatar
Jesse Beder committed
335
336
337
338
339
		TEST EscapedCharacters() {
			YAML::Node doc = YAML::Parse(ex5_13);
			YAML_ASSERT(doc.as<std::string>() == "Fun with \x5C \x22 \x07 \x08 \x1B \x0C \x0A \x0D \x09 \x0B " + std::string("\x00", 1) + " \x20 \xA0 \x85 \xe2\x80\xa8 \xe2\x80\xa9 A A A");
			return true;
		}
340
341
		
		// 5.14
Jesse Beder's avatar
Jesse Beder committed
342
343
344
345
346
347
348
349
350
351
		TEST InvalidEscapedCharacters() {
			try {
				YAML::Parse(ex5_14);
			} catch(const YAML::ParserException& e) {
				YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::INVALID_ESCAPE) + "c");
				return true;
			}
			
			return false;
		}
352
353
		
		// 6.1
354
355
356
357
358
359
360
361
362
363
364
		TEST IndentationSpaces() {
			YAML::Node doc = YAML::Parse(ex6_1);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["Not indented"].size() == 2);
			YAML_ASSERT(doc["Not indented"]["By one space"].as<std::string>() == "By four\n  spaces\n");
			YAML_ASSERT(doc["Not indented"]["Flow style"].size() == 3);
			YAML_ASSERT(doc["Not indented"]["Flow style"][0].as<std::string>() == "By two");
			YAML_ASSERT(doc["Not indented"]["Flow style"][1].as<std::string>() == "Also by two");
			YAML_ASSERT(doc["Not indented"]["Flow style"][2].as<std::string>() == "Still by two");
			return true;
		}
365
366
		
		// 6.2
367
368
369
370
371
372
373
374
375
376
		TEST IndentationIndicators() {
			YAML::Node doc = YAML::Parse(ex6_2);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["a"].size() == 2);
			YAML_ASSERT(doc["a"][0].as<std::string>() == "b");
			YAML_ASSERT(doc["a"][1].size() == 2);
			YAML_ASSERT(doc["a"][1][0].as<std::string>() == "c");
			YAML_ASSERT(doc["a"][1][1].as<std::string>() == "d");
			return true;
		}
377
378
		
		// 6.3
379
380
381
382
383
384
385
386
387
388
		TEST SeparationSpaces() {
			YAML::Node doc = YAML::Parse(ex6_3);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["foo"].as<std::string>() == "bar");
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1][0].as<std::string>() == "baz");
			YAML_ASSERT(doc[1][1].as<std::string>() == "baz");
			return true;
		}
389
390
		
		// 6.4
391
392
393
394
395
396
397
398
		TEST LinePrefixes() {
			YAML::Node doc = YAML::Parse(ex6_4);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["plain"].as<std::string>() == "text lines");
			YAML_ASSERT(doc["quoted"].as<std::string>() == "text lines");
			YAML_ASSERT(doc["block"].as<std::string>() == "text\n \tlines\n");
			return true;
		}
399
400
		
		// 6.5
401
402
403
404
405
406
407
		TEST EmptyLines() {
			YAML::Node doc = YAML::Parse(ex6_5);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["Folding"].as<std::string>() == "Empty line\nas a line feed");
			YAML_ASSERT(doc["Chomping"].as<std::string>() == "Clipped empty lines\n");
			return true;
		}
408
409
		
		// 6.6
410
411
412
413
414
		TEST LineFolding() {
			YAML::Node doc = YAML::Parse(ex6_6);
			YAML_ASSERT(doc.as<std::string>() == "trimmed\n\n\nas space");
			return true;
		}
415
416
		
		// 6.7
417
418
419
420
421
		TEST BlockFolding() {
			YAML::Node doc = YAML::Parse(ex6_7);
			YAML_ASSERT(doc.as<std::string>() == "foo \n\n\t bar\n\nbaz\n");
			return true;
		}
422
423
		
		// 6.8
424
425
426
427
428
		TEST FlowFolding() {
			YAML::Node doc = YAML::Parse(ex6_8);
			YAML_ASSERT(doc.as<std::string>() == " foo\nbar\nbaz ");
			return true;
		}
429
430
		
		// 6.9
431
432
433
434
435
436
		TEST SeparatedComment() {
			YAML::Node doc = YAML::Parse(ex6_9);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["key"].as<std::string>() == "value");
			return true;
		}
437
438
		
		// 6.10
439
440
441
442
443
		TEST CommentLines() {
			YAML::Node doc = YAML::Parse(ex6_10);
			YAML_ASSERT(doc.Type() == YAML::NodeType::Null);
			return true;
		}
444
445
		
		// 6.11
446
447
448
449
450
451
		TEST MultiLineComments() {
			YAML::Node doc = YAML::Parse(ex6_11);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["key"].as<std::string>() == "value");
			return true;
		}
452
453
		
		// 6.12
454
455
456
457
458
459
460
461
462
463
464
465
466
		TEST SeparationSpacesII() {
			YAML::Node doc = YAML::Parse(ex6_12);
			
			std::map<std::string, std::string> sammy;
			sammy["first"] = "Sammy";
			sammy["last"] = "Sosa";
			
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc[sammy].size() == 2);
			YAML_ASSERT(doc[sammy]["hr"].as<int>() == 65);
			YAML_ASSERT(doc[sammy]["avg"].as<std::string>() == "0.278");
			return true;
		}
467
468
		
		// 6.13
469
470
471
472
473
		TEST ReservedDirectives() {
			YAML::Node doc = YAML::Parse(ex6_13);
			YAML_ASSERT(doc.as<std::string>() == "foo");
			return true;
		}
474
475
		
		// 6.14
476
477
478
479
480
		TEST YAMLDirective() {
			YAML::Node doc = YAML::Parse(ex6_14);
			YAML_ASSERT(doc.as<std::string>() == "foo");
			return true;
		}
481
482
		
		// 6.15
483
484
485
486
487
488
489
490
491
492
		TEST InvalidRepeatedYAMLDirective() {
			try {
				YAML::Parse(ex6_15);
			} catch(const YAML::ParserException& e) {
				YAML_ASSERT(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE);
				return true;
			}
			
			return "  No exception was thrown";
		}
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
		
		// 6.16
		TEST TagDirective() { return "  not written yet"; }
		
		// 6.17
		TEST InvalidRepeatedTagDirective() { return "  not written yet"; }
		
		// 6.18
		TEST PrimaryTagHandle() { return "  not written yet"; }
		
		// 6.19
		TEST SecondaryTagHandle() { return "  not written yet"; }
		
		// 6.20
		TEST TagHandles() { return "  not written yet"; }
		
		// 6.21
		TEST LocalTagPrefix() { return "  not written yet"; }
		
		// 6.22
		TEST GlobalTagPrefix() { return "  not written yet"; }
		
		// 6.23
		TEST NodeProperties() { return "  not written yet"; }
		
		// 6.24
		TEST VerbatimTags() { return "  not written yet"; }
		
		// 6.25
		TEST InvalidVerbatimTags() { return "  not written yet"; }
		
		// 6.26
		TEST TagShorthands() { return "  not written yet"; }
		
		// 6.27
		TEST InvalidTagShorthands() { return "  not written yet"; }
		
		// 6.28
		TEST NonSpecificTags() { return "  not written yet"; }
		
		// 6.29
534
535
536
537
538
539
540
		TEST NodeAnchors() {
			YAML::Node doc = YAML::Parse(ex6_29);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["First occurrence"].as<std::string>() == "Value");
			YAML_ASSERT(doc["Second occurrence"].as<std::string>() == "Value");
			return true;
		}
541
542
		
		// 7.1
543
544
545
546
547
548
549
550
551
		TEST AliasNodes() {
			YAML::Node doc = YAML::Parse(ex7_1);
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc["First occurrence"].as<std::string>() == "Foo");
			YAML_ASSERT(doc["Second occurrence"].as<std::string>() == "Foo");
			YAML_ASSERT(doc["Override anchor"].as<std::string>() == "Bar");
			YAML_ASSERT(doc["Reuse anchor"].as<std::string>() == "Bar");
			return true;
		}
552
553
554
555
556
		
		// 7.2
		TEST EmptyNodes() { return "  not written yet"; }
		
		// 7.3
557
558
559
560
		TEST CompletelyEmptyNodes() {
			YAML::Node doc = YAML::Parse(ex7_3);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["foo"].Type() == YAML::NodeType::Null);
561
			YAML_ASSERT(doc[YAML::Null].as<std::string>() == "bar");
562
563
			return true;
		}
564
565
		
		// 7.4
566
567
568
569
570
571
572
573
		TEST DoubleQuotedImplicitKeys() {
			YAML::Node doc = YAML::Parse(ex7_4);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["implicit block key"].size() == 1);
			YAML_ASSERT(doc["implicit block key"][0].size() == 1);
			YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as<std::string>() == "value");
			return true;
		}
574
575
		
		// 7.5
576
577
578
579
580
		TEST DoubleQuotedLineBreaks() {
			YAML::Node doc = YAML::Parse(ex7_5);
			YAML_ASSERT(doc.as<std::string>() == "folded to a space,\nto a line feed, or \t \tnon-content");
			return true;
		}
581
582
		
		// 7.6
583
584
585
586
587
		TEST DoubleQuotedLines() {
			YAML::Node doc = YAML::Parse(ex7_6);
			YAML_ASSERT(doc.as<std::string>() == " 1st non-empty\n2nd non-empty 3rd non-empty ");
			return true;
		}
588
589
		
		// 7.7
590
591
592
593
594
		TEST SingleQuotedCharacters() {
			YAML::Node doc = YAML::Parse(ex7_7);
			YAML_ASSERT(doc.as<std::string>() == "here's to \"quotes\"");
			return true;
		}
595
596
		
		// 7.8
597
598
599
600
601
602
603
604
		TEST SingleQuotedImplicitKeys() {
			YAML::Node doc = YAML::Parse(ex7_8);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["implicit block key"].size() == 1);
			YAML_ASSERT(doc["implicit block key"][0].size() == 1);
			YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as<std::string>() == "value");
			return true;
		}
605
606
		
		// 7.9
607
608
609
610
611
		TEST SingleQuotedLines() {
			YAML::Node doc = YAML::Parse(ex7_9);
			YAML_ASSERT(doc.as<std::string>() == " 1st non-empty\n2nd non-empty 3rd non-empty ");
			return true;
		}
612
613
		
		// 7.10
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
		TEST PlainCharacters() {
			YAML::Node doc = YAML::Parse(ex7_10);
			YAML_ASSERT(doc.size() == 6);
			YAML_ASSERT(doc[0].as<std::string>() == "::vector");
			YAML_ASSERT(doc[1].as<std::string>() == ": - ()");
			YAML_ASSERT(doc[2].as<std::string>() == "Up, up, and away!");
			YAML_ASSERT(doc[3].as<int>() == -123);
			YAML_ASSERT(doc[4].as<std::string>() == "http://example.com/foo#bar");
			YAML_ASSERT(doc[5].size() == 5);
			YAML_ASSERT(doc[5][0].as<std::string>() == "::vector");
			YAML_ASSERT(doc[5][1].as<std::string>() == ": - ()");
			YAML_ASSERT(doc[5][2].as<std::string>() == "Up, up, and away!");
			YAML_ASSERT(doc[5][3].as<int>() == -123);
			YAML_ASSERT(doc[5][4].as<std::string>() == "http://example.com/foo#bar");
			return true;
		}
630
631
		
		// 7.11
632
633
634
635
636
637
638
639
		TEST PlainImplicitKeys() {
			YAML::Node doc = YAML::Parse(ex7_11);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["implicit block key"].size() == 1);
			YAML_ASSERT(doc["implicit block key"][0].size() == 1);
			YAML_ASSERT(doc["implicit block key"][0]["implicit flow key"].as<std::string>() == "value");
			return true;
		}
640
641
		
		// 7.12
642
643
644
645
646
		TEST PlainLines() {
			YAML::Node doc = YAML::Parse(ex7_12);
			YAML_ASSERT(doc.as<std::string>() == "1st non-empty\n2nd non-empty 3rd non-empty");
			return true;
		}
647
648
		
		// 7.13
649
650
651
652
653
654
655
656
657
658
659
		TEST FlowSequence() {
			YAML::Node doc = YAML::Parse(ex7_13);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0][0].as<std::string>() == "one");
			YAML_ASSERT(doc[0][1].as<std::string>() == "two");
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1][0].as<std::string>() == "three");
			YAML_ASSERT(doc[1][1].as<std::string>() == "four");
			return true;
		}
660
661
		
		// 7.14
662
663
664
665
666
667
668
669
670
671
672
673
		TEST FlowSequenceEntries() {
			YAML::Node doc = YAML::Parse(ex7_14);
			YAML_ASSERT(doc.size() == 5);
			YAML_ASSERT(doc[0].as<std::string>() == "double quoted");
			YAML_ASSERT(doc[1].as<std::string>() == "single quoted");
			YAML_ASSERT(doc[2].as<std::string>() == "plain text");
			YAML_ASSERT(doc[3].size() == 1);
			YAML_ASSERT(doc[3][0].as<std::string>() == "nested");
			YAML_ASSERT(doc[4].size() == 1);
			YAML_ASSERT(doc[4]["single"].as<std::string>() == "pair");
			return true;
		}
674
675
		
		// 7.15
676
677
678
679
680
681
682
683
684
685
686
		TEST FlowMappings() {
			YAML::Node doc = YAML::Parse(ex7_15);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0]["one"].as<std::string>() == "two");
			YAML_ASSERT(doc[0]["three"].as<std::string>() == "four");
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1]["five"].as<std::string>() == "six");
			YAML_ASSERT(doc[1]["seven"].as<std::string>() == "eight");
			return true;
		}
687
688
		
		// 7.16
689
690
691
692
693
		TEST FlowMappingEntries() {
			YAML::Node doc = YAML::Parse(ex7_16);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["explicit"].as<std::string>() == "entry");
			YAML_ASSERT(doc["implicit"].as<std::string>() == "entry");
694
			YAML_ASSERT(doc[YAML::Null].Type() == YAML::NodeType::Null);
695
696
			return true;
		}
697
698
		
		// 7.17
699
700
701
702
703
704
		TEST FlowMappingSeparateValues() {
			YAML::Node doc = YAML::Parse(ex7_17);
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc["unquoted"].as<std::string>() == "separate");
			YAML_ASSERT(doc["http://foo.com"].Type() == YAML::NodeType::Null);
			YAML_ASSERT(doc["omitted value"].Type() == YAML::NodeType::Null);
705
			YAML_ASSERT(doc[YAML::Null].as<std::string>() == "omitted key");
706
707
			return true;
		}
708
709
		
		// 7.18
710
711
712
713
714
715
716
717
		TEST FlowMappingAdjacentValues() {
			YAML::Node doc = YAML::Parse(ex7_18);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["adjacent"].as<std::string>() == "value");
			YAML_ASSERT(doc["readable"].as<std::string>() == "value");
			YAML_ASSERT(doc["empty"].Type() == YAML::NodeType::Null);
			return true;
		}
718
719
		
		// 7.19
720
721
722
723
724
725
726
		TEST SinglePairFlowMappings() {
			YAML::Node doc = YAML::Parse(ex7_19);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["foo"].as<std::string>() == "bar");
			return true;
		}
727
728
		
		// 7.20
729
730
731
732
733
734
735
		TEST SinglePairExplicitEntry() {
			YAML::Node doc = YAML::Parse(ex7_20);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["foo bar"].as<std::string>() == "baz");
			return true;
		}
736
737
		
		// 7.21
738
739
740
741
742
743
744
745
		TEST SinglePairImplicitEntries() {
			YAML::Node doc = YAML::Parse(ex7_21);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0][0].size() == 1);
			YAML_ASSERT(doc[0][0]["YAML"].as<std::string>() == "separate");
			YAML_ASSERT(doc[1].size() == 1);
			YAML_ASSERT(doc[1][0].size() == 1);
746
			YAML_ASSERT(doc[1][0][YAML::Null].as<std::string>() == "empty key entry");
747
748
749
750
751
752
753
754
			YAML_ASSERT(doc[2].size() == 1);
			YAML_ASSERT(doc[2][0].size() == 1);
			
			std::map<std::string, std::string> key;
			key["JSON"] = "like";
			YAML_ASSERT(doc[2][0][key].as<std::string>() == "adjacent");
			return true;
		}
755
756
		
		// 7.22
757
758
759
760
761
762
763
764
765
766
767
		TEST InvalidImplicitKeys() {
			try {
				YAML::Parse(ex7_22);
			} catch(const YAML::Exception& e) {
				if(e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW)
					return true;
				
				throw;
			}
			return "  no exception thrown";
		}
768
769
		
		// 7.23
770
771
772
773
774
775
776
777
778
779
780
781
782
		TEST FlowContent() {
			YAML::Node doc = YAML::Parse(ex7_23);
			YAML_ASSERT(doc.size() == 5);
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0][0].as<std::string>() == "a");
			YAML_ASSERT(doc[0][1].as<std::string>() == "b");
			YAML_ASSERT(doc[1].size() == 1);
			YAML_ASSERT(doc[1]["a"].as<std::string>() == "b");
			YAML_ASSERT(doc[2].as<std::string>() == "a");
			YAML_ASSERT(doc[3].as<char>() == 'b');
			YAML_ASSERT(doc[4].as<std::string>() == "c");
			return true;
		}
783
784
785
		
		// 7.24
		TEST FlowNodes() { return "  not written yet"; }
786

787
		// 8.1
788
789
790
791
792
793
794
795
796
		TEST BlockScalarHeader() {
			YAML::Node doc = YAML::Parse(ex8_1);
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc[0].as<std::string>() == "literal\n");
			YAML_ASSERT(doc[1].as<std::string>() == " folded\n");
			YAML_ASSERT(doc[2].as<std::string>() == "keep\n\n");
			YAML_ASSERT(doc[3].as<std::string>() == " strip");
			return true;
		}
797
798
		
		// 8.2
799
800
801
802
803
804
805
806
807
		TEST BlockIndentationHeader() {
			YAML::Node doc = YAML::Parse(ex8_2);
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc[0].as<std::string>() == "detected\n");
			YAML_ASSERT(doc[1].as<std::string>() == "\n\n# detected\n");
			YAML_ASSERT(doc[2].as<std::string>() == " explicit\n");
			YAML_ASSERT(doc[3].as<std::string>() == "\t\ndetected\n");
			return true;
		}
808
809
		
		// 8.3
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
		TEST InvalidBlockScalarIndentationIndicators() {
			{
				bool threw = false;
				try {
					YAML::Parse(ex8_3a);
				} catch(const YAML::Exception& e) {
					if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
						throw;
					
					threw = true;
				}
				
				if(!threw)
					return "  no exception thrown for less indented auto-detecting indentation for a literal block scalar";
			}
			
			{
				bool threw = false;
				try {
					YAML::Parse(ex8_3b);
				} catch(const YAML::Exception& e) {
					if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
						throw;
					
					threw = true;
				}
				
				if(!threw)
					return "  no exception thrown for less indented auto-detecting indentation for a folded block scalar";
			}
			
			{
				bool threw = false;
				try {
					YAML::Parse(ex8_3c);
				} catch(const YAML::Exception& e) {
					if(e.msg != YAML::ErrorMsg::END_OF_SEQ)
						throw;
					
					threw = true;
				}
				
				if(!threw)
					return "  no exception thrown for less indented explicit indentation for a literal block scalar";
			}
			
			return true;
		}
858
859
		
		// 8.4
860
861
862
863
864
865
866
867
		TEST ChompingFinalLineBreak() {
			YAML::Node doc = YAML::Parse(ex8_4);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["strip"].as<std::string>() == "text");
			YAML_ASSERT(doc["clip"].as<std::string>() == "text\n");
			YAML_ASSERT(doc["keep"].as<std::string>() == "text\n");
			return true;
		}
868
869
		
		// 8.5
870
871
872
873
874
875
876
877
		TEST ChompingTrailingLines() {
			YAML::Node doc = YAML::Parse(ex8_5);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["strip"].as<std::string>() == "# text");
			YAML_ASSERT(doc["clip"].as<std::string>() == "# text\n");
			YAML_ASSERT(doc["keep"].as<std::string>() == "# text\n"); // Note: I believe this is a bug in the YAML spec - it should be "# text\n\n"
			return true;
		}
878
879
		
		// 8.6
880
881
882
883
884
885
886
887
		TEST EmptyScalarChomping() {
			YAML::Node doc = YAML::Parse(ex8_6);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["strip"].as<std::string>() == "");
			YAML_ASSERT(doc["clip"].as<std::string>() == "");
			YAML_ASSERT(doc["keep"].as<std::string>() == "\n");
			return true;
		}
888
889
		
		// 8.7
890
891
892
893
894
		TEST LiteralScalar() {
			YAML::Node doc = YAML::Parse(ex8_7);
			YAML_ASSERT(doc.as<std::string>() == "literal\n\ttext\n");
			return true;
		}
895
896
		
		// 8.8
897
898
899
900
901
		TEST LiteralContent() {
			YAML::Node doc = YAML::Parse(ex8_8);
			YAML_ASSERT(doc.as<std::string>() == "\n\nliteral\n \n\ntext\n");
			return true;
		}
902
903
		
		// 8.9
904
905
906
907
908
		TEST FoldedScalar() {
			YAML::Node doc = YAML::Parse(ex8_9);
			YAML_ASSERT(doc.as<std::string>() == "folded text\n");
			return true;
		}
909
910
		
		// 8.10
911
912
913
914
915
		TEST FoldedLines() {
			YAML::Node doc = YAML::Parse(ex8_10);
			YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n  * bullet\n\n  * list\n  * lines\n\nlast line\n");
			return true;
		}
916
917
		
		// 8.11
918
919
920
921
922
		TEST MoreIndentedLines() {
			YAML::Node doc = YAML::Parse(ex8_11);
			YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n  * bullet\n\n  * list\n  * lines\n\nlast line\n");
			return true;
		}
923
924
		
		// 8.12
925
926
927
928
929
		TEST EmptySeparationLines() {
			YAML::Node doc = YAML::Parse(ex8_12);
			YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n  * bullet\n\n  * list\n  * lines\n\nlast line\n");
			return true;
		}
930
931
		
		// 8.13
932
933
934
935
936
		TEST FinalEmptyLines() {
			YAML::Node doc = YAML::Parse(ex8_13);
			YAML_ASSERT(doc.as<std::string>() == "\nfolded line\nnext line\n  * bullet\n\n  * list\n  * lines\n\nlast line\n");
			return true;
		}
937
938
		
		// 8.14
939
940
941
942
943
944
945
946
947
		TEST BlockSequence() {
			YAML::Node doc = YAML::Parse(ex8_14);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["block sequence"].size() == 2);
			YAML_ASSERT(doc["block sequence"][0].as<std::string>() == "one");
			YAML_ASSERT(doc["block sequence"][1].size() == 1);
			YAML_ASSERT(doc["block sequence"][1]["two"].as<std::string>() == "three");
			return true;
		}
948
949
		
		// 8.15
950
951
952
953
954
955
956
957
958
959
960
961
		TEST BlockSequenceEntryTypes() {
			YAML::Node doc = YAML::Parse(ex8_15);
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc[0].Type() == YAML::NodeType::Null);
			YAML_ASSERT(doc[1].as<std::string>() == "block node\n");
			YAML_ASSERT(doc[2].size() == 2);
			YAML_ASSERT(doc[2][0].as<std::string>() == "one");
			YAML_ASSERT(doc[2][1].as<std::string>() == "two");
			YAML_ASSERT(doc[3].size() == 1);
			YAML_ASSERT(doc[3]["one"].as<std::string>() == "two");
			return true;
		}
962
963
		
		// 8.16
964
965
966
967
968
969
970
		TEST BlockMappings() {
			YAML::Node doc = YAML::Parse(ex8_16);
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["block mapping"].size() == 1);
			YAML_ASSERT(doc["block mapping"]["key"].as<std::string>() == "value");
			return true;
		}
971
972
		
		// 8.17
973
974
975
976
977
978
979
980
981
		TEST ExplicitBlockMappingEntries() {
			YAML::Node doc = YAML::Parse(ex8_17);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["explicit key"].Type() == YAML::NodeType::Null);
			YAML_ASSERT(doc["block key\n"].size() == 2);
			YAML_ASSERT(doc["block key\n"][0].as<std::string>() == "one");
			YAML_ASSERT(doc["block key\n"][1].as<std::string>() == "two");
			return true;
		}
982
983
		
		// 8.18
984
985
986
987
		TEST ImplicitBlockMappingEntries() {
			YAML::Node doc = YAML::Parse(ex8_18);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["plain key"].as<std::string>() == "in-line value");
988
			YAML_ASSERT(doc[YAML::Null].Type() == YAML::NodeType::Null);
989
990
991
992
			YAML_ASSERT(doc["quoted key"].size() == 1);
			YAML_ASSERT(doc["quoted key"][0].as<std::string>() == "entry");
			return true;
		}
993
994
		
		// 8.19
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
		TEST CompactBlockMappings() {
			YAML::Node doc = YAML::Parse(ex8_19);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["sun"].as<std::string>() == "yellow");
			YAML_ASSERT(doc[1].size() == 1);
			std::map<std::string, std::string> key;
			key["earth"] = "blue";
			YAML_ASSERT(doc[1][key].size() == 1);
			YAML_ASSERT(doc[1][key]["moon"].as<std::string>() == "white");
			return true;
		}
1007
1008
		
		// 8.20
1009
1010
1011
1012
1013
1014
1015
1016
1017
		TEST BlockNodeTypes() {
			YAML::Node doc = YAML::Parse(ex8_20);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].as<std::string>() == "flow in block");
			YAML_ASSERT(doc[1].as<std::string>() == "Block scalar\n");
			YAML_ASSERT(doc[2].size() == 1);
			YAML_ASSERT(doc[2]["foo"].as<std::string>() == "bar");
			return true;
		}
1018
1019
1020
1021
1022
		
		// 8.21
		TEST BlockScalarNodes() { return "  not written yet"; }
		
		// 8.22
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
		TEST BlockCollectionNodes() {
			YAML::Node doc = YAML::Parse(ex8_22);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["sequence"].size() == 2);
			YAML_ASSERT(doc["sequence"][0].as<std::string>() == "entry");
			YAML_ASSERT(doc["sequence"][1].size() == 1);
			YAML_ASSERT(doc["sequence"][1][0].as<std::string>() == "nested");
			YAML_ASSERT(doc["mapping"].size() == 1);
			YAML_ASSERT(doc["mapping"]["foo"].as<std::string>() == "bar");
			return true;
		}
1034
1035
	}
}