emittertests.cpp 41.5 KB
Newer Older
1
#include "tests.h"
2
#include "handlermacros.h"
3
#include "yaml-cpp/yaml.h"
4
#include "yaml-cpp/eventhandler.h"
5
#include <iostream>
6
7
8
9
10
11
12
13
14

namespace Test
{
	namespace Emitter {
		////////////////////////////////////////////////////////////////////////////////////////////////////////
		// correct emitting

		void SimpleScalar(YAML::Emitter& out, std::string& desiredOutput) {
			out << "Hello, World!";
15
			desiredOutput = "Hello, World!";
16
17
18
19
20
21
22
23
24
		}
		
		void SimpleSeq(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::BeginSeq;
			out << "eggs";
			out << "bread";
			out << "milk";
			out << YAML::EndSeq;

25
			desiredOutput = "- eggs\n- bread\n- milk";
26
27
28
29
30
31
32
33
34
35
		}
		
		void SimpleFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::Flow;
			out << YAML::BeginSeq;
			out << "Larry";
			out << "Curly";
			out << "Moe";
			out << YAML::EndSeq;
			
36
			desiredOutput = "[Larry, Curly, Moe]";
37
38
39
40
41
42
43
		}
		
		void EmptyFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::Flow;
			out << YAML::BeginSeq;
			out << YAML::EndSeq;
			
44
			desiredOutput = "[]";
45
46
47
48
49
50
51
52
		}
		
		void NestedBlockSeq(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::BeginSeq;
			out << "item 1";
			out << YAML::BeginSeq << "subitem 1" << "subitem 2" << YAML::EndSeq;
			out << YAML::EndSeq;
			
53
			desiredOutput = "- item 1\n-\n  - subitem 1\n  - subitem 2";
54
55
56
57
58
59
60
61
		}
		
		void NestedFlowSeq(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::BeginSeq;
			out << "one";
			out << YAML::Flow << YAML::BeginSeq << "two" << "three" << YAML::EndSeq;
			out << YAML::EndSeq;
			
62
			desiredOutput = "- one\n- [two, three]";
63
64
65
66
67
68
69
70
71
72
		}

		void SimpleMap(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::BeginMap;
			out << YAML::Key << "name";
			out << YAML::Value << "Ryan Braun";
			out << YAML::Key << "position";
			out << YAML::Value << "3B";
			out << YAML::EndMap;

73
			desiredOutput = "name: Ryan Braun\nposition: 3B";
74
75
76
77
78
79
80
81
82
83
84
		}
		
		void SimpleFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::Flow;
			out << YAML::BeginMap;
			out << YAML::Key << "shape";
			out << YAML::Value << "square";
			out << YAML::Key << "color";
			out << YAML::Value << "blue";
			out << YAML::EndMap;
			
85
			desiredOutput = "{shape: square, color: blue}";
