Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: tests/utils/src/YamlTest.dart

Issue 10153004: Add a basic YAML processor. Much of the language is still unimplemented. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove tests/lib from TEST_SUITE_DIRECTORIES. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library('yamlTest');
6
7 #import('../../../lib/unittest/unittest.dart');
8 #import('../../../utils/yaml/yaml.dart', prefix: 'yaml');
9
10 /** Constructs a new yaml.YamlMap, optionally from a normal Map. */
11 Map yamlMap([Map from]) =>
12 from == null ? new yaml.YamlMap() : new yaml.YamlMap.from(from);
13
14 /** Returns whether two lists have equivalent contents. */
15 bool listDeepEquals(List list1, List list2) {
16 if (list1.length != list2.length) return false;
17
18 for (var i = 0; i < list1.length; i++) {
19 if (!deepEquals(list1[i], list2[i])) return false;
20 }
21
22 return true;
23 }
24
25 /** Returns whether two maps have equivalent contents. */
26 bool mapDeepEquals(Map map1, Map map2) {
27 if (map1.length != map2.length) return false;
28
29 for (var key in map1.getKeys()) {
30 if (!map2.containsKey(key)) return false;
31 if (!deepEquals(map1[key], map2[key])) return false;
32 }
33
34 return true;
35 }
36
37 /**
38 * Returns whether two doubles are equal. This differs from `d1 == d2` in that
39 * it considers NaN to be equal to itself.
40 */
41 bool doubleEquals(double d1, double d2) {
42 if (d1.isNaN() && d2.isNaN()) return true;
43 return d1 == d2;
44 }
45
46 /** Returns whether two objects are structurally equivalent. */
47 bool deepEquals(obj1, obj2) {
48 if (obj1 is List && obj2 is List) return listDeepEquals(obj1, obj2);
49 if (obj1 is Map && obj2 is Map) return mapDeepEquals(obj1, obj2);
50 if (obj1 is double && obj2 is double) return doubleEquals(obj1, obj2);
51 return obj1 == obj2;
52 }
53
54 /**
55 * Asserts that a string containing a single YAML document produces a given
56 * value when loaded.
57 */
58 expectYamlLoads(expected, String source) {
59 var actual = yaml.load(source);
60 Expect.isTrue(deepEquals(expected, actual),
61 'expectYamlLoads(expected: <$expected>, actual: <$actual>)');
62 }
63
64 /**
65 * Asserts that a string containing a stream of YAML documents produces a given
66 * list of values when loaded.
67 */
68 expectYamlStreamLoads(List expected, String source) {
69 var actual = yaml.loadStream(source);
70 Expect.isTrue(deepEquals(expected, actual),
71 'expectYamlStreamLoads(expected: <$expected>, actual: <$actual>)');
72 }
73
74 main() {
75 var infinity = Math.parseDouble("Infinity");
76 var nan = Math.parseDouble("NaN");
77
78 group('YamlMap', () {
79 group('accepts as a key', () {
80 _expectKeyWorks(keyFn()) {
81 var map = yamlMap();
82 map[keyFn()] = 5;
83 Expect.isTrue(map.containsKey(keyFn()));
84 Expect.equals(5, map[keyFn()]);
85 }
86
87 test('null', () => _expectKeyWorks(() => null));
88 test('true', () => _expectKeyWorks(() => true));
89 test('false', () => _expectKeyWorks(() => false));
90 test('a list', () => _expectKeyWorks(() => [1, 2, 3]));
91 test('a map', () => _expectKeyWorks(() => {'foo': 'bar'}));
92 test('a YAML map', () => _expectKeyWorks(() => yamlMap({'foo': 'bar'})));
93 });
94
95 test('works as a hash key', () {
96 var normalMap = new Map();
97 normalMap[yamlMap({'foo': 'bar'})] = 'baz';
98 Expect.isTrue(normalMap.containsKey(yamlMap({'foo': 'bar'})));
99 Expect.equals('baz', normalMap[yamlMap({'foo': 'bar'})]);
100 });
101 });
102
103 // The following tests are all taken directly from the YAML spec
104 // (http://www.yaml.org/spec/1.2/spec.html). Most of them are code examples
105 // that are directly included in the spec, but additional tests are derived
106 // from the prose.
107
108 // A few examples from the spec are deliberately excluded, because they test
109 // features that this implementation doesn't intend to support (character
110 // encoding detection and user-defined tags). More tests are commented out,
111 // because they're intended to be supported but not yet implemented.
112
113 // Chapter 2 is just a preview of various Yaml documents. It's probably not
114 // necessary to test its examples, but it would be nice to test everything in
115 // the spec.
116 group('2.1: Collections', () {
117 test('[Example 2.1]', () {
118 expectYamlLoads(["Mark McGwire", "Sammy Sosa", "Ken Griffey"], """
119 - Mark McGwire
120 - Sammy Sosa
121 - Ken Griffey
122 """);
123 });
124
125 test('[Example 2.2]', () {
126 expectYamlLoads({"hr": 65, "avg": 0.278, "rbi": 147}, """
127 hr: 65 # Home runs
128 avg: 0.278 # Batting average
129 rbi: 147 # Runs Batted In
130 """);
131 });
132
133 test('[Example 2.3]', () {
134 expectYamlLoads({
135 "american": ["Boston Red Sox", "Detroit Tigers", "New York Yankees"],
136 "national": ["New York Mets", "Chicago Cubs", "Atlanta Braves"],
137 }, """
138 american:
139 - Boston Red Sox
140 - Detroit Tigers
141 - New York Yankees
142 national:
143 - New York Mets
144 - Chicago Cubs
145 - Atlanta Braves
146 """);
147 });
148
149 test('[Example 2.4]', () {
150 expectYamlLoads([
151 {"name": "Mark McGwire", "hr": 65, "avg": 0.278},
152 {"name": "Sammy Sosa", "hr": 63, "avg": 0.288},
153 ], """
154 -
155 name: Mark McGwire
156 hr: 65
157 avg: 0.278
158 -
159 name: Sammy Sosa
160 hr: 63
161 avg: 0.288
162 """);
163 });
164
165 // test('[Example 2.5]', () {
166 // expectYamlLoads([
167 // ["name", "hr", "avg"],
168 // ["Mark McGwire", 65, 0.278],
169 // ["Sammy Sosa", 63, 0.288]
170 // ], """
171 // - [name , hr, avg ]
172 // - [Mark McGwire, 65, 0.278]
173 // - [Sammy Sosa , 63, 0.288]
174 // """);
175 // });
176
177 // test('[Example 2.6]', () {
178 // expectYamlLoads({
179 // "Mark McGwire": {"hr": 65, "avg": 0.278},
180 // "Sammy Sosa": {"hr": 63, "avg": 0.288}
181 // }, """
182 // Mark McGwire: {hr: 65, avg: 0.278}
183 // Sammy Sosa: {
184 // hr: 63,
185 // avg: 0.288
186 // }
187 // """);
188 // });
189 });
190
191 group('2.2: Structures', () {
192 test('[Example 2.7]', () {
193 expectYamlStreamLoads([
194 ["Mark McGwire", "Sammy Sosa", "Ken Griffey"],
195 ["Chicago Cubs", "St Louis Cardinals"]
196 ], """
197 # Ranking of 1998 home runs
198 ---
199 - Mark McGwire
200 - Sammy Sosa
201 - Ken Griffey
202
203 # Team ranking
204 ---
205 - Chicago Cubs
206 - St Louis Cardinals
207 """);
208 });
209
210 test('[Example 2.8]', () {
211 expectYamlStreamLoads([
212 {"time": "20:03:20", "player": "Sammy Sosa", "action": "strike (miss)"},
213 {"time": "20:03:47", "player": "Sammy Sosa", "action": "grand slam"},
214 ], """
215 ---
216 time: 20:03:20
217 player: Sammy Sosa
218 action: strike (miss)
219 ...
220 ---
221 time: 20:03:47
222 player: Sammy Sosa
223 action: grand slam
224 ...
225 """);
226 });
227
228 test('[Example 2.9]', () {
229 expectYamlLoads({
230 "hr": ["Mark McGwire", "Sammy Sosa"],
231 "rbi": ["Sammy Sosa", "Ken Griffey"]
232 }, """
233 ---
234 hr: # 1998 hr ranking
235 - Mark McGwire
236 - Sammy Sosa
237 rbi:
238 # 1998 rbi ranking
239 - Sammy Sosa
240 - Ken Griffey
241 """);
242 });
243
244 // test('[Example 2.10]', () {
245 // expectYamlLoads({
246 // "hr": ["Mark McGwire", "Sammy Sosa"],
247 // "rbi": ["Sammy Sosa", "Ken Griffey"]
248 // }, """
249 // ---
250 // hr:
251 // - Mark McGwire
252 // # Following node labeled SS
253 // - &SS Sammy Sosa
254 // rbi:
255 // - *SS # Subsequent occurrence
256 // - Ken Griffey
257 // """);
258 // });
259
260 // test('[Example 2.11]', () {
261 // var doc = yamlMap();
262 // doc[["Detroit Tigers", "Chicago cubs"]] = ["2001-07-23"];
263 // doc[["New York Yankees", "Atlanta Braves"]] =
264 // ["2001-07-02", "2001-08-12", "2001-08-14"];
265 // expectYamlLoads(doc, """
266 // ? - Detroit Tigers
267 // - Chicago cubs
268 // :
269 // - 2001-07-23
270
271 // ? [ New York Yankees,
272 // Atlanta Braves ]
273 // : [ 2001-07-02, 2001-08-12,
274 // 2001-08-14 ]
275 // """);
276 // });
277
278 test('[Example 2.12]', () {
279 expectYamlLoads([
280 {"item": "Super Hoop", "quantity": 1},
281 {"item": "Basketball", "quantity": 4},
282 {"item": "Big Shoes", "quantity": 1},
283 ], """
284 ---
285 # Products purchased
286 - item : Super Hoop
287 quantity: 1
288 - item : Basketball
289 quantity: 4
290 - item : Big Shoes
291 quantity: 1
292 """);
293 });
294 });
295
296 group('2.3: Scalars', () {
297 // test('[Example 2.13]', () {
298 // expectYamlLoads("""
299 // \//||\/||
300 // // || ||__
301 // """.trim(), """
302 // # ASCII Art
303 // --- |
304 // \//||\/||
305 // // || ||__
306 // """);
307 // });
308
309 // test('[Example 2.14]', () {
310 // expectYamlLoads("Mark McGwire's year was crippled by a knee injury.", " ""
311 // --- >
312 // Mark McGwire's
313 // year was crippled
314 // by a knee injury.
315 // """);
316 // });
317
318 // test('[Example 2.15]', () {
319 // expectYamlLoads("""
320 // Sammy Sosa completed another
321 // fine season with great stats.
322
323 // 63 Home Runs
324 // 0.288 Batting Average
325
326 // What a year!
327 // """, """
328 // >
329 // Sammy Sosa completed another
330 // fine season with great stats.
331
332 // 63 Home Runs
333 // 0.288 Batting Average
334
335 // What a year!
336 // """);
337 // });
338
339 // test('[Example 2.16]', () {
340 // expectYamlLoads({
341 // "name": "Mark McGwire",
342 // "accomplishment": "Mark set a major league home run record in 1998.",
343 // "stats": "65 Home Runs\n0.278 Batting Average"
344 // }, """
345 // name: Mark McGwire
346 // accomplishment: >
347 // Mark set a major league
348 // home run record in 1998.
349 // stats: |
350 // 65 Home Runs
351 // 0.278 Batting Average
352 // """);
353 // });
354
355 // test('[Example 2.17]', () {
356 // expectYamlLoads({
357 // "unicode": "Sosa did fine.\u263A",
358 // "control": "\b1998\t1999\t2000\n",
359 // "hex esc": "\r\n is \r\n",
360 // "single": '"Howdy!" he cried.',
361 // "quoted": " # Not a 'comment'.",
362 // "tie-fighter": "|\-*-/|"
363 // }, """
364 // unicode: "Sosa did fine.\u263A"
365 // control: "\b1998\t1999\t2000\n"
366 // hex esc: "\x0d\x0a is \r\n"
367
368 // single: '"Howdy!" he cried.'
369 // quoted: ' # Not a ''comment''.'
370 // tie-fighter: '|\-*-/|'
371 // """);
372 // });
373
374 // test('[Example 2.18]', () {
375 // expectYamlLoads({
376 // "plain": "This unquoted scalar spans many lines.",
377 // "quoted": "So does this quoted scalar.\n"
378 // }, """
379 // plain:
380 // This unquoted scalar
381 // spans many lines.
382
383 // quoted: "So does this
384 // quoted scalar.\n"
385 // """);
386 // });
387 });
388
389 group('2.4: Tags', () {
390 test('[Example 2.19]', () {
391 expectYamlLoads({
392 "canonical": 12345,
393 "decimal": 12345,
394 "octal": 12,
395 "hexadecimal": 12
396 }, """
397 canonical: 12345
398 decimal: +12345
399 octal: 0o14
400 hexadecimal: 0xC
401 """);
402 });
403
404 test('[Example 2.20]', () {
405 expectYamlLoads({
406 "canonical": 1230.15,
407 "exponential": 1230.15,
408 "fixed": 1230.15,
409 "negative infinity": -infinity,
410 "not a number": nan
411 }, """
412 canonical: 1.23015e+3
413 exponential: 12.3015e+02
414 fixed: 1230.15
415 negative infinity: -.inf
416 not a number: .NaN
417 """);
418 });
419
420 // test('[Example 2.21]', () {
421 // var doc = yamlMap({
422 // "booleans": [true, false],
423 // "string": "012345"
424 // });
425 // doc[null] = null;
426 // expectYamlLoads(doc, """
427 // null:
428 // booleans: [ true, false ]
429 // string: '012345'
430 // """);
431 // });
432
433 // Examples 2.22 through 2.26 test custom tag URIs, which this
434 // implementation currently doesn't plan to support.
435 });
436
437 group('2.5 Full Length Example', () {
438 // Example 2.27 tests custom tag URIs, which this implementation currently
439 // doesn't plan to support.
440
441 // test('[Example 2.28]', () {
442 // expectYamlStreamLoads([
443 // {
444 // "Time": "2001-11-23 15:01:42 -5",
445 // "User": "ed",
446 // "Warning": "This is an error message for the log file"
447 // },
448 // {
449 // "Time": "2001-11-23 15:02:31 -5",
450 // "User": "ed",
451 // "Warning": "A slightly different error message."
452 // },
453 // {
454 // "Date": "2001-11-23 15:03:17 -5",
455 // "User": "ed",
456 // "Fatal": 'Unknown variable "bar"',
457 // "Stack": [
458 // {
459 // "file": "TopClass.py",
460 // "line": 23,
461 // "code": 'x = MoreObject("345\n")\n'
462 // },
463 // {"file": "MoreClass.py", "line": 58, "code": "foo = bar"}
464 // ]
465 // }
466 // ], """
467 // ---
468 // Time: 2001-11-23 15:01:42 -5
469 // User: ed
470 // Warning:
471 // This is an error message
472 // for the log file
473 // ---
474 // Time: 2001-11-23 15:02:31 -5
475 // User: ed
476 // Warning:
477 // A slightly different error
478 // message.
479 // ---
480 // Date: 2001-11-23 15:03:17 -5
481 // User: ed
482 // Fatal:
483 // Unknown variable "bar"
484 // Stack:
485 // - file: TopClass.py
486 // line: 23
487 // code: |
488 // x = MoreObject("345\n")
489 // - file: MoreClass.py
490 // line: 58
491 // code: |-
492 // foo = bar
493 // """);
494 // });
495 });
496
497 // Chapter 3 just talks about the structure of loading and dumping Yaml.
498 // Chapter 4 explains conventions used in the spec.
499
500 // Chapter 5: Characters
501 group('5.1: Character Set', () {
502 expectAllowsCharacter(int charCode) {
503 var char = new String.fromCharCodes([charCode]);
504 expectYamlLoads('The character "$char" is allowed',
505 'The character "$char" is allowed');
506 }
507
508 expectAllowsQuotedCharacter(int charCode) {
509 var char = new String.fromCharCodes([charCode]);
510 expectYamlLoads("The character '$char' is allowed",
511 '"The character \'$char\' is allowed"');
512 }
513
514 expectDisallowsCharacter(int charCode) {
515 var char = new String.fromCharCodes([charCode]);
516 Expect.throws(() => yaml.load('The character "$char" is disallowed'));
517 }
518
519 test("doesn't include C0 control characters", () {
520 expectDisallowsCharacter(0x0);
521 expectDisallowsCharacter(0x8);
522 expectDisallowsCharacter(0x1F);
523 });
524
525 test("includes TAB", () => expectAllowsCharacter(0x9));
526 test("doesn't include DEL", () => expectDisallowsCharacter(0x7F));
527
528 test("doesn't include C1 control characters", () {
529 expectDisallowsCharacter(0x80);
530 expectDisallowsCharacter(0x8A);
531 expectDisallowsCharacter(0x9F);
532 });
533
534 test("includes NEL", () => expectAllowsCharacter(0x85));
535
536 group("within quoted strings", () {
537 // test("includes DEL", () => expectAllowsQuotedCharacter(0x7F));
538 // test("includes C1 control characters", () {
539 // expectAllowsQuotedCharacter(0x80);
540 // expectAllowsQuotedCharacter(0x8A);
541 // expectAllowsQuotedCharacter(0x9F);
542 // });
543 });
544 });
545
546 // Skipping section 5.2 (Character Encodings), since at the moment the module
547 // assumes that the client code is providing it with a string of the proper
548 // encoding.
549
550 group('5.3: Indicator Characters', () {
551 // test('[Example 5.3]', () {
552 // expectYamlLoads({
553 // 'sequence': ['one', 'two'],
554 // 'mapping': {'sky': 'blue', 'sea': 'green'}
555 // }, """
556 // sequence:
557 // - one
558 // - two
559 // mapping:
560 // ? sky
561 // : blue
562 // sea : green
563 // """);
564 // });
565
566 // test('[Example 5.4]', () {
567 // expectYamlLoads({
568 // 'sequence': ['one', 'two'],
569 // 'mapping': {'sky': 'blue', 'sea': 'green'}
570 // }, """
571 // sequence: [ one, two, ]
572 // mapping: { sky: blue, sea: green }
573 // """);
574 // });
575
576 test('[Example 5.5]', () => expectYamlLoads(null, "# Comment only."));
577
578 // Skipping 5.6 because it uses an undefined tag.
579
580 // test('[Example 5.7]', () {
581 // expectYamlLoads({
582 // 'literal': "some text\n",
583 // 'folded': "some\ntext\n"
584 // }, """
585 // literal: |
586 // some
587 // text
588 // folded: >
589 // some
590 // text
591 // """);
592 // });
593
594 // test('[Example 5.8]', () {
595 // expectYamlLoads({
596 // 'single': "text",
597 // 'double': "text"
598 // }, """
599 // single: 'text'
600 // double: "text"
601 // """);
602 // });
603
604 // test('[Example 5.9]', () {
605 // expectYamlLoads("text", """
606 // %YAML 1.2
607 // --- text
608 // """);
609 // });
610
611 test('[Example 5.10]', () {
612 Expect.throws(() => yaml.load("commercial-at: @text"));
613 Expect.throws(() => yaml.load("commercial-at: `text"));
614 });
615 });
616
617 group('5.4: Line Break Characters', () {
618 group('include', () {
619 test('\\n', () => expectYamlLoads([1, 2], "- 1\n- 2"));
620 test('\\r', () => expectYamlLoads([1, 2], "- 1\r- 2"));
621 });
622
623 group('do not include', () {
624 test('form feed', () => Expect.throws(() => yaml.load("- 1\x0C- 2")));
625 test('NEL', () => expectYamlLoads(["1\x85- 2"], "- 1\x85- 2"));
626 test('0x2028', () => expectYamlLoads(["1\u2028- 2"], "- 1\u2028- 2"));
627 test('0x2029', () => expectYamlLoads(["1\u2029- 2"], "- 1\u2029- 2"));
628 });
629
630 group('in a scalar context must be normalized', () {
631 // test("from \\r to \\n", () =>
632 // expectYamlLoads("foo\nbar", '- |\n foo\r bar'));
633 // test("from \\r\\n to \\n", () =>
634 // expectYamlLoads("foo\nbar", '- |\n foo\r\n bar'));
635 });
636
637 // test('[Example 5.11]', () {
638 // expectYamlLoads("""
639 // Line break (no glyph)
640 // Line break (glyphed)
641 // """, """
642 // |
643 // Line break (no glyph)
644 // Line break (glyphed)
645 // """);
646 // });
647 });
648
649 group('5.5: White Space Characters', () {
650 // test('[Example 5.12]', () {
651 // expectYamlLoads({
652 // "quoted": "Quoted \t",
653 // "block": 'void main() {\n\tprintf("Hello, world!\\n");\n}\n'
654 // }, """
655 // # Tabs and spaces
656 // quoted: "Quoted \t"
657 // block:\t|
658 // void main() {
659 // \tprintf("Hello, world!\\n");
660 // }
661 // """);
662 // });
663 });
664
665 group('5.7: Escaped Characters', () {
666 // test('[Example 5.13]', () {
667 // expectYamlLoads("""
668 // Fun with \x5C
669 // \x22 \x07 \x08 \x1B \x0C
670 // \x0A \x0D \x09 \x0B \x00
671 // \x20 \xA0 \x85 \u2028 \u2029
672 // A A A
673 // """.trim(), '''
674 // "Fun with \\\\
675 // \\" \\a \\b \\e \\f \\
676 // \\n \\r \\t \\v \\0 \\
677 // \\ \\_ \\N \\L \\P \\
678 // \\x41 \\u0041 \\U00000041"
679 // ''');
680 // });
681
682 // test('[Example 5.14]', () {
683 // Expect.throws(() => yaml.load('Bad escape: "\\c"'));
684 // Expect.throws(() => yaml.load('Bad escape: "\\xq-"'));
685 // });
686 });
687
688 // Chapter 6: Basic Structures
689 group('6.1: Indentation Spaces', () {
690 test('may not include TAB characters', () {
691 Expect.throws(() => yaml.load("""
692 -
693 \t- foo
694 \t- bar
695 """));
696 });
697
698 test('must be the same for all sibling nodes', () {
699 Expect.throws(() => yaml.load("""
700 -
701 - foo
702 - bar
703 """));
704 });
705
706 test('may be different for the children of sibling nodes', () {
707 expectYamlLoads([["foo"], ["bar"]], """
708 -
709 - foo
710 -
711 - bar
712 """);
713 });
714
715 // test('[Example 6.1]', () {
716 // expectYamlLoads({
717 // "Not indented": {
718 // "By one space": "By four\n spaces\n",
719 // "Flow style": [
720 // "By two",
721 // "Also by two",
722 // "Still by two"
723 // ]
724 // }
725 // }, """
726 // # Leading comment line spaces are
727 // # neither content nor indentation.
728
729 // Not indented:
730 // By one space: |
731 // By four
732 // spaces
733 // Flow style: [ # Leading spaces
734 // By two, # in flow style
735 // Also by two, # are neither
736 // \tStill by two # content nor
737 // ] # indentation.
738 // """);
739 // });
740
741 // test('[Example 6.2]', () {
742 // expectYamlLoads({'a': ['b', ['c', 'd']]}, """
743 // ? a
744 // : -\tb
745 // - -\tc
746 // - d
747 // """);
748 // });
749 });
750
751 group('6.2: Separation Spaces', () {
752 test('[Example 6.3]', () {
753 expectYamlLoads([{'foo': 'bar'}, ['baz', 'baz']], """
754 - foo:\t bar
755 - - baz
756 -\tbaz
757 """);
758 });
759 });
760
761 group('6.3: Line Prefixes', () {
762 // test('[Example 6.4]', () {
763 // expectYamlLoads({
764 // "plain": "text lines",
765 // "quoted": "text lines",
766 // "block": "text\n \tlines\n"
767 // }, """
768 // plain: text
769 // lines
770 // quoted: "text
771 // \tlines"
772 // block: |
773 // text
774 // \tlines
775 // """);
776 // });
777 });
778
779 group('6.4: Empty Lines', () {
780 // test('[Example 6.5]', () {
781 // expectYamlLoads({
782 // "Folding": "Empty line\nas a line feed",
783 // "Chomping": "Clipped empty lines\n",
784 // }, """
785 // Folding:
786 // "Empty line
787 // \t
788 // as a line feed"
789 // Chomping: |
790 // Clipped empty lines
791 // """);
792 // });
793 });
794
795 group('6.5: Line Folding', () {
796 // test('[Example 6.6]', () {
797 // expectYamlLoads("trimmed\n\n\nas space", """
798 // >-
799 // trimmed
800
801
802
803 // as
804 // space
805 // """.trim());
806 // });
807
808 // test('[Example 6.7]', () {
809 // expectYamlLoads("foo \n\n\t bar\n\nbaz\n", """
810 // >
811 // foo
812
813 // \t bar
814
815 // baz
816 // """);
817 // });
818
819 // test('[Example 6.8]', () {
820 // expectYamlLoads(" foo\nbar\nbaz ", """
821 // "
822 // foo
823
824 // \t bar
825
826 // baz
827 // "
828 // """);
829 // });
830 });
831
832 group('6.6: Comments', () {
833 test('must be separated from other tokens by white space characters', () {
834 expectYamlLoads("foo#bar", "foo#bar");
835 expectYamlLoads("foo:#bar", "foo:#bar");
836 expectYamlLoads("-#bar", "-#bar");
837 });
838
839 test('[Example 6.9]', () {
840 expectYamlLoads({'key': 'value'}, """
841 key: # Comment
842 value
843 """);
844 });
845
846 group('outside of scalar content', () {
847 test('may appear on a line of their own', () {
848 expectYamlLoads([1, 2], """
849 - 1
850 # Comment
851 - 2
852 """);
853 });
854
855 test('are independent of indentation level', () {
856 expectYamlLoads([[1, 2]], """
857 -
858 - 1
859 # Comment
860 - 2
861 """);
862 });
863
864 test('include lines containing only white space characters', () {
865 expectYamlLoads([1, 2], """
866 - 1
867 \t
868 - 2
869 """);
870 });
871 });
872
873 group('within scalar content', () {
874 // test('may not appear on a line of their own', () {
875 // expectYamlLoads("foo\n# not comment\nbar\n", """
876 // - |
877 // foo
878 // # not comment
879 // bar
880 // """);
881 // });
882
883 // test("don't include lines containing only white space characters", () {
884 // expectYamlLoads("foo\n \t \nbar\n", """
885 // - |
886 // foo
887 // \t
888 // bar
889 // """);
890 // });
891 });
892
893 test('[Example 6.10]', () {
894 expectYamlLoads(null, """
895 # Comment
896
897 """);
898 });
899
900 test('[Example 6.11]', () {
901 expectYamlLoads({'key': 'value'}, """
902 key: # Comment
903 # lines
904 value
905 """);
906 });
907
908 group('ending a block scalar header', () {
909 // test('may not be followed by additional comment lines', () {
910 // expectYamlLoads("# not comment\nfoo\n", """
911 // - | # comment
912 // # not comment
913 // foo
914 // """);
915 // });
916 });
917 });
918
919 group('6.7: Separation Lines', () {
920 // test('may not be used within implicit keys', () {
921 // Expect.throws(() => yaml.load("""
922 // [1,
923 // 2]: 3
924 // """));
925 // });
926
927 // test('[Example 6.12]', () {
928 // var doc = yamlMap();
929 // doc[{'first': 'Sammy', 'last': 'Sosa'}] = {
930 // 'hr': 65,
931 // 'avg': 0.278
932 // };
933 // expectYamlLoads(doc, """
934 // { first: Sammy, last: Sosa }:
935 // # Statistics:
936 // hr: # Home runs
937 // 65
938 // avg: # Average
939 // 0.278
940 // """);
941 // });
942 });
943
944 group('6.8: Directives', () {
945 // // TODO(nweiz): assert that this produces a warning
946 // test('[Example 6.13]', () {
947 // expectYamlLoads("foo", """
948 // %FOO bar baz # Should be ignored
949 // # with a warning.
950 // --- "foo"
951 // """);
952 // });
953
954 // // TODO(nweiz): assert that this produces a warning
955 // test('[Example 6.14]', () {
956 // expectYamlLoads("foo", """
957 // %YAML 1.3 # Attempt parsing
958 // # with a warning
959 // ---
960 // "foo"
961 // """);
962 // });
963
964 // test('[Example 6.15]', () {
965 // Expect.throws(() => yaml.load("""
966 // %YAML 1.2
967 // %YAML 1.1
968 // foo
969 // """));
970 // });
971
972 // test('[Example 6.16]', () {
973 // expectYamlLoads("foo", """
974 // %TAG !yaml! tag:yaml.org,2002:
975 // ---
976 // !yaml!str "foo"
977 // """);
978 // });
979
980 // test('[Example 6.17]', () {
981 // Expect.throws(() => yaml.load("""
982 // %TAG ! !foo
983 // %TAG ! !foo
984 // bar
985 // """));
986 // });
987
988 // Examples 6.18 through 6.22 test custom tag URIs, which this
989 // implementation currently doesn't plan to support.
990 });
991
992 group('6.9: Node Properties', () {
993 // test('may be specified in any order', () {
994 // expectYamlLoads(["foo", "bar"], """
995 // - !!str &a1 foo
996 // - &a2 !!str bar
997 // """);
998 // });
999
1000 // test('[Example 6.23]', () {
1001 // expectYamlLoads({
1002 // "foo": "bar",
1003 // "baz": "foo"
1004 // }, """
1005 // !!str &a1 "foo":
1006 // !!str bar
1007 // &a2 baz : *a1
1008 // """);
1009 // });
1010
1011 // // Example 6.24 tests custom tag URIs, which this implementation currentl y
1012 // // doesn't plan to support.
1013
1014 // test('[Example 6.25]', () {
1015 // Expect.throws(() => yaml.load("- !<!> foo"));
1016 // Expect.throws(() => yaml.load("- !<\$:?> foo"));
1017 // });
1018
1019 // // Examples 6.26 and 6.27 test custom tag URIs, which this implementation
1020 // // currently doesn't plan to support.
1021
1022 // test('[Example 6.28]', () {
1023 // expectYamlLoads(["12", 12, "12"], """
1024 // # Assuming conventional resolution:
1025 // - "12"
1026 // - 12
1027 // - ! 12
1028 // """);
1029 // });
1030
1031 // test('[Example 6.29]', () {
1032 // expectYamlLoads({
1033 // "First occurrence": "Value",
1034 // "Second occurrence": "anchor"
1035 // }, """
1036 // First occurrence: &anchor Value
1037 // Second occurrence: *anchor
1038 // """);
1039 // });
1040 });
1041
1042 // Chapter 7: Flow Styles
1043 group('7.1: Alias Nodes', () {
1044 // test("must not use an anchor that doesn't previously occur", () {
1045 // Expect.throws(() => yaml.load("""
1046 // - *anchor
1047 // - &anchor foo
1048 // """));
1049 // });
1050
1051 // test("don't have to exist for a given anchor node", () {
1052 // expectYamlLoads(["foo"], "- &anchor foo");
1053 // });
1054
1055 // group('must not specify', () {
1056 // test('tag properties', () => Expect.throws(() => yaml.load("""
1057 // - &anchor foo
1058 // - !str *anchor
1059 // """)));
1060
1061 // test('anchor properties', () => Expect.throws(() => yaml.load("""
1062 // - &anchor foo
1063 // - &anchor2 *anchor
1064 // """)));
1065
1066 // test('content', () => Expect.throws(() => yaml.load("""
1067 // - &anchor foo
1068 // - *anchor bar
1069 // """)));
1070 // });
1071
1072 // test('must preserve structural equality', () {
1073 // var doc = yaml.load("""
1074 // anchor: &anchor [a, b, c]
1075 // alias: *anchor
1076 // """);
1077 // var anchorList = doc['anchor'];
1078 // var aliasList = doc['alias'];
1079 // Expect.isTrue(anchorList === aliasList);
1080 // anchorList.add('d');
1081 // Expect.listEquals(['a', 'b', 'c', 'd'], aliasList);
1082
1083 // doc = yaml.load("""
1084 // ? &anchor [a, b, c]
1085 // : ? *anchor
1086 // : bar
1087 // """);
1088 // anchorList = doc.getKeys()[0];
1089 // aliasList = doc[['a', 'b', 'c']].getKeys()[0];
1090 // Expect.isTrue(anchorList === aliasList);
1091 // anchorList.add('d');
1092 // Expect.listEquals(['a', 'b', 'c', 'd'], aliasList);
1093 // });
1094
1095 // test('[Example 7.1]', () {
1096 // expectYamlLoads({
1097 // "First occurence": "Foo",
1098 // "Second occurence": "Foo",
1099 // "Override anchor": "Bar",
1100 // "Reuse anchor": "Bar",
1101 // }, """
1102 // First occurrence: &anchor Foo
1103 // Second occurrence: *anchor
1104 // Override anchor: &anchor Bar
1105 // Reuse anchor: *anchor
1106 // """);
1107 // });
1108 });
1109
1110 group('7.2: Empty Nodes', () {
1111
1112 // test('[Example 7.2]', () {
1113 // expectYamlLoads({
1114 // "foo": "",
1115 // "": "bar"
1116 // }, """
1117 // {
1118 // foo : !!str,
1119 // !!str : bar,
1120 // }
1121 // """);
1122 // });
1123
1124 // test('[Example 7.3]', () {
1125 // var doc = yamlMap({"foo": null});
1126 // doc[null] = "bar";
1127 // expectYamlLoads(doc, """
1128 // {
1129 // ? foo :,
1130 // : bar,
1131 // }
1132 // """);
1133 // });
1134 });
1135
1136 group('7.3: Flow Scalar Styles', () {
1137 // test('[Example 7.4]', () {
1138 // expectYamlLoads({
1139 // "implicit block key": [{"implicit flow key": "value"}]
1140 // }, """
1141 // "implicit block key" : [
1142 // "implicit flow key" : value,
1143 // ]
1144 // """);
1145 // });
1146
1147 // test('[Example 7.5]', () {
1148 // expectYamlLoads(
1149 // "folded to a space,\nto a line feed, or \t \tnon-content", """
1150 // "folded
1151 // to a space,\t
1152
1153 // to a line feed, or \t\\
1154 // \\ \tnon-content"
1155 // """);
1156 // });
1157
1158 // test('[Example 7.6]', () {
1159 // expectYamlLoads(" 1st non-empty\n2nd non-empty 3rd non-empty ", """
1160 // " 1st non-empty
1161
1162 // 2nd non-empty
1163 // \t3rd non-empty "
1164 // """);
1165 // });
1166
1167 // test('[Example 7.7]', () {
1168 // expectYamlLoads("here's to \"quotes\"", "'here''s to \"quotes\"'");
1169 // });
1170
1171 // test('[Example 7.8]', () {
1172 // expectYamlLoads({
1173 // "implicit block key": [{"implicit flow key": "value"}]
1174 // }, """
1175 // 'implicit block key' : [
1176 // 'implicit flow key' : value,
1177 // ]
1178 // """);
1179 // });
1180
1181 // test('[Example 7.9]', () {
1182 // expectYamlLoads(" 1st non-empty\n2nd non-empty 3rd non-empty ", """
1183 // ' 1st non-empty
1184
1185 // 2nd non-empty
1186 // \t3rd non-empty '
1187 // """);
1188 // });
1189
1190 // test('[Example 7.10]', () {
1191 // expectYamlLoads([
1192 // "::vector", ": - ()", "Up, up, and away!", -123,
1193 // "http://example.com/foo#bar",
1194 // [
1195 // "::vector", ": - ()", "Up, up, and away!", -123,
1196 // "http://example.com/foo#bar"
1197 // ]
1198 // ], """
1199 // # Outside flow collection:
1200 // - ::vector
1201 // - ": - ()"
1202 // - Up, up, and away!
1203 // - -123
1204 // - http://example.com/foo#bar
1205 // # Inside flow collection:
1206 // - [ ::vector,
1207 // ": - ()",
1208 // "Up, up and away!",
1209 // -123,
1210 // http://example.com/foo#bar ]
1211 // """);
1212 // });
1213
1214 // test('[Example 7.11]', () {
1215 // expectYamlLoads({
1216 // "implicit block key": [{"implicit flow key": "value"}]
1217 // }, """
1218 // implicit block key : [
1219 // implicit flow key : value,
1220 // ]
1221 // """);
1222 // });
1223
1224 // test('[Example 7.12]', () {
1225 // expectYamlLoads("1st non-empty\n2nd non-empty 3rd non-empty", """
1226 // 1st non-empty
1227
1228 // 2nd non-empty
1229 // \t3rd non-empty
1230 // """);
1231 // });
1232 });
1233
1234 group('7.4: Flow Collection Styles', () {
1235 // test('[Example 7.13]', () {
1236 // expectYamlLoads([
1237 // ['one', 'two'],
1238 // ['three', 'four']
1239 // ], """
1240 // - [ one, two, ]
1241 // - [three ,four]
1242 // """);
1243 // });
1244
1245 // test('[Example 7.14]', () {
1246 // expectYamlLoads([
1247 // "double quoted", "single quoted", "plain text", ["nested"],
1248 // {"single": "pair"}
1249 // ], """
1250 // [
1251 // "double
1252 // quoted", 'single
1253 // quoted',
1254 // plain
1255 // text, [ nested ],
1256 // single: pair,
1257 // ]
1258 // """);
1259 // });
1260
1261 // test('[Example 7.15]', () {
1262 // expectYamlLoads([
1263 // {"one": "two", "three": "four"},
1264 // {"five": "six", "seven": "eight"},
1265 // ], """
1266 // - { one : two , three: four , }
1267 // - {five: six,seven : eight}
1268 // """);
1269 // });
1270
1271 // test('[Example 7.16]', () {
1272 // var doc = yamlMap({
1273 // "explicit": "entry",
1274 // "implicit": "entry"
1275 // });
1276 // doc[null] = null;
1277 // expectYamlLoads(doc, """
1278 // {
1279 // ? explicit: entry,
1280 // implicit: entry,
1281 // ?
1282 // }
1283 // """);
1284 // });
1285
1286 // test('[Example 7.17]', () {
1287 // var doc = yamlMap({
1288 // "unquoted": "separate",
1289 // "http://foo.com": null,
1290 // "omitted value": null
1291 // });
1292 // doc[null] = "omitted key";
1293 // expectYamlLoads(doc, """
1294 // {
1295 // unquoted : "separate",
1296 // http://foo.com,
1297 // omitted value:,
1298 // : omitted key,
1299 // }
1300 // """);
1301 // });
1302
1303 // test('[Example 7.18]', () {
1304 // expectYamlLoads({
1305 // "adjacent": "value",
1306 // "readable": "value",
1307 // "empty": null
1308 // }, """
1309 // {
1310 // "adjacent":value,
1311 // "readable": value,
1312 // "empty":
1313 // }
1314 // """);
1315 // });
1316
1317 // test('[Example 7.19]', () {
1318 // expectYamlLoads([{"foo": "bar"}], """
1319 // [
1320 // foo: bar
1321 // ]
1322 // """);
1323 // });
1324
1325 // test('[Example 7.20]', () {
1326 // expectYamlLoads([{"foo bar": "baz"}], """
1327 // [
1328 // ? foo
1329 // bar : baz
1330 // ]
1331 // """);
1332 // });
1333
1334 // test('[Example 7.21]', () {
1335 // var el1 = yamlMap();
1336 // el1[null] = "empty key array";
1337
1338 // var el2 = yamlMap();
1339 // el2[{"JSON": "like"}] = "adjacent";
1340 // expectYamlLoads([[{"YAML": "separate"}], [el1], [el2]], """
1341 // - [ YAML : separate ]
1342 // - [ : empty key entry ]
1343 // - [ {JSON: like}:adjacent ]
1344 // """);
1345 // });
1346
1347 // test('[Example 7.22]', () {
1348 // Expect.throws(() => yaml.load("""
1349 // [ foo
1350 // bar: invalid ]
1351 // """));
1352
1353 // var dotList = [];
1354 // dotList.insertRange(0, 1024, ' ');
1355 // var dots = Strings.join(dotList, '');
1356 // Expect.throws(() => yaml.load('[ "foo...$dots...bar": invalid ]'));
1357 // });
1358 });
1359
1360 group('7.5: Flow Nodes', () {
1361 // test('[Example 7.23]', () {
1362 // expectYamlLoads([["a", "b"], {"a": "b"}, "a", "b", "c"], """
1363 // - [ a, b ]
1364 // - { a: b }
1365 // - "a"
1366 // - 'b'
1367 // - c
1368 // """);
1369 // });
1370
1371 // test('[Example 7.24]', () {
1372 // expectYamlLoads(["a", "b", "c", "c", ""], """
1373 // - !!str "a"
1374 // - 'b'
1375 // - &anchor "c"
1376 // - *anchor
1377 // - !!str
1378 // """);
1379 // });
1380 });
1381
1382 // Chapter 8: Block Styles
1383 group('8.1: Block Scalar Styles', () {
1384 // test('[Example 8.1]', () {
1385 // expectYamlLoads(["literal\n", " folded\n", "keep\n\n", " strip"], """
1386 // - | # Empty header
1387 // literal
1388 // - >1 # Indentation indicator
1389 // folded
1390 // - |+ # Chomping indicator
1391 // keep
1392
1393 // - >1- # Both indicators
1394 // strip
1395 // """);
1396 // });
1397
1398 // test('[Example 8.2]', () {
1399 // expectYamlLoads([
1400 // "detected\n",
1401 // "\n\n# detected\n",
1402 // " explicit\n",
1403 // "\t detected\n"
1404 // ], """
1405 // - |
1406 // detected
1407 // - >
1408
1409
1410 // # detected
1411 // - |1
1412 // explicit
1413 // - >
1414 // \t
1415 // detected
1416 // """);
1417 // });
1418
1419 // test('[Example 8.3]', () {
1420 // Expect.throws(() => yaml.load("""
1421 // - |
1422
1423 // text
1424 // """));
1425
1426 // Expect.throws(() => yaml.load("""
1427 // - >
1428 // text
1429 // text
1430 // """));
1431
1432 // Expect.throws(() => yaml.load("""
1433 // - |2
1434 // text
1435 // """));
1436 // });
1437
1438 // test('[Example 8.4]', () {
1439 // expectYamlLoads({"strip": "text", "clip": "text\n", "keep": "text\n"}, """
1440 // strip: |-
1441 // text
1442 // clip: |
1443 // text
1444 // keep: |+
1445 // text
1446 // """);
1447 // });
1448
1449 // test('[Example 8.5]', () {
1450 // expectYamlLoads({
1451 // "strip": "# text",
1452 // "clip": "# text\n",
1453 // "keep": "# text\n"
1454 // }, """
1455 // # Strip
1456 // # Comments:
1457 // strip: |-
1458 // # text
1459
1460 // # Clip
1461 // # comments:
1462
1463 // clip: |
1464 // # text
1465
1466 // # Keep
1467 // # comments:
1468
1469 // keep: |+
1470 // # text
1471
1472 // # Trail
1473 // # comments.
1474 // """);
1475 // });
1476
1477 // test('[Example 8.6]', () {
1478 // expectYamlLoads({"strip": "", "clip": "", "keep": "\n"}, """
1479 // strip: >-
1480
1481 // clip: >
1482
1483 // keep: |+
1484
1485 // """);
1486 // });
1487
1488 // test('[Example 8.7]', () {
1489 // expectYamlLoads("literal\n\ttext\n", """
1490 // |
1491 // literal
1492 // \ttext
1493
1494 // """);
1495 // });
1496
1497 // test('[Example 8.8]', () {
1498 // expectYamlLoads("\n\nliteral\n \n\ntext\n", """
1499 // |
1500
1501
1502 // literal
1503
1504
1505 // text
1506
1507 // # Comment
1508 // """);
1509 // });
1510
1511 // test('[Example 8.9]', () {
1512 // expectYamlLoads("folded text\n", """
1513 // >
1514 // folded
1515 // text
1516
1517 // """);
1518 // });
1519
1520 // test('[Example 8.10]', () {
1521 // expectYamlLoads("""
1522 // folded line
1523 // next line
1524 // * bullet
1525
1526 // * list
1527 // * lines
1528
1529 // last line
1530 // """, """
1531 // >
1532
1533 // folded
1534 // line
1535
1536 // next
1537 // line
1538 // * bullet
1539
1540 // * list
1541 // * lines
1542
1543 // last
1544 // line
1545
1546 // # Comment
1547 // """);
1548 // });
1549
1550 // Examples 8.11 through 8.13 are duplicates of 8.10.
1551 });
1552
1553 group('8.2: Block Collection Styles', () {
1554 test('[Example 8.14]', () {
1555 expectYamlLoads({"block sequence": ["one", {"two": "three"}]}, """
1556 block sequence:
1557 - one
1558 - two : three
1559 """);
1560 });
1561
1562 // test('[Example 8.15]', () {
1563 // expectYamlLoads([
1564 // null, "block node\n", ["one", "two"], [{"one": "two"}]
1565 // ], """
1566 // - # Empty
1567 // - |
1568 // block node
1569 // - - one # Compact
1570 // - two # sequence
1571 // - one: two # Compact mapping
1572 // """);
1573 // });
1574
1575 test('[Example 8.16]', () {
1576 expectYamlLoads({"block mapping": {"key": "value"}}, """
1577 block mapping:
1578 key: value
1579 """);
1580 });
1581
1582 // test('[Example 8.17]', () {
1583 // expectYamlLoads({
1584 // "explicit key": null,
1585 // "block key\n": ["one", "two"]
1586 // }, """
1587 // ? explicit key # Empty value
1588 // ? |
1589 // block key
1590 // : - one # Explicit compact
1591 // - two # block value
1592 // """);
1593 // });
1594
1595 // test('[Example 8.18]', () {
1596 // var doc = yamlMap({
1597 // 'plain key': 'in-line value',
1598 // "quoted key": ["entry"]
1599 // });
1600 // doc[null] = null;
1601 // expectYamlLoads(doc, """
1602 // plain key: in-line value
1603 // : # Both empty
1604 // "quoted key":
1605 // - entry
1606 // """);
1607 // });
1608
1609 // test('[Example 8.19]', () {
1610 // var el = yamlMap();
1611 // el[{'earth': 'blue'}] = {'moon': 'white'};
1612 // expectYamlLoads([{'sun': 'yellow'}, el], """
1613 // - sun: yellow
1614 // - ? earth: blue
1615 // : moon: white
1616 // """);
1617 // });
1618
1619 // test('[Example 8.20]', () {
1620 // expectYamlLoads(["flow in block", "Block scalar\n", {"foo": "bar"}], "" "
1621 // -
1622 // "flow in block"
1623 // - >
1624 // Block scalar
1625 // - !!map # Block collection
1626 // foo : bar
1627 // """);
1628 // });
1629
1630 // test('[Example 8.21]', () {
1631 // expectYamlLoads({"literal": "value", "folded": "value"}, """
1632 // literal: |2
1633 // value
1634 // folded:
1635 // !!str
1636 // >1
1637 // value
1638 // """);
1639 // });
1640
1641 // test('[Example 8.22]', () {
1642 // expectYamlLoads({
1643 // "sequence": ["entry", ["nested"]],
1644 // "mapping": {"foo": "bar"}
1645 // }, """
1646 // sequence: !!seq
1647 // - entry
1648 // - !!seq
1649 // - nested
1650 // mapping: !!map
1651 // foo: bar
1652 // """);
1653 // });
1654 });
1655
1656 // Chapter 9: YAML Character Stream
1657 group('9.1: Documents', () {
1658 // Example 9.1 tests the use of a BOM, which this implementation currently
1659 // doesn't plan to support.
1660
1661 // test('[Example 9.2]', () {
1662 // expectYamlLoads("Document", """
1663 // %YAML 1.2
1664 // ---
1665 // Document
1666 // ... # Suffix
1667 // """);
1668 // });
1669
1670 // test('[Example 9.3]', () {
1671 // expectYamlStreamLoads(["Bare Document", "%!PS-Adobe-2.0\n"], """
1672 // Bare
1673 // document
1674 // ...
1675 // # No document
1676 // ...
1677 // |
1678 // %!PS-Adobe-2.0 # Not the first line
1679 // """);
1680 // });
1681
1682 // test('[Example 9.4]', () {
1683 // expectYamlStreamLoads([{"matches %": 20}, null], """
1684 // ---
1685 // { matches
1686 // % : 20 }
1687 // ...
1688 // ---
1689 // # Empty
1690 // ...
1691 // """);
1692 // });
1693
1694 // test('[Example 9.5]', () {
1695 // expectYamlStreamLoads(["%!PS-Adobe-2.0\n", null], """
1696 // %YAML 1.2
1697 // --- |
1698 // %!PS-Adobe-2.0
1699 // ...
1700 // %YAML1.2
1701 // ---
1702 // # Empty
1703 // ...
1704 // """);
1705 // });
1706
1707 // test('[Example 9.6]', () {
1708 // expectYamlStreamLoads(["Document", null, {"matches %": 20}], """
1709 // Document
1710 // ---
1711 // # Empty
1712 // ...
1713 // %YAML 1.2
1714 // ---
1715 // matches %: 20
1716 // """);
1717 // });
1718 });
1719
1720 // Chapter 10: Recommended Schemas
1721 group('10.1: Failsafe Schema', () {
1722 // test('[Example 10.1]', () {
1723 // expectYamlStreamLoads({
1724 // "Block style": {
1725 // "Clark": "Evans",
1726 // "Ingy": "döt Net",
1727 // "Oren": "Ben-Kiki"
1728 // },
1729 // "Flow style": {
1730 // "Clark": "Evans",
1731 // "Ingy": "döt Net",
1732 // "Oren": "Ben-Kiki"
1733 // }
1734 // }, """
1735 // Block style: !!map
1736 // Clark : Evans
1737 // Ingy : döt Net
1738 // Oren : Ben-Kiki
1739
1740 // Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki }
1741 // """);
1742 // });
1743
1744 // test('[Example 10.2]', () {
1745 // expectYamlStreamLoads({
1746 // "Block style": ["Clark Evans", "Ingy döt Net", "Oren Ben-Kiki"],
1747 // "Flow style": ["Clark Evans", "Ingy döt Net", "Oren Ben-Kiki"]
1748 // }, """
1749 // Block style: !!seq
1750 // - Clark Evans
1751 // - Ingy döt Net
1752 // - Oren Ben-Kiki
1753
1754 // Flow style: !!seq [ Clark Evans, Ingy döt Net, Oren Ben-Kiki ]
1755 // """);
1756 // });
1757
1758 // test('[Example 10.3]', () {
1759 // expectYamlStreamLoads({
1760 // "Block style": "String: just a theory.",
1761 // "Flow style": "String: just a theory."
1762 // }, """
1763 // Block style: !!str |-
1764 // String: just a theory.
1765
1766 // Flow style: !!str "String: just a theory."
1767 // """);
1768 // });
1769 });
1770
1771 group('10.2: JSON Schema', () {
1772 // test('[Example 10.4]', () {
1773 // var doc = yamlMap({"key with null value": null});
1774 // doc[null] = "value for null key";
1775 // expectYamlStreamLoads(doc, """
1776 // !!null null: value for null key
1777 // key with null value: !!null null
1778 // """);
1779 // });
1780
1781 // test('[Example 10.5]', () {
1782 // expectYamlStreamLoads({
1783 // "YAML is a superset of JSON": true,
1784 // "Pluto is a planet": false
1785 // }, """
1786 // YAML is a superset of JSON: !!bool true
1787 // Pluto is a planet: !!bool false
1788 // """);
1789 // });
1790
1791 // test('[Example 10.6]', () {
1792 // expectYamlStreamLoads({
1793 // "negative": -12,
1794 // "zero": 0,
1795 // "positive": 34
1796 // }, """
1797 // negative: !!int -12
1798 // zero: !!int 0
1799 // positive: !!int 34
1800 // """);
1801 // });
1802
1803 // test('[Example 10.7]', () {
1804 // expectYamlStreamLoads({
1805 // "negative": -1,
1806 // "zero": 0,
1807 // "positive": 23000,
1808 // "infinity": infinity,
1809 // "not a number": nan
1810 // }, """
1811 // negative: !!float -1
1812 // zero: !!float 0
1813 // positive: !!float 2.3e4
1814 // infinity: !!float .inf
1815 // not a number: !!float .nan
1816 // """);
1817 // });
1818
1819 // test('[Example 10.8]', () {
1820 // expectYamlStreamLoads({
1821 // "A null": null,
1822 // "Booleans": [true, false],
1823 // "Integers": [0, -0, 3, -19],
1824 // "Floats": [0, 0, 12000, -200000],
1825 // // Despite being invalid in the JSON schema, these values are valid i n
1826 // // the core schema which this implementation supports.
1827 // "Invalid": [ true, null, 7, 0x3A, 12.3]
1828 // }, """
1829 // A null: null
1830 // Booleans: [ true, false ]
1831 // Integers: [ 0, -0, 3, -19 ]
1832 // Floats: [ 0., -0.0, 12e03, -2E+05 ]
1833 // Invalid: [ True, Null, 0o7, 0x3A, +12.3 ]
1834 // """);
1835 // });
1836 });
1837
1838 group('10.3: Core Schema', () {
1839 // test('[Example 10.9]', () {
1840 // expectYamlStreamLoads({
1841 // "A null": null,
1842 // "Also a null": null,
1843 // "Not a null": "",
1844 // "Booleans": [true, true, false, false],
1845 // "Integers": [0, 7, 0x3A, -19],
1846 // "Floats": [0, 0, 0.5, 12000, -200000],
1847 // "Also floats": [infinity, -infinity, infinity, nan]
1848 // }, """
1849 // A null: null
1850 // Also a null: # Empty
1851 // Not a null: ""
1852 // Booleans: [ true, True, false, FALSE ]
1853 // Integers: [ 0, 0o7, 0x3A, -19 ]
1854 // Floats: [ 0., -0.0, .5, +12e03, -2E+05 ]
1855 // Also floats: [ .inf, -.Inf, +.INF, .NAN ]
1856 // """);
1857 // });
1858 });
1859 }
OLDNEW
« no previous file with comments | « tests/lib/lib.status ('k') | tools/test.dart » ('j') | utils/yaml/composer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698