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

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

Powered by Google App Engine
This is Rietveld 408576698