86
87
88
89
90
91
92
93
94
95
		}
		
		void MapAndList(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::BeginMap;
			out << YAML::Key << "name";
			out << YAML::Value << "Barack Obama";
			out << YAML::Key << "children";
			out << YAML::Value << YAML::BeginSeq << "Sasha" << "Malia" << YAML::EndSeq;
			out << YAML::EndMap;

96
			desiredOutput = "name: Barack Obama\nchildren:\n  - Sasha\n  - Malia";
97
98
99
100
101
102
103
104
105
106
107
108
		}
		
		void ListAndMap(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::BeginSeq;
			out << "item 1";
			out << YAML::BeginMap;
			out << YAML::Key << "pens" << YAML::Value << 8;
			out << YAML::Key << "pencils" << YAML::Value << 14;
			out << YAML::EndMap;
			out << "item 2";
			out << YAML::EndSeq;
			
109
			desiredOutput = "- item 1\n- pens: 8\n  pencils: 14\n- item 2";
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
		}

		void NestedBlockMap(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::BeginMap;
			out << YAML::Key << "name";
			out << YAML::Value << "Fred";
			out << YAML::Key << "grades";
			out << YAML::Value;
			out << YAML::BeginMap;
			out << YAML::Key << "algebra" << YAML::Value << "A";
			out << YAML::Key << "physics" << YAML::Value << "C+";
			out << YAML::Key << "literature" << YAML::Value << "B";
			out << YAML::EndMap;
			out << YAML::EndMap;
			
125
			desiredOutput = "name: Fred\ngrades:\n  algebra: A\n  physics: C+\n  literature: B";
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
		}

		void NestedFlowMap(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::Flow;
			out << YAML::BeginMap;
			out << YAML::Key << "name";
			out << YAML::Value << "Fred";
			out << YAML::Key << "grades";
			out << YAML::Value;
			out << YAML::BeginMap;
			out << YAML::Key << "algebra" << YAML::Value << "A";
			out << YAML::Key << "physics" << YAML::Value << "C+";
			out << YAML::Key << "literature" << YAML::Value << "B";
			out << YAML::EndMap;
			out << YAML::EndMap;
			
142
			desiredOutput = "{name: Fred, grades: {algebra: A, physics: C+, literature: B}}";
143
144
145
146
147
148
149
150
151
152
153
154
		}
		
		void MapListMix(YAML::Emitter& out, std::string& desiredOutput) {
			out << YAML::BeginMap;
			out << YAML::Key << "name";
			out << YAML::Value << "Bob";
			out << YAML::Key << "position";
			out << YAML::Value;
			out << YAML::Flow << YAML::BeginSeq << 2 << 4 << YAML::EndSeq;
			out << YAML::Key << "invincible" << YAML::Value << YAML::OnOffBool << false;
			out << YAML::EndMap;
			
155
			desiredOutput = "name: Bob\nposition: [2, 4]\ninvincible: off";
156
157
158
159
160
161
162
163
164
165
166
167
		}

		void SimpleLongKey(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::LongKey;
			out << YAML::BeginMap;
			out << YAML::Key << "height";
			out << YAML::Value << "5'9\"";
			out << YAML::Key << "weight";
			out << YAML::Value << 145;
			out << YAML::EndMap;
			
168
			desiredOutput = "? height\n: 5'9\"\n? weight\n: 145";
169
170
171
172
173
174
175
176
177
178
179
180
181
		}
		
		void SingleLongKey(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << "age";
			out << YAML::Value << "24";
			out << YAML::LongKey << YAML::Key << "height";
			out << YAML::Value << "5'9\"";
			out << YAML::Key << "weight";
			out << YAML::Value << 145;
			out << YAML::EndMap;
			
182
			desiredOutput = "age: 24\n? height\n: 5'9\"\nweight: 145";
183
184
185
186
187
188
189
190
191
192
193
194
		}
		
		void ComplexLongKey(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::LongKey;
			out << YAML::BeginMap;
			out << YAML::Key << YAML::BeginSeq << 1 << 3 << YAML::EndSeq;
			out << YAML::Value << "monster";
			out << YAML::Key << YAML::Flow << YAML::BeginSeq << 2 << 0 << YAML::EndSeq;
			out << YAML::Value << "demon";
			out << YAML::EndMap;
			
195
			desiredOutput = "? - 1\n  - 3\n: monster\n? [2, 0]\n: demon";
196
197
198
199
200
201
202
203
204
205
206
207
208
		}

		void AutoLongKey(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << YAML::BeginSeq << 1 << 3 << YAML::EndSeq;
			out << YAML::Value << "monster";
			out << YAML::Key << YAML::Flow << YAML::BeginSeq << 2 << 0 << YAML::EndSeq;
			out << YAML::Value << "demon";
			out << YAML::Key << "the origin";
			out << YAML::Value << "angel";
			out << YAML::EndMap;
			
Jesse Beder's avatar
Jesse Beder committed
209
			desiredOutput = "? - 1\n  - 3\n: monster\n[2, 0]: demon\nthe origin: angel";
210
211
212
213
214
215
216
217
218
219
220
221
222
		}
		
		void ScalarFormat(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << "simple scalar";
			out << YAML::SingleQuoted << "explicit single-quoted scalar";
			out << YAML::DoubleQuoted << "explicit double-quoted scalar";
			out << "auto-detected\ndouble-quoted scalar";
			out << "a non-\"auto-detected\" double-quoted scalar";
			out << YAML::Literal << "literal scalar\nthat may span\nmany, many\nlines and have \"whatever\" crazy\tsymbols that we like";
			out << YAML::EndSeq;
			
223
			desiredOutput = "- simple scalar\n- 'explicit single-quoted scalar'\n- \"explicit double-quoted scalar\"\n- \"auto-detected\\ndouble-quoted scalar\"\n- a non-\"auto-detected\" double-quoted scalar\n- |\n  literal scalar\n  that may span\n  many, many\n  lines and have \"whatever\" crazy\tsymbols that we like";
224
225
226
227
228
229
230
231
232
		}

		void AutoLongKeyScalar(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << YAML::Literal << "multi-line\nscalar";
			out << YAML::Value << "and its value";
			out << YAML::EndMap;
			
233
			desiredOutput = "? |\n  multi-line\n  scalar\n: and its value";
234
235
236
237
238
239
240
241
242
243
244
245
		}
		
		void LongKeyFlowMap(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow;
			out << YAML::BeginMap;
			out << YAML::Key << "simple key";
			out << YAML::Value << "and value";
			out << YAML::LongKey << YAML::Key << "long key";
			out << YAML::Value << "and its value";
			out << YAML::EndMap;
			
246
			desiredOutput = "{simple key: and value, ? long key: and its value}";
247
248
249
250
251
252
253
254
255
256
257
258
259
260
		}

		void BlockMapAsKey(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key;
			out << YAML::BeginMap;
			out << YAML::Key << "key" << YAML::Value << "value";
			out << YAML::Key << "next key" << YAML::Value << "next value";
			out << YAML::EndMap;
			out << YAML::Value;
			out << "total value";
			out << YAML::EndMap;
			
261
			desiredOutput = "? key: value\n  next key: next value\n: total value";
262
263
264
265
266
267
268
269
270
271
272
273
274
		}
		
		void AliasAndAnchor(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << YAML::Anchor("fred");
			out << YAML::BeginMap;
			out << YAML::Key << "name" << YAML::Value << "Fred";
			out << YAML::Key << "age" << YAML::Value << 42;
			out << YAML::EndMap;
			out << YAML::Alias("fred");
			out << YAML::EndSeq;
			
275
			desiredOutput = "- &fred\n  name: Fred\n  age: 42\n- *fred";
276
277
		}

278
279
280
281
282
283
284
		void AliasAndAnchorWithNull(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << YAML::Anchor("fred") << YAML::Null;
			out << YAML::Alias("fred");
			out << YAML::EndSeq;
			
285
			desiredOutput = "- &fred ~\n- *fred";
286
287
		}
		
288
289
290
291
292
293
294
295
296
297
298
299
300
301
		void AliasAndAnchorInFlow(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginSeq;
			out << YAML::Anchor("fred");
			out << YAML::BeginMap;
			out << YAML::Key << "name" << YAML::Value << "Fred";
			out << YAML::Key << "age" << YAML::Value << 42;
			out << YAML::EndMap;
			out << YAML::Alias("fred");
			out << YAML::EndSeq;
			
			desiredOutput = "[&fred {name: Fred, age: 42}, *fred]";
		}
		
302
303
304
305
		void SimpleVerbatimTag(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::VerbatimTag("!foo") << "bar";
			
306
			desiredOutput = "!<!foo> bar";
307
308
309
310
311
312
313
314
315
		}

		void VerbatimTagInBlockSeq(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << YAML::VerbatimTag("!foo") << "bar";
			out << "baz";
			out << YAML::EndSeq;
			
316
			desiredOutput = "- !<!foo> bar\n- baz";
317
318
319
320
321
322
323
324
325
		}

		void VerbatimTagInFlowSeq(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginSeq;
			out << YAML::VerbatimTag("!foo") << "bar";
			out << "baz";
			out << YAML::EndSeq;
			
326
			desiredOutput = "[!<!foo> bar, baz]";
327
328
329
330
331
332
333
334
335
		}

		void VerbatimTagInFlowSeqWithNull(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginSeq;
			out << YAML::VerbatimTag("!foo") << YAML::Null;
			out << "baz";
			out << YAML::EndSeq;
			
336
			desiredOutput = "[!<!foo> ~, baz]";
337
338
339
340
341
342
343
344
345
		}

		void VerbatimTagInBlockMap(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << YAML::VerbatimTag("!foo") << "bar";
			out << YAML::Value << YAML::VerbatimTag("!waz") << "baz";
			out << YAML::EndMap;
			
346
			desiredOutput = "!<!foo> bar: !<!waz> baz";
347
348
349
350
351
352
353
354
355
		}

		void VerbatimTagInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginMap;
			out << YAML::Key << YAML::VerbatimTag("!foo") << "bar";
			out << YAML::Value << "baz";
			out << YAML::EndMap;
			
