"test/old-api/parsertests.cpp" did not exist on "c7ed85a4acf2ac9394fce22be668377235724dcc"
spectests.cpp 41.3 KB
Newer Older
beder's avatar
beder committed
1
#include "spectests.h"
2
#include "specexamples.h"
beder's avatar
beder committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "yaml-cpp/yaml.h"
#include <fstream>
#include <sstream>
#include <vector>
#include <iostream>

#define YAML_ASSERT(cond) do { if(!(cond)) return "  Assert failed: " #cond; } while(false)
#define PARSE(doc, input) \
	std::stringstream stream(input);\
	YAML::Parser parser(stream);\
	YAML::Node doc;\
	parser.GetNextDocument(doc)
#define PARSE_NEXT(doc) parser.GetNextDocument(doc)

namespace Test {
	namespace Spec {
		// 2.1
		TEST SeqScalars() {
21
			PARSE(doc, ex2_1);
beder's avatar
beder committed
22
23
24
25
26
27
28
29
30
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].to<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc[1].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc[2].to<std::string>() == "Ken Griffey");
			return true;
		}
		
		// 2.2
		TEST MappingScalarsToScalars() {
31
			PARSE(doc, ex2_2);
beder's avatar
beder committed
32
33
34
35
36
37
38
39
40
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["hr"].to<std::string>() == "65");
			YAML_ASSERT(doc["avg"].to<std::string>() == "0.278");
			YAML_ASSERT(doc["rbi"].to<std::string>() == "147");
			return true;
		}
		
		// 2.3
		TEST MappingScalarsToSequences() {
41
			PARSE(doc, ex2_3);
beder's avatar
beder committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["american"].size() == 3);
			YAML_ASSERT(doc["american"][0].to<std::string>() == "Boston Red Sox");
			YAML_ASSERT(doc["american"][1].to<std::string>() == "Detroit Tigers");
			YAML_ASSERT(doc["american"][2].to<std::string>() == "New York Yankees");
			YAML_ASSERT(doc["national"].size() == 3);
			YAML_ASSERT(doc["national"][0].to<std::string>() == "New York Mets");
			YAML_ASSERT(doc["national"][1].to<std::string>() == "Chicago Cubs");
			YAML_ASSERT(doc["national"][2].to<std::string>() == "Atlanta Braves");
			return true;
		}
		
		// 2.4
		TEST SequenceOfMappings()
		{
57
			PARSE(doc, ex2_4);
beder's avatar
beder committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 3);
			YAML_ASSERT(doc[0]["name"].to<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc[0]["hr"].to<std::string>() == "65");
			YAML_ASSERT(doc[0]["avg"].to<std::string>() == "0.278");
			YAML_ASSERT(doc[1].size() == 3);
			YAML_ASSERT(doc[1]["name"].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc[1]["hr"].to<std::string>() == "63");
			YAML_ASSERT(doc[1]["avg"].to<std::string>() == "0.288");
			return true;
		}
		
		// 2.5
		TEST SequenceOfSequences()
		{
73
			PARSE(doc, ex2_5);
beder's avatar
beder committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].size() == 3);
			YAML_ASSERT(doc[0][0].to<std::string>() == "name");
			YAML_ASSERT(doc[0][1].to<std::string>() == "hr");
			YAML_ASSERT(doc[0][2].to<std::string>() == "avg");
			YAML_ASSERT(doc[1].size() == 3);
			YAML_ASSERT(doc[1][0].to<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc[1][1].to<std::string>() == "65");
			YAML_ASSERT(doc[1][2].to<std::string>() == "0.278");
			YAML_ASSERT(doc[2].size() == 3);
			YAML_ASSERT(doc[2][0].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc[2][1].to<std::string>() == "63");
			YAML_ASSERT(doc[2][2].to<std::string>() == "0.288");
			return true;
		}
		
		// 2.6
		TEST MappingOfMappings()
		{
93
			PARSE(doc, ex2_6);
beder's avatar
beder committed
94
95
96
97
98
99
100
101
102
103
104
105
106
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["Mark McGwire"].size() == 2);
			YAML_ASSERT(doc["Mark McGwire"]["hr"].to<std::string>() == "65");
			YAML_ASSERT(doc["Mark McGwire"]["avg"].to<std::string>() == "0.278");
			YAML_ASSERT(doc["Sammy Sosa"].size() == 2);
			YAML_ASSERT(doc["Sammy Sosa"]["hr"].to<std::string>() == "63");
			YAML_ASSERT(doc["Sammy Sosa"]["avg"].to<std::string>() == "0.288");
			return true;
		}
		
		// 2.7
		TEST TwoDocumentsInAStream()
		{
107
			PARSE(doc, ex2_7);
beder's avatar
beder committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].to<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc[1].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc[2].to<std::string>() == "Ken Griffey");

			PARSE_NEXT(doc);
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].to<std::string>() == "Chicago Cubs");
			YAML_ASSERT(doc[1].to<std::string>() == "St Louis Cardinals");
			return true;
		}
		
		// 2.8
		TEST PlayByPlayFeed()
		{
123
			PARSE(doc, ex2_8);
beder's avatar
beder committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["time"].to<std::string>() == "20:03:20");
			YAML_ASSERT(doc["player"].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["action"].to<std::string>() == "strike (miss)");

			PARSE_NEXT(doc);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["time"].to<std::string>() == "20:03:47");
			YAML_ASSERT(doc["player"].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["action"].to<std::string>() == "grand slam");
			return true;
		}
		
		// 2.9
		TEST SingleDocumentWithTwoComments()
		{
140
			PARSE(doc, ex2_9);
beder's avatar
beder committed
141
142
143
144
145
146
147
148
149
150
151
152
153
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["hr"].size() == 2);
			YAML_ASSERT(doc["hr"][0].to<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc["hr"][1].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["rbi"].size() == 2);
			YAML_ASSERT(doc["rbi"][0].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["rbi"][1].to<std::string>() == "Ken Griffey");
			return true;
		}
		
		// 2.10
		TEST SimpleAnchor()
		{
154
			PARSE(doc, ex2_10);
beder's avatar
beder committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["hr"].size() == 2);
			YAML_ASSERT(doc["hr"][0].to<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc["hr"][1].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["rbi"].size() == 2);
			YAML_ASSERT(doc["rbi"][0].to<std::string>() == "Sammy Sosa");
			YAML_ASSERT(doc["rbi"][1].to<std::string>() == "Ken Griffey");
			return true;
		}
		
		struct Pair {
			Pair() {}
			Pair(const std::string& f, const std::string& s): first(f), second(s) {}
			std::string first, second;
		};
		
		bool operator == (const Pair& p, const Pair& q) {
			return p.first == q.first && p.second == q.second;
		}
		
		void operator >> (const YAML::Node& node, Pair& p) {
			node[0] >> p.first;
			node[1] >> p.second;
		}
		
		// 2.11
		TEST MappingBetweenSequences()
		{
183
			PARSE(doc, ex2_11);
beder's avatar
beder committed
184
185
186
187
188
189
190
191
192
193
194
195
196
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")].size() == 1);
			YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")][0].to<std::string>() == "2001-07-23");
			YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")].size() == 3);
			YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][0].to<std::string>() == "2001-07-02");
			YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][1].to<std::string>() == "2001-08-12");
			YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][2].to<std::string>() == "2001-08-14");
			return true;
		}
		
		// 2.12
		TEST CompactNestedMapping()
		{
197
			PARSE(doc, ex2_12);
beder's avatar
beder committed
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0]["item"].to<std::string>() == "Super Hoop");
			YAML_ASSERT(doc[0]["quantity"].to<int>() == 1);
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1]["item"].to<std::string>() == "Basketball");
			YAML_ASSERT(doc[1]["quantity"].to<int>() == 4);
			YAML_ASSERT(doc[2].size() == 2);
			YAML_ASSERT(doc[2]["item"].to<std::string>() == "Big Shoes");
			YAML_ASSERT(doc[2]["quantity"].to<int>() == 1);
			return true;
		}
		
		// 2.13
		TEST InLiteralsNewlinesArePreserved()
		{
214
			PARSE(doc, ex2_13);
beder's avatar
beder committed
215
216
217
218
219
220
221
222
223
			YAML_ASSERT(doc.to<std::string>() ==
						"\\//||\\/||\n"
						"// ||  ||__");
			return true;
		}
		
		// 2.14
		TEST InFoldedScalarsNewlinesBecomeSpaces()
		{
224
			PARSE(doc, ex2_14);
beder's avatar
beder committed
225
226
227
228
229
230
231
			YAML_ASSERT(doc.to<std::string>() == "Mark McGwire's year was crippled by a knee injury.");
			return true;
		}
		
		// 2.15
		TEST FoldedNewlinesArePreservedForMoreIndentedAndBlankLines()
		{
232
			PARSE(doc, ex2_15);
beder's avatar
beder committed
233
234
235
236
237
238
239
240
241
242
243
			YAML_ASSERT(doc.to<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;
		}
		
		// 2.16
		TEST IndentationDeterminesScope()
		{
244
			PARSE(doc, ex2_16);
beder's avatar
beder committed
245
246
247
248
249
250
251
252
253
254
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["name"].to<std::string>() == "Mark McGwire");
			YAML_ASSERT(doc["accomplishment"].to<std::string>() == "Mark set a major league home run record in 1998.\n");
			YAML_ASSERT(doc["stats"].to<std::string>() == "65 Home Runs\n0.278 Batting Average\n");
			return true;
		}
		
		// 2.17
		TEST QuotedScalars()
		{
255
			PARSE(doc, ex2_17);
beder's avatar
beder committed
256
257
258
259
260
261
262
263
264
265
266
267
268
			YAML_ASSERT(doc.size() == 6);
			YAML_ASSERT(doc["unicode"].to<std::string>() == "Sosa did fine.\xe2\x98\xba");
			YAML_ASSERT(doc["control"].to<std::string>() == "\b1998\t1999\t2000\n");
			YAML_ASSERT(doc["hex esc"].to<std::string>() == "\x0d\x0a is \r\n");
			YAML_ASSERT(doc["single"].to<std::string>() == "\"Howdy!\" he cried.");
			YAML_ASSERT(doc["quoted"].to<std::string>() == " # Not a 'comment'.");
			YAML_ASSERT(doc["tie-fighter"].to<std::string>() == "|\\-*-/|");
			return true;
		}
		
		// 2.18
		TEST MultiLineFlowScalars()
		{
269
			PARSE(doc, ex2_18);
beder's avatar
beder committed
270
271
272
273
274
275
276
277
278
279
280
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["plain"].to<std::string>() == "This unquoted scalar spans many lines.");
			YAML_ASSERT(doc["quoted"].to<std::string>() == "So does this quoted scalar.\n");
			return true;
		}
		
		// TODO: 2.19 - 2.22 schema tags
		
		// 2.23
		TEST VariousExplicitTags()
		{
281
			PARSE(doc, ex2_23);
beder's avatar
beder committed
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["not-date"].Tag() == "tag:yaml.org,2002:str");
			YAML_ASSERT(doc["not-date"].to<std::string>() == "2002-04-28");
			YAML_ASSERT(doc["picture"].Tag() == "tag:yaml.org,2002:binary");
			YAML_ASSERT(doc["picture"].to<std::string>() ==
				"R0lGODlhDAAMAIQAAP//9/X\n"
				"17unp5WZmZgAAAOfn515eXv\n"
				"Pz7Y6OjuDg4J+fn5OTk6enp\n"
				"56enmleECcgggoBADs=\n"
			);
			YAML_ASSERT(doc["application specific tag"].Tag() == "!something");
			YAML_ASSERT(doc["application specific tag"].to<std::string>() ==
				"The semantics of the tag\n"
				"above may be different for\n"
				"different documents."
			);
			return true;
		}
		
		// 2.24
		TEST GlobalTags()
		{
304
			PARSE(doc, ex2_24);
beder's avatar
beder committed
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
			YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:shape");
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].Tag() == "tag:clarkevans.com,2002:circle");
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0]["center"].size() == 2);
			YAML_ASSERT(doc[0]["center"]["x"].to<int>() == 73);
			YAML_ASSERT(doc[0]["center"]["y"].to<int>() == 129);
			YAML_ASSERT(doc[0]["radius"].to<int>() == 7);
			YAML_ASSERT(doc[1].Tag() == "tag:clarkevans.com,2002:line");
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1]["start"].size() == 2);
			YAML_ASSERT(doc[1]["start"]["x"].to<int>() == 73);
			YAML_ASSERT(doc[1]["start"]["y"].to<int>() == 129);
			YAML_ASSERT(doc[1]["finish"].size() == 2);
			YAML_ASSERT(doc[1]["finish"]["x"].to<int>() == 89);
			YAML_ASSERT(doc[1]["finish"]["y"].to<int>() == 102);
			YAML_ASSERT(doc[2].Tag() == "tag:clarkevans.com,2002:label");
			YAML_ASSERT(doc[2].size() == 3);
			YAML_ASSERT(doc[2]["start"].size() == 2);
			YAML_ASSERT(doc[2]["start"]["x"].to<int>() == 73);
			YAML_ASSERT(doc[2]["start"]["y"].to<int>() == 129);
			YAML_ASSERT(doc[2]["color"].to<std::string>() == "0xFFEEBB");
			YAML_ASSERT(doc[2]["text"].to<std::string>() == "Pretty vector drawing.");
			return true;
		}
		
		// 2.25
		TEST UnorderedSets()
		{
334
			PARSE(doc, ex2_25);
beder's avatar
beder committed
335
336
337
338
339
340
341
342
343
344
345
			YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:set");
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(IsNull(doc["Mark McGwire"]));
			YAML_ASSERT(IsNull(doc["Sammy Sosa"]));
			YAML_ASSERT(IsNull(doc["Ken Griffey"]));
			return true;
		}
		
		// 2.26
		TEST OrderedMappings()
		{
346
			PARSE(doc, ex2_26);
beder's avatar
beder committed
347
348
349
350
351
352
353
354
355
356
357
358
359
360
			YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:omap");
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["Mark McGwire"].to<int>() == 65);
			YAML_ASSERT(doc[1].size() == 1);
			YAML_ASSERT(doc[1]["Sammy Sosa"].to<int>() == 63);
			YAML_ASSERT(doc[2].size() == 1);
			YAML_ASSERT(doc[2]["Ken Griffey"].to<int>() == 58);
			return true;
		}
		
		// 2.27
		TEST Invoice()
		{
361
			PARSE(doc, ex2_27);
beder's avatar
beder committed
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
			YAML_ASSERT(doc.Tag() == "tag:clarkevans.com,2002:invoice");
			YAML_ASSERT(doc.size() == 8);
			YAML_ASSERT(doc["invoice"].to<int>() == 34843);
			YAML_ASSERT(doc["date"].to<std::string>() == "2001-01-23");
			YAML_ASSERT(doc["bill-to"].size() == 3);
			YAML_ASSERT(doc["bill-to"]["given"].to<std::string>() == "Chris");
			YAML_ASSERT(doc["bill-to"]["family"].to<std::string>() == "Dumars");
			YAML_ASSERT(doc["bill-to"]["address"].size() == 4);
			YAML_ASSERT(doc["bill-to"]["address"]["lines"].to<std::string>() == "458 Walkman Dr.\nSuite #292\n");
			YAML_ASSERT(doc["bill-to"]["address"]["city"].to<std::string>() == "Royal Oak");
			YAML_ASSERT(doc["bill-to"]["address"]["state"].to<std::string>() == "MI");
			YAML_ASSERT(doc["bill-to"]["address"]["postal"].to<std::string>() == "48046");
			YAML_ASSERT(doc["ship-to"].size() == 3);
			YAML_ASSERT(doc["ship-to"]["given"].to<std::string>() == "Chris");
			YAML_ASSERT(doc["ship-to"]["family"].to<std::string>() == "Dumars");
			YAML_ASSERT(doc["ship-to"]["address"].size() == 4);
			YAML_ASSERT(doc["ship-to"]["address"]["lines"].to<std::string>() == "458 Walkman Dr.\nSuite #292\n");
			YAML_ASSERT(doc["ship-to"]["address"]["city"].to<std::string>() == "Royal Oak");
			YAML_ASSERT(doc["ship-to"]["address"]["state"].to<std::string>() == "MI");
			YAML_ASSERT(doc["ship-to"]["address"]["postal"].to<std::string>() == "48046");
			YAML_ASSERT(doc["product"].size() == 2);
			YAML_ASSERT(doc["product"][0].size() == 4);
			YAML_ASSERT(doc["product"][0]["sku"].to<std::string>() == "BL394D");
			YAML_ASSERT(doc["product"][0]["quantity"].to<int>() == 4);
			YAML_ASSERT(doc["product"][0]["description"].to<std::string>() == "Basketball");
			YAML_ASSERT(doc["product"][0]["price"].to<std::string>() == "450.00");
			YAML_ASSERT(doc["product"][1].size() == 4);
			YAML_ASSERT(doc["product"][1]["sku"].to<std::string>() == "BL4438H");
			YAML_ASSERT(doc["product"][1]["quantity"].to<int>() == 1);
			YAML_ASSERT(doc["product"][1]["description"].to<std::string>() == "Super Hoop");
			YAML_ASSERT(doc["product"][1]["price"].to<std::string>() == "2392.00");
			YAML_ASSERT(doc["tax"].to<std::string>() == "251.42");
			YAML_ASSERT(doc["total"].to<std::string>() == "4443.52");
			YAML_ASSERT(doc["comments"].to<std::string>() == "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.");
			return true;
		}
		
		// 2.28
		TEST LogFile()
		{
402
			PARSE(doc, ex2_28);
beder's avatar
beder committed
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["Time"].to<std::string>() == "2001-11-23 15:01:42 -5");
			YAML_ASSERT(doc["User"].to<std::string>() == "ed");
			YAML_ASSERT(doc["Warning"].to<std::string>() == "This is an error message for the log file");

			PARSE_NEXT(doc);
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["Time"].to<std::string>() == "2001-11-23 15:02:31 -5");
			YAML_ASSERT(doc["User"].to<std::string>() == "ed");
			YAML_ASSERT(doc["Warning"].to<std::string>() == "A slightly different error message.");

			PARSE_NEXT(doc);
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc["Date"].to<std::string>() == "2001-11-23 15:03:17 -5");
			YAML_ASSERT(doc["User"].to<std::string>() == "ed");
			YAML_ASSERT(doc["Fatal"].to<std::string>() == "Unknown variable \"bar\"");
			YAML_ASSERT(doc["Stack"].size() == 2);
			YAML_ASSERT(doc["Stack"][0].size() == 3);
			YAML_ASSERT(doc["Stack"][0]["file"].to<std::string>() == "TopClass.py");
			YAML_ASSERT(doc["Stack"][0]["line"].to<std::string>() == "23");
			YAML_ASSERT(doc["Stack"][0]["code"].to<std::string>() == "x = MoreObject(\"345\\n\")\n");
			YAML_ASSERT(doc["Stack"][1].size() == 3);
			YAML_ASSERT(doc["Stack"][1]["file"].to<std::string>() == "MoreClass.py");
			YAML_ASSERT(doc["Stack"][1]["line"].to<std::string>() == "58");
			YAML_ASSERT(doc["Stack"][1]["code"].to<std::string>() == "foo = bar");
			return true;
		}
		
		// TODO: 5.1 - 5.2 BOM
		
		// 5.3
		TEST BlockStructureIndicators()
		{
436
			PARSE(doc, ex5_3);
beder's avatar
beder committed
437
438
439
440
441
442
443
444
445
446
447
448
449
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["sequence"].size() == 2);
			YAML_ASSERT(doc["sequence"][0].to<std::string>() == "one");
			YAML_ASSERT(doc["sequence"][1].to<std::string>() == "two");
			YAML_ASSERT(doc["mapping"].size() == 2);
			YAML_ASSERT(doc["mapping"]["sky"].to<std::string>() == "blue");
			YAML_ASSERT(doc["mapping"]["sea"].to<std::string>() == "green");
			return true;
		}
		
		// 5.4
		TEST FlowStructureIndicators()
		{
450
			PARSE(doc, ex5_4);
beder's avatar
beder committed
451
452
453
454
455
456
457
458
459
460
461
462
463
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["sequence"].size() == 2);
			YAML_ASSERT(doc["sequence"][0].to<std::string>() == "one");
			YAML_ASSERT(doc["sequence"][1].to<std::string>() == "two");
			YAML_ASSERT(doc["mapping"].size() == 2);
			YAML_ASSERT(doc["mapping"]["sky"].to<std::string>() == "blue");
			YAML_ASSERT(doc["mapping"]["sea"].to<std::string>() == "green");
			return true;
		}
		
		// 5.5
		TEST CommentIndicator()
		{
464
			PARSE(doc, ex5_5);
beder's avatar
beder committed
465
466
467
468
469
470
471
			YAML_ASSERT(doc.size() == 0);
			return true;
		}
		
		// 5.6
		TEST NodePropertyIndicators()
		{
472
			PARSE(doc, ex5_6);
beder's avatar
beder committed
473
474
475
476
477
478
479
480
481
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["anchored"].to<std::string>() == "value"); // TODO: assert tag
			YAML_ASSERT(doc["alias"].to<std::string>() == "value");
			return true;
		}
		
		// 5.7
		TEST BlockScalarIndicators()
		{
482
			PARSE(doc, ex5_7);
beder's avatar
beder committed
483
484
485
486
487
488
489
490
491
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["literal"].to<std::string>() == "some\ntext\n");
			YAML_ASSERT(doc["folded"].to<std::string>() == "some text\n");
			return true;
		}
		
		// 5.8
		TEST QuotedScalarIndicators()
		{
492
			PARSE(doc, ex5_8);
beder's avatar
beder committed
493
494
495
496
497
498
499
500
501
502
503
504
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["single"].to<std::string>() == "text");
			YAML_ASSERT(doc["double"].to<std::string>() == "text");
			return true;
		}
		
		// TODO: 5.9 directive
		// TODO: 5.10 reserved indicator
		
		// 5.11
		TEST LineBreakCharacters()
		{
505
			PARSE(doc, ex5_11);
beder's avatar
beder committed
506
507
508
509
510
511
512
			YAML_ASSERT(doc.to<std::string>() == "Line break (no glyph)\nLine break (glyphed)\n");
			return true;
		}
		
		// 5.12
		TEST TabsAndSpaces()
		{
513
			PARSE(doc, ex5_12);
beder's avatar
beder committed
514
515
516
517
518
519
520
521
522
523
524
525
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["quoted"].to<std::string>() == "Quoted\t");
			YAML_ASSERT(doc["block"].to<std::string>() ==
						"void main() {\n"
						"\tprintf(\"Hello, world!\\n\");\n"
						"}");
			return true;
		}
		
		// 5.13
		TEST EscapedCharacters()
		{
526
			PARSE(doc, ex5_13);
beder's avatar
beder committed
527
528
529
530
531
532
533
			YAML_ASSERT(doc.to<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;
		}
		
		// 5.14
		TEST InvalidEscapedCharacters()
		{
534
			std::stringstream stream(ex5_14);
beder's avatar
beder committed
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
			try {
				YAML::Parser parser(stream);
				YAML::Node doc;
				parser.GetNextDocument(doc);
			} catch(const YAML::ParserException& e) {
				YAML_ASSERT(e.msg == std::string(YAML::ErrorMsg::INVALID_ESCAPE) + "c");
				return true;
			}
			
			return false;
		}
		
		// 6.1
		TEST IndentationSpaces()
		{
550
			PARSE(doc, ex6_1);
beder's avatar
beder committed
551
552
553
554
555
556
557
558
559
560
561
562
563
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["Not indented"].size() == 2);
			YAML_ASSERT(doc["Not indented"]["By one space"].to<std::string>() == "By four\n  spaces\n");
			YAML_ASSERT(doc["Not indented"]["Flow style"].size() == 3);
			YAML_ASSERT(doc["Not indented"]["Flow style"][0].to<std::string>() == "By two");
			YAML_ASSERT(doc["Not indented"]["Flow style"][1].to<std::string>() == "Also by two");
			YAML_ASSERT(doc["Not indented"]["Flow style"][2].to<std::string>() == "Still by two");
			return true;
		}
		
		// 6.2
		TEST IndentationIndicators()
		{
564
			PARSE(doc, ex6_2);
beder's avatar
beder committed
565
566
567
568
569
570
571
572
573
574
575
576
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["a"].size() == 2);
			YAML_ASSERT(doc["a"][0].to<std::string>() == "b");
			YAML_ASSERT(doc["a"][1].size() == 2);
			YAML_ASSERT(doc["a"][1][0].to<std::string>() == "c");
			YAML_ASSERT(doc["a"][1][1].to<std::string>() == "d");
			return true;
		}
		
		// 6.3
		TEST SeparationSpaces()
		{
577
			PARSE(doc, ex6_3);
beder's avatar
beder committed
578
579
580
581
582
583
584
585
586
587
588
589
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["foo"].to<std::string>() == "bar");
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1][0].to<std::string>() == "baz");
			YAML_ASSERT(doc[1][1].to<std::string>() == "baz");
			return true;
		}
		
		// 6.4
		TEST LinePrefixes()
		{
590
			PARSE(doc, ex6_4);
beder's avatar
beder committed
591
592
593
594
595
596
597
598
599
600
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["plain"].to<std::string>() == "text lines");
			YAML_ASSERT(doc["quoted"].to<std::string>() == "text lines");
			YAML_ASSERT(doc["block"].to<std::string>() == "text\n \tlines\n");
			return true;
		}
		
		// 6.5
		TEST EmptyLines()
		{
601
			PARSE(doc, ex6_5);
beder's avatar
beder committed
602
603
604
605
606
607
608
609
610
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["Folding"].to<std::string>() == "Empty line\nas a line feed");
			YAML_ASSERT(doc["Chomping"].to<std::string>() == "Clipped empty lines\n");
			return true;
		}
		
		// 6.6
		TEST LineFolding()
		{
611
			PARSE(doc, ex6_6);
beder's avatar
beder committed
612
613
614
615
616
617
618
			YAML_ASSERT(doc.to<std::string>() == "trimmed\n\n\nas space");
			return true;
		}
		
		// 6.7
		TEST BlockFolding()
		{
619
			PARSE(doc, ex6_7);
beder's avatar
beder committed
620
621
622
623
624
625
626
			YAML_ASSERT(doc.to<std::string>() == "foo \n\n\t bar\n\nbaz\n");
			return true;
		}
		
		// 6.8
		TEST FlowFolding()
		{
627
			PARSE(doc, ex6_8);			
beder's avatar
beder committed
628
629
630
631
632
633
634
			YAML_ASSERT(doc.to<std::string>() == " foo\nbar\nbaz ");
			return true;
		}
		
		// 6.9
		TEST SeparatedComment()
		{
635
			PARSE(doc, ex6_9);
beder's avatar
beder committed
636
637
638
639
640
641
642
643
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["key"].to<std::string>() == "value");
			return true;
		}
		
		// 6.10
		TEST CommentLines()
		{
644
			PARSE(doc, ex6_10);
beder's avatar
beder committed
645
646
647
648
649
650
651
			YAML_ASSERT(doc.size() == 0);
			return true;
		}
		
		// 6.11
		TEST MultiLineComments()
		{
652
			PARSE(doc, ex6_11);
beder's avatar
beder committed
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["key"].to<std::string>() == "value");
			return true;
		}

		struct StringMap {
			typedef std::map<std::string, std::string> Map;
			Map _;
		};
		
		bool operator == (const StringMap& m, const StringMap& n) {
			return m._ == n._;
		}
		
		void operator >> (const YAML::Node& node, StringMap& m) {
			m._.clear();
			for(YAML::Iterator it=node.begin();it!=node.end();++it) {
				std::string key = it.first().to<std::string>();
				std::string value = it.second().to<std::string>();
				m._[key] = value;
			}
		}

		
		// 6.12
		TEST SeparationSpacesII()
		{
680
			PARSE(doc, ex6_12);
beder's avatar
beder committed
681
682
683
684
685
686
687
688
689
690
691
692
693
			std::map<std::string, std::string> key;
			key["first"] = "Sammy";
			key["last"] = "Sosa";
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc[key].size() == 2);
			YAML_ASSERT(doc[key]["hr"].to<int>() == 65);
			YAML_ASSERT(doc[key]["avg"].to<std::string>() == "0.278");
			return true;
		}
		
		// 6.13
		TEST ReservedDirectives()
		{
694
			PARSE(doc, ex6_13);
beder's avatar
beder committed
695
696
697
698
699
700
			return true;
		}
		
		// 6.14
		TEST YAMLDirective()
		{
701
			PARSE(doc, ex6_14);
beder's avatar
beder committed
702
703
704
705
706
707
708
			return true;
		}
		
		// 6.15
		TEST InvalidRepeatedYAMLDirective()
		{
			try {
709
				PARSE(doc, ex6_15);
beder's avatar
beder committed
710
711
712
713
714
715
716
717
718
719
720
721
722
			} catch(const YAML::ParserException& e) {
				if(e.msg == YAML::ErrorMsg::REPEATED_YAML_DIRECTIVE)
					return true;

				throw;
			}
			
			return "  No exception was thrown";
		}
		
		// 6.16
		TEST TagDirective()
		{
723
			PARSE(doc, ex6_16);
beder's avatar
beder committed
724
725
726
727
728
729
730
731
732
			YAML_ASSERT(doc.Tag() == "tag:yaml.org,2002:str");
			YAML_ASSERT(doc.to<std::string>() == "foo");
			return true;
		}
		
		// 6.17
		TEST InvalidRepeatedTagDirective()
		{
			try {
733
				PARSE(doc, ex6_17);
beder's avatar
beder committed
734
735
736
737
738
739
740
741
742
743
744
745
746
			} catch(const YAML::ParserException& e) {
				if(e.msg == YAML::ErrorMsg::REPEATED_TAG_DIRECTIVE)
					return true;
				
				throw;
			}
	
			return "  No exception was thrown";
		}

		// 6.18
		TEST PrimaryTagHandle()
		{
747
			PARSE(doc, ex6_18);
beder's avatar
beder committed
748
749
750
751
752
753
754
755
756
757
758
759
			YAML_ASSERT(doc.Tag() == "!foo");
			YAML_ASSERT(doc.to<std::string>() == "bar");

			PARSE_NEXT(doc);
			YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/foo");
			YAML_ASSERT(doc.to<std::string>() == "bar");
			return true;
		}
		
		// 6.19
		TEST SecondaryTagHandle()
		{
760
			PARSE(doc, ex6_19);
beder's avatar
beder committed
761
762
763
764
765
766
767
768
			YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/int");
			YAML_ASSERT(doc.to<std::string>() == "1 - 3");
			return true;
		}
		
		// 6.20
		TEST TagHandles()
		{
769
			PARSE(doc, ex6_20);
beder's avatar
beder committed
770
771
772
773
774
775
776
777
			YAML_ASSERT(doc.Tag() == "tag:example.com,2000:app/foo");
			YAML_ASSERT(doc.to<std::string>() == "bar");
			return true;
		}
		
		// 6.21
		TEST LocalTagPrefix()
		{
778
			PARSE(doc, ex6_21);
beder's avatar
beder committed
779
780
781
782
783
784
785
786
787
788
789
790
			YAML_ASSERT(doc.Tag() == "!my-light");
			YAML_ASSERT(doc.to<std::string>() == "fluorescent");
			
			PARSE_NEXT(doc);
			YAML_ASSERT(doc.Tag() == "!my-light");
			YAML_ASSERT(doc.to<std::string>() == "green");
			return true;
		}
		
		// 6.22
		TEST GlobalTagPrefix()
		{
791
			PARSE(doc, ex6_22);
beder's avatar
beder committed
792
793
794
795
796
797
798
799
800
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc[0].Tag() == "tag:example.com,2000:app/foo");
			YAML_ASSERT(doc[0].to<std::string>() == "bar");
			return true;
		}
		
		// 6.23
		TEST NodeProperties()
		{
801
			PARSE(doc, ex6_23);
beder's avatar
beder committed
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
			YAML_ASSERT(doc.size() == 2);
			for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
				if(it.first().to<std::string>() == "foo") {
					YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str");
					YAML_ASSERT(it.second().Tag() == "tag:yaml.org,2002:str");
					YAML_ASSERT(it.second().to<std::string>() == "bar");
				} else if(it.first().to<std::string>() == "baz") {
					YAML_ASSERT(it.second().to<std::string>() == "foo");
				} else
					return "  unknown key";
			}
			
			return true;
		}
		
		// 6.24
		TEST VerbatimTags()
		{
820
			PARSE(doc, ex6_24);
beder's avatar
beder committed
821
822
823
824
825
826
827
828
829
830
831
832
833
			YAML_ASSERT(doc.size() == 1);
			for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
				YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str");
				YAML_ASSERT(it.first().to<std::string>() == "foo");
				YAML_ASSERT(it.second().Tag() == "!bar");
				YAML_ASSERT(it.second().to<std::string>() == "baz");
			}
			return true;
		}
		
		// 6.25
		TEST InvalidVerbatimTags()
		{
834
			PARSE(doc, ex6_25);
beder's avatar
beder committed
835
836
837
838
839
840
			return "  not implemented yet"; // TODO: check tags (but we probably will say these are valid, I think)
		}
		
		// 6.26
		TEST TagShorthands()
		{
841
			PARSE(doc, ex6_26);
beder's avatar
beder committed
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].Tag() == "!local");
			YAML_ASSERT(doc[0].to<std::string>() == "foo");
			YAML_ASSERT(doc[1].Tag() == "tag:yaml.org,2002:str");
			YAML_ASSERT(doc[1].to<std::string>() == "bar");
			YAML_ASSERT(doc[2].Tag() == "tag:example.com,2000:app/tag%21");
			YAML_ASSERT(doc[2].to<std::string>() == "baz");
			return true;
		}
		
		// 6.27
		TEST InvalidTagShorthands()
		{
			bool threw = false;
			try {
857
				PARSE(doc, ex6_27a);
beder's avatar
beder committed
858
859
860
861
862
863
864
865
866
			} catch(const YAML::ParserException& e) {
				threw = true;
				if(e.msg != YAML::ErrorMsg::TAG_WITH_NO_SUFFIX)
					throw;
			}
			
			if(!threw)
				return "  No exception was thrown for a tag with no suffix";

867
			PARSE(doc, ex6_27b); // TODO: should we reject this one (since !h! is not declared)?
beder's avatar
beder committed
868
869
870
871
872
873
			return "  not implemented yet";
		}
		
		// 6.28
		TEST NonSpecificTags()
		{
874
			PARSE(doc, ex6_28);
beder's avatar
beder committed
875
876
877
878
879
880
881
882
883
884
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].to<std::string>() == "12"); // TODO: check tags. How?
			YAML_ASSERT(doc[1].to<int>() == 12);
			YAML_ASSERT(doc[2].to<std::string>() == "12");
			return true;
		}

		// 6.29
		TEST NodeAnchors()
		{
885
			PARSE(doc, ex6_29);
beder's avatar
beder committed
886
887
888
889
890
891
892
893
894
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["First occurrence"].to<std::string>() == "Value");
			YAML_ASSERT(doc["Second occurrence"].to<std::string>() == "Value");
			return true;
		}
		
		// 7.1
		TEST AliasNodes()
		{
895
			PARSE(doc, ex7_1);
beder's avatar
beder committed
896
897
898
899
900
901
902
903
904
905
906
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc["First occurrence"].to<std::string>() == "Foo");
			YAML_ASSERT(doc["Second occurrence"].to<std::string>() == "Foo");
			YAML_ASSERT(doc["Override anchor"].to<std::string>() == "Bar");
			YAML_ASSERT(doc["Reuse anchor"].to<std::string>() == "Bar");
			return true;
		}
		
		// 7.2
		TEST EmptyNodes()
		{
907
			PARSE(doc, ex7_2);
beder's avatar
beder committed
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
			YAML_ASSERT(doc.size() == 2);
			for(YAML::Iterator it=doc.begin();it!=doc.end();++it) {
				if(it.first().to<std::string>() == "foo") {
					YAML_ASSERT(it.second().Tag() == "tag:yaml.org,2002:str");
					YAML_ASSERT(it.second().to<std::string>() == "");
				} else if(it.first().to<std::string>() == "") {
					YAML_ASSERT(it.first().Tag() == "tag:yaml.org,2002:str");
					YAML_ASSERT(it.second().to<std::string>() == "bar");
				} else
					return "  unexpected key";
			}
			return true;
		}
		
		// 7.3
		TEST CompletelyEmptyNodes()
		{
925
			PARSE(doc, ex7_3);
beder's avatar
beder committed
926
927
928
929
930
931
932
933
934
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(IsNull(doc["foo"]));
			YAML_ASSERT(doc[YAML::Null].to<std::string>() == "bar");
			return true;
		}
		
		// 7.4
		TEST DoubleQuotedImplicitKeys()
		{
935
			PARSE(doc, ex7_4);
beder's avatar
beder committed
936
937
938
939
940
941
942
943
944
945
			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"].to<std::string>() == "value");
			return true;
		}
		
		// 7.5
		TEST DoubleQuotedLineBreaks()
		{
946
			PARSE(doc, ex7_5);
beder's avatar
beder committed
947
948
949
950
951
952
953
			YAML_ASSERT(doc.to<std::string>() == "folded to a space,\nto a line feed, or \t \tnon-content");
			return true;
		}
		
		// 7.6
		TEST DoubleQuotedLines()
		{
954
			PARSE(doc, ex7_6);
beder's avatar
beder committed
955
956
957
958
959
960
961
			YAML_ASSERT(doc.to<std::string>() == " 1st non-empty\n2nd non-empty 3rd non-empty ");
			return true;
		}
		
		// 7.7
		TEST SingleQuotedCharacters()
		{
962
			PARSE(doc, ex7_7);
beder's avatar
beder committed
963
964
965
966
967
968
969
			YAML_ASSERT(doc.to<std::string>() == "here's to \"quotes\"");
			return true;
		}
		
		// 7.8
		TEST SingleQuotedImplicitKeys()
		{
970
			PARSE(doc, ex7_8);
beder's avatar
beder committed
971
972
973
974
975
976
977
978
979
980
			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"].to<std::string>() == "value");
			return true;
		}
		
		// 7.9
		TEST SingleQuotedLines()
		{
981
			PARSE(doc, ex7_9);
beder's avatar
beder committed
982
983
984
985
986
987
988
			YAML_ASSERT(doc.to<std::string>() == " 1st non-empty\n2nd non-empty 3rd non-empty ");
			return true;
		}
		
		// 7.10
		TEST PlainCharacters()
		{
989
			PARSE(doc, ex7_10);
beder's avatar
beder committed
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
			YAML_ASSERT(doc.size() == 6);
			YAML_ASSERT(doc[0].to<std::string>() == "::vector");
			YAML_ASSERT(doc[1].to<std::string>() == ": - ()");
			YAML_ASSERT(doc[2].to<std::string>() == "Up, up, and away!");
			YAML_ASSERT(doc[3].to<int>() == -123);
			YAML_ASSERT(doc[4].to<std::string>() == "http://example.com/foo#bar");
			YAML_ASSERT(doc[5].size() == 5);
			YAML_ASSERT(doc[5][0].to<std::string>() == "::vector");
			YAML_ASSERT(doc[5][1].to<std::string>() == ": - ()");
			YAML_ASSERT(doc[5][2].to<std::string>() == "Up, up, and away!");
			YAML_ASSERT(doc[5][3].to<int>() == -123);
			YAML_ASSERT(doc[5][4].to<std::string>() == "http://example.com/foo#bar");
			return true;
		}
		
		// 7.11
		TEST PlainImplicitKeys()
		{
1008
			PARSE(doc, ex7_11);
beder's avatar
beder committed
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
			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"].to<std::string>() == "value");
			return true;
		}
		
		// 7.12
		TEST PlainLines()
		{
1019
			PARSE(doc, ex7_12);
beder's avatar
beder committed
1020
1021
1022
1023
1024
1025
1026
			YAML_ASSERT(doc.to<std::string>() == "1st non-empty\n2nd non-empty 3rd non-empty");
			return true;
		}
		
		// 7.13
		TEST FlowSequence()
		{
1027
			PARSE(doc, ex7_13);
beder's avatar
beder committed
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0][0].to<std::string>() == "one");
			YAML_ASSERT(doc[0][1].to<std::string>() == "two");
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1][0].to<std::string>() == "three");
			YAML_ASSERT(doc[1][1].to<std::string>() == "four");
			return true;
		}
		
		// 7.14
		TEST FlowSequenceEntries()
		{
1041
			PARSE(doc, ex7_14);
beder's avatar
beder committed
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
			YAML_ASSERT(doc.size() == 5);
			YAML_ASSERT(doc[0].to<std::string>() == "double quoted");
			YAML_ASSERT(doc[1].to<std::string>() == "single quoted");
			YAML_ASSERT(doc[2].to<std::string>() == "plain text");
			YAML_ASSERT(doc[3].size() == 1);
			YAML_ASSERT(doc[3][0].to<std::string>() == "nested");
			YAML_ASSERT(doc[4].size() == 1);
			YAML_ASSERT(doc[4]["single"].to<std::string>() == "pair");
			return true;
		}
		
		// 7.15
		TEST FlowMappings()
		{
1056
			PARSE(doc, ex7_15);
beder's avatar
beder committed
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0]["one"].to<std::string>() == "two");
			YAML_ASSERT(doc[0]["three"].to<std::string>() == "four");
			YAML_ASSERT(doc[1].size() == 2);
			YAML_ASSERT(doc[1]["five"].to<std::string>() == "six");
			YAML_ASSERT(doc[1]["seven"].to<std::string>() == "eight");
			return true;
		}
		
		// 7.16
		TEST FlowMappingEntries()
		{
1070
			PARSE(doc, ex7_16);
beder's avatar
beder committed
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["explicit"].to<std::string>() == "entry");
			YAML_ASSERT(doc["implicit"].to<std::string>() == "entry");
			YAML_ASSERT(IsNull(doc[YAML::Null]));
			return true;
		}
		
		// 7.17
		TEST FlowMappingSeparateValues()
		{
1081
			PARSE(doc, ex7_17);
beder's avatar
beder committed
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc["unquoted"].to<std::string>() == "separate");
			YAML_ASSERT(IsNull(doc["http://foo.com"]));
			YAML_ASSERT(IsNull(doc["omitted value"]));
			YAML_ASSERT(doc[YAML::Null].to<std::string>() == "omitted key");
			return true;
		}
		
		// 7.18
		TEST FlowMappingAdjacentValues()
		{
1093
			PARSE(doc, ex7_18);
beder's avatar
beder committed
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["adjacent"].to<std::string>() == "value");
			YAML_ASSERT(doc["readable"].to<std::string>() == "value");
			YAML_ASSERT(IsNull(doc["empty"]));
			return true;
		}
		
		// 7.19
		TEST SinglePairFlowMappings()
		{
1104
			PARSE(doc, ex7_19);
beder's avatar
beder committed
1105
1106
1107
1108
1109
1110
1111
1112
1113
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["foo"].to<std::string>() == "bar");
			return true;
		}
		
		// 7.20
		TEST SinglePairExplicitEntry()
		{
1114
			PARSE(doc, ex7_20);
beder's avatar
beder committed
1115
1116
1117
1118
1119
1120
1121
1122
1123
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["foo bar"].to<std::string>() == "baz");
			return true;
		}
		
		// 7.21
		TEST SinglePairImplicitEntries()
		{
1124
			PARSE(doc, ex7_21);
beder's avatar
beder committed
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0][0].size() == 1);
			YAML_ASSERT(doc[0][0]["YAML"].to<std::string>() == "separate");
			YAML_ASSERT(doc[1].size() == 1);
			YAML_ASSERT(doc[1][0].size() == 1);
			YAML_ASSERT(doc[1][0][YAML::Null].to<std::string>() == "empty key entry");
			YAML_ASSERT(doc[2].size() == 1);
			YAML_ASSERT(doc[2][0].size() == 1);
			StringMap key;
			key._["JSON"] = "like";
			YAML_ASSERT(doc[2][0][key].to<std::string>() == "adjacent");
			return true;
		}
		
		// 7.22
		TEST InvalidImplicitKeys()
		{
			try {
1144
				PARSE(doc, ex7_22);
beder's avatar
beder committed
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
			} catch(const YAML::Exception& e) {
				if(e.msg == YAML::ErrorMsg::END_OF_SEQ_FLOW)
					return true;
				
				throw;
			}
			return "  no exception thrown";
		}
		
		// 7.23
		TEST FlowContent()
		{
1157
			PARSE(doc, ex7_23);
beder's avatar
beder committed
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
			YAML_ASSERT(doc.size() == 5);
			YAML_ASSERT(doc[0].size() == 2);
			YAML_ASSERT(doc[0][0].to<std::string>() == "a");
			YAML_ASSERT(doc[0][1].to<std::string>() == "b");
			YAML_ASSERT(doc[1].size() == 1);
			YAML_ASSERT(doc[1]["a"].to<std::string>() == "b");
			YAML_ASSERT(doc[2].to<std::string>() == "a");
			YAML_ASSERT(doc[3].to<char>() == 'b');
			YAML_ASSERT(doc[4].to<std::string>() == "c");
			return true;
		}
		
		// 7.24
		TEST FlowNodes()
		{
1173
			PARSE(doc, ex7_24);
beder's avatar
beder committed
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
			YAML_ASSERT(doc.size() == 5);
			YAML_ASSERT(doc[0].Tag() == "tag:yaml.org,2002:str");
			YAML_ASSERT(doc[0].to<std::string>() == "a");
			YAML_ASSERT(doc[1].to<char>() == 'b');
			YAML_ASSERT(doc[2].to<std::string>() == "c");
			YAML_ASSERT(doc[3].to<std::string>() == "c");
			YAML_ASSERT(doc[4].Tag() == "tag:yaml.org,2002:str");
			YAML_ASSERT(doc[4].to<std::string>() == "");
			return true;
		}
		
		// 8.1
		TEST BlockScalarHeader()
		{
1188
			PARSE(doc, ex8_1);
beder's avatar
beder committed
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc[0].to<std::string>() == "literal\n");
			YAML_ASSERT(doc[1].to<std::string>() == " folded\n");
			YAML_ASSERT(doc[2].to<std::string>() == "keep\n\n");
			YAML_ASSERT(doc[3].to<std::string>() == " strip");
			return true;
		}
		
		// 8.2
		TEST BlockIndentationHeader()
		{
1200
			PARSE(doc, ex8_2);
beder's avatar
beder committed
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(doc[0].to<std::string>() == "detected\n");
			YAML_ASSERT(doc[1].to<std::string>() == "\n\n# detected\n");
			YAML_ASSERT(doc[2].to<std::string>() == " explicit\n");
			YAML_ASSERT(doc[3].to<std::string>() == "\t\ndetected\n");
			return true;
		}
		
		// 8.3
		TEST InvalidBlockScalarIndentationIndicators()
		{
			{
				bool threw = false;
				try {
1215
					PARSE(doc, ex8_3a);
beder's avatar
beder committed
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
				} 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 {
1230
					PARSE(doc, ex8_3b);
beder's avatar
beder committed
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
				} 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 {
1245
					PARSE(doc, ex8_3c);
beder's avatar
beder committed
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
				} 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;
		}
		
		// 8.4
		TEST ChompingFinalLineBreak()
		{
1263
			PARSE(doc, ex8_4);
beder's avatar
beder committed
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["strip"].to<std::string>() == "text");
			YAML_ASSERT(doc["clip"].to<std::string>() == "text\n");
			YAML_ASSERT(doc["keep"].to<std::string>() == "text\n");
			return true;
		}
		
		// 8.5
		TEST ChompingTrailingLines()
		{
1274
			PARSE(doc, ex8_5);
beder's avatar
beder committed
1275
1276
1277
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["strip"].to<std::string>() == "# text");
			YAML_ASSERT(doc["clip"].to<std::string>() == "# text\n");