356
			desiredOutput = "{!<!foo> bar: baz}";
357
358
359
360
361
362
363
364
365
		}

		void VerbatimTagInFlowMapWithNull(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginMap;
			out << YAML::Key << YAML::VerbatimTag("!foo") << YAML::Null;
			out << YAML::Value << "baz";
			out << YAML::EndMap;
			
366
			desiredOutput = "{!<!foo> ~: baz}";
367
368
369
370
371
372
		}
		
		void VerbatimTagWithEmptySeq(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::VerbatimTag("!foo") << YAML::BeginSeq << YAML::EndSeq;
			
373
			desiredOutput = "!<!foo>\n[]";
374
375
376
377
378
379
		}

		void VerbatimTagWithEmptyMap(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::VerbatimTag("!bar") << YAML::BeginMap << YAML::EndMap;
			
380
			desiredOutput = "!<!bar>\n{}";
381
382
383
384
385
386
387
388
389
		}

		void VerbatimTagWithEmptySeqAndMap(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << YAML::VerbatimTag("!foo") << YAML::BeginSeq << YAML::EndSeq;
			out << YAML::VerbatimTag("!bar") << YAML::BeginMap << YAML::EndMap;
			out << YAML::EndSeq;
			
390
			desiredOutput = "- !<!foo>\n  []\n- !<!bar>\n  {}";
391
392
		}

393
394
395
396
397
398
399
400
		void ByKindTagWithScalar(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << YAML::DoubleQuoted << "12";
			out << "12";
			out << YAML::TagByKind << "12";
			out << YAML::EndSeq;
			
401
			desiredOutput = "- \"12\"\n- 12\n- ! 12";
402
403
404
405
406
407
		}

		void LocalTagWithScalar(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::LocalTag("foo") << "bar";
			
408
			desiredOutput = "!foo bar";
409
410
411
412
413
414
415
416
417
		}

		void BadLocalTag(YAML::Emitter& out, std::string& desiredError)
		{
			out << YAML::LocalTag("e!far") << "bar";
			
			desiredError = "invalid tag";
		}

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
		void ComplexDoc(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << "receipt";
			out << YAML::Value << "Oz-Ware Purchase Invoice";
			out << YAML::Key << "date";
			out << YAML::Value << "2007-08-06";
			out << YAML::Key << "customer";
			out << YAML::Value;
			out << YAML::BeginMap;
			out << YAML::Key << "given";
			out << YAML::Value << "Dorothy";
			out << YAML::Key << "family";
			out << YAML::Value << "Gale";
			out << YAML::EndMap;
			out << YAML::Key << "items";
			out << YAML::Value;
			out << YAML::BeginSeq;
			out << YAML::BeginMap;
			out << YAML::Key << "part_no";
			out << YAML::Value << "A4786";
			out << YAML::Key << "descrip";
			out << YAML::Value << "Water Bucket (Filled)";
			out << YAML::Key << "price";
			out << YAML::Value << 1.47;
			out << YAML::Key << "quantity";
			out << YAML::Value << 4;
			out << YAML::EndMap;
			out << YAML::BeginMap;
			out << YAML::Key << "part_no";
			out << YAML::Value << "E1628";
			out << YAML::Key << "descrip";
			out << YAML::Value << "High Heeled \"Ruby\" Slippers";
			out << YAML::Key << "price";
			out << YAML::Value << 100.27;
			out << YAML::Key << "quantity";
			out << YAML::Value << 1;
			out << YAML::EndMap;
			out << YAML::EndSeq;
			out << YAML::Key << "bill-to";
			out << YAML::Value << YAML::Anchor("id001");
			out << YAML::BeginMap;
			out << YAML::Key << "street";
			out << YAML::Value << YAML::Literal << "123 Tornado Alley\nSuite 16";
			out << YAML::Key << "city";
			out << YAML::Value << "East Westville";
			out << YAML::Key << "state";
			out << YAML::Value << "KS";
			out << YAML::EndMap;
			out << YAML::Key << "ship-to";
			out << YAML::Value << YAML::Alias("id001");
			out << YAML::EndMap;
			
471
			desiredOutput = "receipt: Oz-Ware Purchase Invoice\ndate: 2007-08-06\ncustomer:\n  given: Dorothy\n  family: Gale\nitems:\n  - part_no: A4786\n    descrip: Water Bucket (Filled)\n    price: 1.47\n    quantity: 4\n  - part_no: E1628\n    descrip: High Heeled \"Ruby\" Slippers\n    price: 100.27\n    quantity: 1\nbill-to: &id001\n  street: |\n    123 Tornado Alley\n    Suite 16\n  city: East Westville\n  state: KS\nship-to: *id001";
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
		}

		void STLContainers(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			std::vector <int> primes;
			primes.push_back(2);
			primes.push_back(3);
			primes.push_back(5);
			primes.push_back(7);
			primes.push_back(11);
			primes.push_back(13);
			out << YAML::Flow << primes;
			std::map <std::string, int> ages;
			ages["Daniel"] = 26;
			ages["Jesse"] = 24;
			out << ages;
			out << YAML::EndSeq;
			
491
			desiredOutput = "- [2, 3, 5, 7, 11, 13]\n- Daniel: 26\n  Jesse: 24";
492
493
494
495
496
497
498
499
500
		}

		void SimpleComment(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << "method";
			out << YAML::Value << "least squares" << YAML::Comment("should we change this method?");
			out << YAML::EndMap;
			
501
			desiredOutput = "method: least squares  # should we change this method?";
502
503
504
505
506
507
508
509
510
		}

		void MultiLineComment(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << "item 1" << YAML::Comment("really really long\ncomment that couldn't possibly\nfit on one line");
			out << "item 2";
			out << YAML::EndSeq;
			
511
			desiredOutput = "- item 1  # really really long\n          # comment that couldn't possibly\n          # fit on one line\n- item 2";
512
513
514
515
516
517
518
519
520
		}

		void ComplexComments(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::LongKey << YAML::Key << "long key" << YAML::Comment("long key");
			out << YAML::Value << "value";
			out << YAML::EndMap;
			
521
			desiredOutput = "? long key  # long key\n: value";
522
		}
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
		
		void InitialComment(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Comment("A comment describing the purpose of the file.");
			out << YAML::BeginMap << YAML::Key << "key" << YAML::Value << "value" << YAML::EndMap;
			
			desiredOutput = "# A comment describing the purpose of the file.\nkey: value";
		}

		void InitialCommentWithDocIndicator(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginDoc << YAML::Comment("A comment describing the purpose of the file.");
			out << YAML::BeginMap << YAML::Key << "key" << YAML::Value << "value" << YAML::EndMap;
			
			desiredOutput = "---\n# A comment describing the purpose of the file.\nkey: value";
		}

		void CommentInFlowSeq(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginSeq << "foo" << YAML::Comment("foo!") << "bar" << YAML::EndSeq;
			
544
			desiredOutput = "[foo,  # foo!\nbar]";
545
546
547
548
549
		}

		void CommentInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginMap;
550
			out << YAML::Key << "foo" << YAML::Value << "foo value";
551
			out << YAML::Key << "bar" << YAML::Value << "bar value" << YAML::Comment("bar!");
552
			out << YAML::Key << "baz" << YAML::Value << "baz value" << YAML::Comment("baz!");
553
554
			out << YAML::EndMap;
			
Jesse Beder's avatar
Jesse Beder committed
555
			desiredOutput = "{foo: foo value, bar: bar value,  # bar!\nbaz: baz value,  # baz!\n}";
556
		}
557
558
559
560
561
562
563
564
565
566
567

		void Indentation(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Indent(4);
			out << YAML::BeginSeq;
			out << YAML::BeginMap;
			out << YAML::Key << "key 1" << YAML::Value << "value 1";
			out << YAML::Key << "key 2" << YAML::Value << YAML::BeginSeq << "a" << "b" << "c" << YAML::EndSeq;
			out << YAML::EndMap;
			out << YAML::EndSeq;
			
568
			desiredOutput = "-   key 1: value 1\n    key 2:\n        -   a\n        -   b\n        -   c";
569
570
571
572
573
574
575
576
577
578
579
580
581
582
		}

		void SimpleGlobalSettings(YAML::Emitter& out, std::string& desiredOutput)
		{
			out.SetIndent(4);
			out.SetMapFormat(YAML::LongKey);

			out << YAML::BeginSeq;
			out << YAML::BeginMap;
			out << YAML::Key << "key 1" << YAML::Value << "value 1";
			out << YAML::Key << "key 2" << YAML::Value << YAML::Flow << YAML::BeginSeq << "a" << "b" << "c" << YAML::EndSeq;
			out << YAML::EndMap;
			out << YAML::EndSeq;
			
583
			desiredOutput = "-   ? key 1\n    : value 1\n    ? key 2\n    : [a, b, c]";
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
		}
		
		void ComplexGlobalSettings(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << YAML::Block;
			out << YAML::BeginMap;
			out << YAML::Key << "key 1" << YAML::Value << "value 1";
			out << YAML::Key << "key 2" << YAML::Value;
			out.SetSeqFormat(YAML::Flow);
			out << YAML::BeginSeq << "a" << "b" << "c" << YAML::EndSeq;
			out << YAML::EndMap;
			out << YAML::BeginMap;
			out << YAML::Key << YAML::BeginSeq << 1 << 2 << YAML::EndSeq;
			out << YAML::Value << YAML::BeginMap << YAML::Key << "a" << YAML::Value << "b" << YAML::EndMap;
			out << YAML::EndMap;
			out << YAML::EndSeq;
			
Jesse Beder's avatar
Jesse Beder committed
602
			desiredOutput = "- key 1: value 1\n  key 2: [a, b, c]\n- [1, 2]:\n    a: b";
603
604
605
606
607
608
609
610
611
612
613
614
		}

		void Null(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << YAML::Null;
			out << YAML::BeginMap;
			out << YAML::Key << "null value" << YAML::Value << YAML::Null;
			out << YAML::Key << YAML::Null << YAML::Value << "null key";
			out << YAML::EndMap;
			out << YAML::EndSeq;
			
615
			desiredOutput = "- ~\n- null value: ~\n  ~: null key";
616
		}
Jesse Beder's avatar
Jesse Beder committed
617
		
618
		void EscapedUnicode(YAML::Emitter& out, std::string& desiredOutput)
Jesse Beder's avatar
Jesse Beder committed
619
		{
620
			out << YAML::EscapeNonAscii << "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
Jesse Beder's avatar
Jesse Beder committed
621
			
622
			desiredOutput = "\"$ \\xa2 \\u20ac \\U00024b62\"";
Jesse Beder's avatar
Jesse Beder committed
623
		}
624
625
626
627
		
		void Unicode(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
628
			desiredOutput = "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
629
630
631
632
633
		}
		
		void DoubleQuotedUnicode(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::DoubleQuoted << "\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2";
634
			desiredOutput = "\"\x24 \xC2\xA2 \xE2\x82\xAC \xF0\xA4\xAD\xA2\"";
635
636
		}
		
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
		struct Foo {
			Foo(): x(0) {}
			Foo(int x_, const std::string& bar_): x(x_), bar(bar_) {}
			
			int x;
			std::string bar;
		};
		
		YAML::Emitter& operator << (YAML::Emitter& out, const Foo& foo) {
			out << YAML::BeginMap;
			out << YAML::Key << "x" << YAML::Value << foo.x;
			out << YAML::Key << "bar" << YAML::Value << foo.bar;
			out << YAML::EndMap;
			return out;
		}
		
		void UserType(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << Foo(5, "hello");
			out << Foo(3, "goodbye");
			out << YAML::EndSeq;
			
660
			desiredOutput = "- x: 5\n  bar: hello\n- x: 3\n  bar: goodbye";
661
662
663
664
665
666
667
668
669
		}
		
		void UserTypeInContainer(YAML::Emitter& out, std::string& desiredOutput)
		{
			std::vector<Foo> fv;
			fv.push_back(Foo(5, "hello"));
			fv.push_back(Foo(3, "goodbye"));
			out << fv;
			
670
			desiredOutput = "- x: 5\n  bar: hello\n- x: 3\n  bar: goodbye";
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
		}
		
		template <typename T>
		YAML::Emitter& operator << (YAML::Emitter& out, const T *v) {
			if(v)
				out << *v;
			else
				out << YAML::Null;
			return out;
		}
		
		void PointerToInt(YAML::Emitter& out, std::string& desiredOutput)
		{
			int foo = 5;
			int *bar = &foo;
			int *baz = 0;
			out << YAML::BeginSeq;
			out << bar << baz;
			out << YAML::EndSeq;
			
691
			desiredOutput = "- 5\n- ~";
692
693
694
695
696
697
698
699
700
701
702
		}

		void PointerToUserType(YAML::Emitter& out, std::string& desiredOutput)
		{
			Foo foo(5, "hello");
			Foo *bar = &foo;
			Foo *baz = 0;
			out << YAML::BeginSeq;
			out << bar << baz;
			out << YAML::EndSeq;
			
703
			desiredOutput = "- x: 5\n  bar: hello\n- ~";
704
		}