beder's avatar
beder committed
1278
			YAML_ASSERT(doc["keep"].to<std::string>() == "# text\n"); // Note: I believe this is a bug in the YAML spec - it should be "# text\n\n"
beder's avatar
beder committed
1279
1280
1281
1282
1283
1284
			return true;
		}
		
		// 8.6
		TEST EmptyScalarChomping()
		{
1285
			PARSE(doc, ex8_6);
beder's avatar
beder committed
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["strip"].to<std::string>() == "");
			YAML_ASSERT(doc["clip"].to<std::string>() == "");
			YAML_ASSERT(doc["keep"].to<std::string>() == "\n");
			return true;
		}
		
		// 8.7
		TEST LiteralScalar()
		{
1296
			PARSE(doc, ex8_7);
beder's avatar
beder committed
1297
1298
1299
1300
1301
1302
1303
			YAML_ASSERT(doc.to<std::string>() == "literal\n\ttext\n");
			return true;
		}
		
		// 8.8
		TEST LiteralContent()
		{
1304
			PARSE(doc, ex8_8);
beder's avatar
beder committed
1305
1306
1307
1308
1309
1310
1311
			YAML_ASSERT(doc.to<std::string>() == "\n\nliteral\n \n\ntext\n");
			return true;
		}
		
		// 8.9
		TEST FoldedScalar()
		{
1312
			PARSE(doc, ex8_9);
beder's avatar
beder committed
1313
1314
1315
1316
1317
1318
1319
			YAML_ASSERT(doc.to<std::string>() == "folded text\n");
			return true;
		}
		
		// 8.10
		TEST FoldedLines()
		{
1320
			PARSE(doc, ex8_10);
beder's avatar
beder committed
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
			YAML_ASSERT(doc.to<std::string>() == "\nfolded line\nnext line\n  * bullet\n\n  * list\n  * lines\n\nlast line\n");
			return true;
		}
		
		// 8.11
		TEST MoreIndentedLines()
		{
			return true; // same as 8.10
		}
		
		// 8.12
		TEST EmptySeparationLines()
		{
			return true; // same as 8.10
		}
		
		// 8.13
		TEST FinalEmptyLines()
		{
			return true; // same as 8.10
		}
		
		// 8.14
		TEST BlockSequence()
		{
1346
			PARSE(doc, ex8_14);
beder's avatar
beder committed
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["block sequence"].size() == 2);
			YAML_ASSERT(doc["block sequence"][0].to<std::string>() == "one");
			YAML_ASSERT(doc["block sequence"][1].size() == 1);
			YAML_ASSERT(doc["block sequence"][1]["two"].to<std::string>() == "three");
			return true;
		}
		
		// 8.15
		TEST BlockSequenceEntryTypes()
		{
1358
			PARSE(doc, ex8_15);
beder's avatar
beder committed
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
			YAML_ASSERT(doc.size() == 4);
			YAML_ASSERT(YAML::IsNull(doc[0]));
			YAML_ASSERT(doc[1].to<std::string>() == "block node\n");
			YAML_ASSERT(doc[2].size() == 2);
			YAML_ASSERT(doc[2][0].to<std::string>() == "one");
			YAML_ASSERT(doc[2][1].to<std::string>() == "two");
			YAML_ASSERT(doc[3].size() == 1);
			YAML_ASSERT(doc[3]["one"].to<std::string>() == "two");
			return true;
		}
		
		// 8.16
		TEST BlockMappings()
		{
1373
			PARSE(doc, ex8_16);
beder's avatar
beder committed
1374
1375
1376
1377
1378
1379
1380
1381
1382
			YAML_ASSERT(doc.size() == 1);
			YAML_ASSERT(doc["block mapping"].size() == 1);
			YAML_ASSERT(doc["block mapping"]["key"].to<std::string>() == "value");
			return true;
		}
		
		// 8.17
		TEST ExplicitBlockMappingEntries()
		{
1383
			PARSE(doc, ex8_17);
beder's avatar
beder committed
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(IsNull(doc["explicit key"]));
			YAML_ASSERT(doc["block key\n"].size() == 2);
			YAML_ASSERT(doc["block key\n"][0].to<std::string>() == "one");
			YAML_ASSERT(doc["block key\n"][1].to<std::string>() == "two");
			return true;
		}
		
		// 8.18
		TEST ImplicitBlockMappingEntries()
		{
1395
			PARSE(doc, ex8_18);
beder's avatar
beder committed
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc["plain key"].to<std::string>() == "in-line value");
			YAML_ASSERT(IsNull(doc[YAML::Null]));
			YAML_ASSERT(doc["quoted key"].size() == 1);
			YAML_ASSERT(doc["quoted key"][0].to<std::string>() == "entry");
			return true;
		}
		
		// 8.19
		TEST CompactBlockMappings()
		{
1407
			PARSE(doc, ex8_19);
beder's avatar
beder committed
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc[0].size() == 1);
			YAML_ASSERT(doc[0]["sun"].to<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"].to<std::string>() == "white");
			return true;
		}
		
		// 8.20
		TEST BlockNodeTypes()
		{
1422
			PARSE(doc, ex8_20);
beder's avatar
beder committed
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
			YAML_ASSERT(doc.size() == 3);
			YAML_ASSERT(doc[0].to<std::string>() == "flow in block");
			YAML_ASSERT(doc[1].to<std::string>() == "Block scalar\n");
			YAML_ASSERT(doc[2].size() == 1);
			YAML_ASSERT(doc[2]["foo"].to<std::string>() == "bar");
			return true;
		}
		
		// 8.21
		TEST BlockScalarNodes()
		{
1434
			PARSE(doc, ex8_21);
beder's avatar
beder committed
1435
			YAML_ASSERT(doc.size() == 2);
beder's avatar
beder committed
1436
			YAML_ASSERT(doc["literal"].to<std::string>() == "value"); // Note: I believe this is a bug in the YAML spec - it should be "value\n"
beder's avatar
beder committed
1437
1438
1439
1440
1441
1442
1443
1444
			YAML_ASSERT(doc["folded"].to<std::string>() == "value");
			YAML_ASSERT(doc["folded"].Tag() == "!foo");
			return true;
		}
		
		// 8.22
		TEST BlockCollectionNodes()
		{
1445
			PARSE(doc, ex8_22);
beder's avatar
beder committed
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
			YAML_ASSERT(doc.size() == 2);
			YAML_ASSERT(doc["sequence"].size() == 2);
			YAML_ASSERT(doc["sequence"][0].to<std::string>() == "entry");
			YAML_ASSERT(doc["sequence"][1].size() == 1);
			YAML_ASSERT(doc["sequence"][1][0].to<std::string>() == "nested");
			YAML_ASSERT(doc["mapping"].size() == 1);
			YAML_ASSERT(doc["mapping"]["foo"].to<std::string>() == "bar");
			return true;
		}
	}
}