705
706
707
708
		
		void NewlineAtEnd(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << "Hello" << YAML::Newline << YAML::Newline;
709
			desiredOutput = "Hello\n\n";
710
711
712
713
714
715
716
		}
		
		void NewlineInBlockSequence(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << "a" << YAML::Newline << "b" << "c" << YAML::Newline << "d";
			out << YAML::EndSeq;
717
			desiredOutput = "- a\n\n- b\n- c\n\n- d";
718
719
720
721
722
723
724
		}
		
		void NewlineInFlowSequence(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginSeq;
			out << "a" << YAML::Newline << "b" << "c" << YAML::Newline << "d";
			out << YAML::EndSeq;
725
			desiredOutput = "[a,\nb, c,\nd]";
726
		}
727
728
729
730
731
732
733
734

		void NewlineInBlockMap(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << "a" << YAML::Value << "foo" << YAML::Newline;
			out << YAML::Key << "b" << YAML::Newline << YAML::Value << "bar";
			out << YAML::LongKey << YAML::Key << "c" << YAML::Newline << YAML::Value << "car";
			out << YAML::EndMap;
735
			desiredOutput = "a: foo\nb:\n  bar\n? c\n\n: car";
736
737
738
739
740
741
		}
		
		void NewlineInFlowMap(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginMap;
			out << YAML::Key << "a" << YAML::Value << "foo" << YAML::Newline;
742
			out << YAML::Key << "b" << YAML::Value << "bar";
743
			out << YAML::EndMap;
744
			desiredOutput = "{a: foo,\nb: bar}";
745
		}
746
		
747
748
749
750
751
752
753
754
755
756
757
758
759
		void LotsOfNewlines(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << "a" << YAML::Newline;
			out << YAML::BeginSeq;
			out << "b" << "c" << YAML::Newline;
			out << YAML::EndSeq;
			out << YAML::Newline;
			out << YAML::BeginMap;
			out << YAML::Newline << YAML::Key << "d" << YAML::Value << YAML::Newline << "e";
			out << YAML::LongKey << YAML::Key << "f" << YAML::Newline << YAML::Value << "foo";
			out << YAML::EndMap;
			out << YAML::EndSeq;
760
			desiredOutput = "- a\n\n-\n  - b\n  - c\n\n\n-\n  d:\n    e\n  ? f\n\n  : foo";
761
		}
762
763
764
		
		void Binary(YAML::Emitter& out, std::string& desiredOutput)
		{
765
			out << YAML::Binary(reinterpret_cast<const unsigned char*>("Hello, World!"), 13);
766
			desiredOutput = "!!binary \"SGVsbG8sIFdvcmxkIQ==\"";
767
768
769
770
		}

		void LongBinary(YAML::Emitter& out, std::string& desiredOutput)
		{
771
			out << YAML::Binary(reinterpret_cast<const unsigned char*>("Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.\n"), 270);
772
			desiredOutput = "!!binary \"TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4K\"";
773
774
775
776
		}

		void EmptyBinary(YAML::Emitter& out, std::string& desiredOutput)
		{
777
			out << YAML::Binary(reinterpret_cast<const unsigned char *>(""), 0);
778
			desiredOutput = "!!binary \"\"";
779
		}
780
781
782
783
		
		void ColonAtEndOfScalar(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << "a:";
784
			desiredOutput = "\"a:\"";
785
786
787
788
789
790
791
792
		}

		void ColonAsScalar(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << "apple" << YAML::Value << ":";
			out << YAML::Key << "banana" << YAML::Value << ":";
			out << YAML::EndMap;
793
			desiredOutput = "apple: \":\"\nbanana: \":\"";
794
		}
795
		
796
797
798
799
800
801
		void ColonAtEndOfScalarInFlow(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::Flow << YAML::BeginMap << YAML::Key << "C:" << YAML::Value << "C:" << YAML::EndMap;
			desiredOutput = "{\"C:\": \"C:\"}";
		}
		
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
		void BoolFormatting(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << YAML::TrueFalseBool << YAML::UpperCase << true;
			out << YAML::TrueFalseBool << YAML::CamelCase << true;
			out << YAML::TrueFalseBool << YAML::LowerCase << true;
			out << YAML::TrueFalseBool << YAML::UpperCase << false;
			out << YAML::TrueFalseBool << YAML::CamelCase << false;
			out << YAML::TrueFalseBool << YAML::LowerCase << false;
			out << YAML::YesNoBool << YAML::UpperCase << true;
			out << YAML::YesNoBool << YAML::CamelCase << true;
			out << YAML::YesNoBool << YAML::LowerCase << true;
			out << YAML::YesNoBool << YAML::UpperCase << false;
			out << YAML::YesNoBool << YAML::CamelCase << false;
			out << YAML::YesNoBool << YAML::LowerCase << false;
			out << YAML::OnOffBool << YAML::UpperCase << true;
			out << YAML::OnOffBool << YAML::CamelCase << true;
			out << YAML::OnOffBool << YAML::LowerCase << true;
			out << YAML::OnOffBool << YAML::UpperCase << false;
			out << YAML::OnOffBool << YAML::CamelCase << false;
			out << YAML::OnOffBool << YAML::LowerCase << false;
			out << YAML::ShortBool << YAML::UpperCase << true;
			out << YAML::ShortBool << YAML::CamelCase << true;
			out << YAML::ShortBool << YAML::LowerCase << true;
			out << YAML::ShortBool << YAML::UpperCase << false;
			out << YAML::ShortBool << YAML::CamelCase << false;
			out << YAML::ShortBool << YAML::LowerCase << false;
			out << YAML::EndSeq;
			desiredOutput =
831
			"- TRUE\n- True\n- true\n- FALSE\n- False\n- false\n"
832
833
834
835
			"- YES\n- Yes\n- yes\n- NO\n- No\n- no\n"
			"- ON\n- On\n- on\n- OFF\n- Off\n- off\n"
			"- Y\n- Y\n- y\n- N\n- N\n- n";
		}
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
		
		void DocStartAndEnd(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginDoc;
			out << YAML::BeginSeq << 1 << 2 << 3 << YAML::EndSeq;
			out << YAML::BeginDoc;
			out << "Hi there!";
			out << YAML::EndDoc;
			out << YAML::EndDoc;
			out << YAML::EndDoc;
			out << YAML::BeginDoc;
			out << YAML::VerbatimTag("foo") << "bar";
			desiredOutput = "---\n- 1\n- 2\n- 3\n---\nHi there!\n...\n...\n...\n---\n!<foo> bar";
		}
		
		void ImplicitDocStart(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << "Hi";
			out << "Bye";
			out << "Oops";
			desiredOutput = "Hi\n---\nBye\n---\nOops";
		}
858
859
860
861
862
863
864
865
		
		void EmptyString(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginMap;
			out << YAML::Key << "key" << YAML::Value << "";
			out << YAML::EndMap;
			desiredOutput = "key: \"\"";
		}
Jesse Beder's avatar
Jesse Beder committed
866
867
868
869
870
871
872
873
874
875
876
877
878
		
		void SingleChar(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::BeginSeq;
			out << 'a';
			out << ':';
			out << (char)0x10;
			out << '\n';
			out << ' ';
			out << '\t';
			out << YAML::EndSeq;
			desiredOutput = "- a\n- \":\"\n- \"\\x10\"\n- \"\\n\"\n- \" \"\n- \"\\t\"";
		}
879
880
881
882
883
884
885
886
887
        
        void DefaultPrecision(YAML::Emitter& out, std::string& desiredOutput)
        {
            out << YAML::BeginSeq;
            out << 1.234f;
            out << 3.14159265358979;
            out << YAML::EndSeq;
            desiredOutput = "- 1.234\n- 3.14159265358979";
        }
888

889
890
891
892
893
894
895
896
        void SetPrecision(YAML::Emitter& out, std::string& desiredOutput)
        {
            out << YAML::BeginSeq;
            out << YAML::FloatPrecision(3) << 1.234f;
            out << YAML::DoublePrecision(6) << 3.14159265358979;
            out << YAML::EndSeq;
            desiredOutput = "- 1.23\n- 3.14159";
        }
897
898
899
900
901
902
903
904
905
        
        void DashInBlockContext(YAML::Emitter& out, std::string& desiredOutput)
        {
            out << YAML::BeginMap;
            out << YAML::Key << "key" << YAML::Value << "-";
            out << YAML::EndMap;
            desiredOutput = "key: \"-\"";
        }
        
906
907
908
909
910
911
912
913
914
915
        void HexAndOct(YAML::Emitter& out, std::string& desiredOutput)
        {
            out << YAML::Flow << YAML::BeginSeq;
            out << 31;
            out << YAML::Hex << 31;
            out << YAML::Oct << 31;
            out << YAML::EndSeq;
            desiredOutput = "[31, 0x1f, 037]";
        }
        
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
        void CompactMapWithNewline(YAML::Emitter& out, std::string& desiredOutput)
        {
            out << YAML::Comment("Characteristics");
            out << YAML::BeginSeq;
            out << YAML::BeginMap;
            out << YAML::Key << "color" << YAML::Value << "blue";
            out << YAML::Key << "height" << YAML::Value << 120;
            out << YAML::EndMap;
            out << YAML::Newline << YAML::Newline;
            out << YAML::Comment("Skills");
            out << YAML::BeginMap;
            out << YAML::Key << "attack" << YAML::Value << 23;
            out << YAML::Key << "intelligence" << YAML::Value << 56;
            out << YAML::EndMap;
            out << YAML::EndSeq;
            
            desiredOutput =
            "# Characteristics\n"
            "- color: blue\n"
            "  height: 120\n"
            "\n"
            "# Skills\n"
            "- attack: 23\n"
            "  intelligence: 56";
        }
        
942
943
944
945
		void ForceSingleQuotedToDouble(YAML::Emitter& out, std::string& desiredOutput)
		{
			out << YAML::SingleQuoted << "Hello\nWorld";

946
            desiredOutput = "\"Hello\\nWorld\"";
947
948
949
		}
        
        ////////////////////////////////////////////////////////////////////////////////
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
		// incorrect emitting
		
		void ExtraEndSeq(YAML::Emitter& out, std::string& desiredError)
		{
			desiredError = YAML::ErrorMsg::UNEXPECTED_END_SEQ;

			out << YAML::BeginSeq;
			out << "Hello";
			out << "World";
			out << YAML::EndSeq;
			out << YAML::EndSeq;
		}

		void ExtraEndMap(YAML::Emitter& out, std::string& desiredError)
		{
			desiredError = YAML::ErrorMsg::UNEXPECTED_END_MAP;
			
			out << YAML::BeginMap;
			out << YAML::Key << "Hello" << YAML::Value << "World";
			out << YAML::EndMap;
			out << YAML::EndMap;
		}

		void InvalidAnchor(YAML::Emitter& out, std::string& desiredError)
		{
			desiredError = YAML::ErrorMsg::INVALID_ANCHOR;
			
			out << YAML::BeginSeq;
			out << YAML::Anchor("new\nline") << "Test";
			out << YAML::EndSeq;
		}
		
		void InvalidAlias(YAML::Emitter& out, std::string& desiredError)
		{
			desiredError = YAML::ErrorMsg::INVALID_ALIAS;
			
			out << YAML::BeginSeq;
			out << YAML::Alias("new\nline");
			out << YAML::EndSeq;
		}
	}
Jesse Beder's avatar
Jesse Beder committed
991
992
	
	namespace {
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
        class NullEventHandler: public YAML::EventHandler {
            virtual void OnDocumentStart(const YAML::Mark&) {}
            virtual void OnDocumentEnd() {}
            
            virtual void OnNull(const YAML::Mark&, YAML::anchor_t) {}
            virtual void OnAlias(const YAML::Mark&, YAML::anchor_t) {}
            virtual void OnScalar(const YAML::Mark&, const std::string&, YAML::anchor_t, const std::string&) {}
            
            virtual void OnSequenceStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
            virtual void OnSequenceEnd() {}
            
            virtual void OnMapStart(const YAML::Mark&, const std::string&, YAML::anchor_t) {}
            virtual void OnMapEnd() {}
        };
        
Jesse Beder's avatar
Jesse Beder committed
1008
1009
1010
1011
1012
		void RunEmitterTest(void (*test)(YAML::Emitter&, std::string&), const std::string& name, int& passed, int& total) {
			YAML::Emitter out;
			std::string desiredOutput;
			test(out, desiredOutput);
			std::string output = out.c_str();
1013
			std::string lastError = out.GetLastError();
Jesse Beder's avatar
Jesse Beder committed
1014
1015

			if(output == desiredOutput) {
1016
1017
1018
				try {
					std::stringstream stream(output);
					YAML::Parser parser;
1019
1020
                    NullEventHandler handler;
                    parser.HandleNextDocument(handler);
1021
1022
1023
1024
1025
					passed++;
				} catch(const YAML::Exception& e) {
					std::cout << "Emitter test failed: " << name << "\n";
					std::cout << "Parsing output error: " << e.what() << "\n";
				}
Jesse Beder's avatar
Jesse Beder committed
1026
1027
1028
1029
1030
1031
			} else {
				std::cout << "Emitter test failed: " << name << "\n";
				std::cout << "Output:\n";
				std::cout << output << "<<<\n";
				std::cout << "Desired output:\n";
				std::cout << desiredOutput << "<<<\n";				
1032
1033
				if(!out.good())
					std::cout << "Emitter error: " << lastError << "\n";
Jesse Beder's avatar
Jesse Beder committed
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
			}
			total++;
		}
		
		void RunEmitterErrorTest(void (*test)(YAML::Emitter&, std::string&), const std::string& name, int& passed, int& total) {
			YAML::Emitter out;
			std::string desiredError;
			test(out, desiredError);
			std::string lastError = out.GetLastError();
			if(!out.good() && lastError == desiredError) {
				passed++;
			} else {
				std::cout << "Emitter test failed: " << name << "\n";
				if(out.good())
					std::cout << "No error detected\n";
				else
					std::cout << "Detected error: " << lastError << "\n";
				std::cout << "Expected error: " << desiredError << "\n";
			}
			total++;
		}
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
        
        void RunGenEmitterTest(TEST (*test)(YAML::Emitter&), const std::string& name, int& passed, int& total) {
            YAML::Emitter out;
            TEST ret;

			try {
				ret = test(out);
			} catch(const YAML::Exception& e) {
				ret.ok = false;
				ret.error = std::string("  Exception caught: ") + e.what();
			}
            
            if(!out.good()) {
                ret.ok = false;
                ret.error = out.GetLastError();
            }
			
			if(!ret.ok) {
				std::cout << "Generated emitter test failed: " << name << "\n";
                std::cout << "Output:\n";
                std::cout << out.c_str() << "<<<\n";
				std::cout << ret.error << "\n";
			}
			
			if(ret.ok)
				passed++;
			total++;
        }
Jesse Beder's avatar
Jesse Beder committed
1083
	}
1084
1085
    
#include "genemittertests.h"
Jesse Beder's avatar
Jesse Beder committed
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
	
	bool RunEmitterTests()
	{
		int passed = 0;
		int total = 0;
		RunEmitterTest(&Emitter::SimpleScalar, "simple scalar", passed, total);
		RunEmitterTest(&Emitter::SimpleSeq, "simple seq", passed, total);
		RunEmitterTest(&Emitter::SimpleFlowSeq, "simple flow seq", passed, total);
		RunEmitterTest(&Emitter::EmptyFlowSeq, "empty flow seq", passed, total);
		RunEmitterTest(&Emitter::NestedBlockSeq, "nested block seq", passed, total);
		RunEmitterTest(&Emitter::NestedFlowSeq, "nested flow seq", passed, total);
		RunEmitterTest(&Emitter::SimpleMap, "simple map", passed, total);
		RunEmitterTest(&Emitter::SimpleFlowMap, "simple flow map", passed, total);
		RunEmitterTest(&Emitter::MapAndList, "map and list", passed, total);
		RunEmitterTest(&Emitter::ListAndMap, "list and map", passed, total);
		RunEmitterTest(&Emitter::NestedBlockMap, "nested block map", passed, total);
		RunEmitterTest(&Emitter::NestedFlowMap, "nested flow map", passed, total);
		RunEmitterTest(&Emitter::MapListMix, "map list mix", passed, total);
		RunEmitterTest(&Emitter::SimpleLongKey, "simple long key", passed, total);
		RunEmitterTest(&Emitter::SingleLongKey, "single long key", passed, total);
		RunEmitterTest(&Emitter::ComplexLongKey, "complex long key", passed, total);
		RunEmitterTest(&Emitter::AutoLongKey, "auto long key", passed, total);
		RunEmitterTest(&Emitter::ScalarFormat, "scalar format", passed, total);
		RunEmitterTest(&Emitter::AutoLongKeyScalar, "auto long key scalar", passed, total);
		RunEmitterTest(&Emitter::LongKeyFlowMap, "long key flow map", passed, total);
		RunEmitterTest(&Emitter::BlockMapAsKey, "block map as key", passed, total);
		RunEmitterTest(&Emitter::AliasAndAnchor, "alias and anchor", passed, total);
		RunEmitterTest(&Emitter::AliasAndAnchorWithNull, "alias and anchor with null", passed, total);
1114
		RunEmitterTest(&Emitter::AliasAndAnchorInFlow, "alias and anchor in flow", passed, total);
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
		RunEmitterTest(&Emitter::SimpleVerbatimTag, "simple verbatim tag", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagInBlockSeq, "verbatim tag in block seq", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagInFlowSeq, "verbatim tag in flow seq", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagInFlowSeqWithNull, "verbatim tag in flow seq with null", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagInBlockMap, "verbatim tag in block map", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagInFlowMap, "verbatim tag in flow map", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagInFlowMapWithNull, "verbatim tag in flow map with null", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagWithEmptySeq, "verbatim tag with empty seq", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagWithEmptyMap, "verbatim tag with empty map", passed, total);
		RunEmitterTest(&Emitter::VerbatimTagWithEmptySeqAndMap, "verbatim tag with empty seq and map", passed, total);
1125
1126
		RunEmitterTest(&Emitter::ByKindTagWithScalar, "by-kind tag with scalar", passed, total);
		RunEmitterTest(&Emitter::LocalTagWithScalar, "local tag with scalar", passed, total);
Jesse Beder's avatar
Jesse Beder committed
1127
1128
1129
1130
1131
		RunEmitterTest(&Emitter::ComplexDoc, "complex doc", passed, total);
		RunEmitterTest(&Emitter::STLContainers, "STL containers", passed, total);
		RunEmitterTest(&Emitter::SimpleComment, "simple comment", passed, total);
		RunEmitterTest(&Emitter::MultiLineComment, "multi-line comment", passed, total);
		RunEmitterTest(&Emitter::ComplexComments, "complex comments", passed, total);
1132
1133
1134
1135
		RunEmitterTest(&Emitter::InitialComment, "initial comment", passed, total);
		RunEmitterTest(&Emitter::InitialCommentWithDocIndicator, "initial comment with doc indicator", passed, total);
		RunEmitterTest(&Emitter::CommentInFlowSeq, "comment in flow seq", passed, total);
		RunEmitterTest(&Emitter::CommentInFlowMap, "comment in flow map", passed, total);
Jesse Beder's avatar
Jesse Beder committed
1136
1137
1138
1139
		RunEmitterTest(&Emitter::Indentation, "indentation", passed, total);
		RunEmitterTest(&Emitter::SimpleGlobalSettings, "simple global settings", passed, total);
		RunEmitterTest(&Emitter::ComplexGlobalSettings, "complex global settings", passed, total);
		RunEmitterTest(&Emitter::Null, "null", passed, total);
1140
		RunEmitterTest(&Emitter::EscapedUnicode, "escaped unicode", passed, total);
Jesse Beder's avatar
Jesse Beder committed
1141
		RunEmitterTest(&Emitter::Unicode, "unicode", passed, total);
1142
		RunEmitterTest(&Emitter::DoubleQuotedUnicode, "double quoted unicode", passed, total);
1143
1144
1145
1146
		RunEmitterTest(&Emitter::UserType, "user type", passed, total);
		RunEmitterTest(&Emitter::UserTypeInContainer, "user type in container", passed, total);
		RunEmitterTest(&Emitter::PointerToInt, "pointer to int", passed, total);
		RunEmitterTest(&Emitter::PointerToUserType, "pointer to user type", passed, total);
1147
1148
1149
		RunEmitterTest(&Emitter::NewlineAtEnd, "newline at end", passed, total);
		RunEmitterTest(&Emitter::NewlineInBlockSequence, "newline in block sequence", passed, total);
		RunEmitterTest(&Emitter::NewlineInFlowSequence, "newline in flow sequence", passed, total);
1150
1151
1152
		RunEmitterTest(&Emitter::NewlineInBlockMap, "newline in block map", passed, total);
		RunEmitterTest(&Emitter::NewlineInFlowMap, "newline in flow map", passed, total);
		RunEmitterTest(&Emitter::LotsOfNewlines, "lots of newlines", passed, total);
1153
1154
1155
		RunEmitterTest(&Emitter::Binary, "binary", passed, total);
		RunEmitterTest(&Emitter::LongBinary, "long binary", passed, total);
		RunEmitterTest(&Emitter::EmptyBinary, "empty binary", passed, total);
1156
1157
		RunEmitterTest(&Emitter::ColonAtEndOfScalar, "colon at end of scalar", passed, total);
		RunEmitterTest(&Emitter::ColonAsScalar, "colon as scalar", passed, total);
1158
		RunEmitterTest(&Emitter::ColonAtEndOfScalarInFlow, "colon at end of scalar in flow", passed, total);
1159
		RunEmitterTest(&Emitter::BoolFormatting, "bool formatting", passed, total);
1160
1161
		RunEmitterTest(&Emitter::DocStartAndEnd, "doc start and end", passed, total);
		RunEmitterTest(&Emitter::ImplicitDocStart, "implicit doc start", passed, total);
1162
		RunEmitterTest(&Emitter::EmptyString, "empty string", passed, total);
Jesse Beder's avatar
Jesse Beder committed
1163
		RunEmitterTest(&Emitter::SingleChar, "single char", passed, total);
1164
1165
		RunEmitterTest(&Emitter::DefaultPrecision, "default precision", passed, total);
		RunEmitterTest(&Emitter::SetPrecision, "set precision", passed, total);
1166
		RunEmitterTest(&Emitter::DashInBlockContext, "dash in block context", passed, total);
1167
		RunEmitterTest(&Emitter::HexAndOct, "hex and oct", passed, total);
1168
		RunEmitterTest(&Emitter::CompactMapWithNewline, "compact map with newline", passed, total);
1169
        RunEmitterTest(&Emitter::ForceSingleQuotedToDouble, "force single quoted to double", passed, total);
Jesse Beder's avatar
Jesse Beder committed
1170
1171
1172
1173
1174
		
		RunEmitterErrorTest(&Emitter::ExtraEndSeq, "extra EndSeq", passed, total);
		RunEmitterErrorTest(&Emitter::ExtraEndMap, "extra EndMap", passed, total);
		RunEmitterErrorTest(&Emitter::InvalidAnchor, "invalid anchor", passed, total);
		RunEmitterErrorTest(&Emitter::InvalidAlias, "invalid alias", passed, total);
1175
		RunEmitterErrorTest(&Emitter::BadLocalTag, "bad local tag", passed, total);
1176
1177
        
        RunGenEmitterTests(passed, total);
Jesse Beder's avatar
Jesse Beder committed
1178
1179
1180
1181

		std::cout << "Emitter tests: " << passed << "/" << total << " passed\n";
		return passed == total;
	}
1182
}
Jesse Beder's avatar
Jesse Beder committed
1183