OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library yaml.test; | 5 library yaml.test; |
6 | 6 |
7 // TODO(rnystrom): rewrite tests so that they don't need "Expect". | |
8 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
9 import 'package:yaml/yaml.dart'; | 8 import 'package:yaml/yaml.dart'; |
10 | 9 |
11 import 'utils.dart'; | 10 import 'utils.dart'; |
12 | 11 |
13 main() { | 12 main() { |
14 var infinity = double.parse("Infinity"); | 13 var infinity = double.parse("Infinity"); |
15 var nan = double.parse("NaN"); | 14 var nan = double.parse("NaN"); |
16 | 15 |
17 group('has a friendly error message for', () { | 16 group('has a friendly error message for', () { |
18 var tabError = predicate((e) => | 17 var tabError = predicate((e) => |
19 e.toString().contains('tab characters are not allowed as indentation')); | 18 e.toString().contains('Tab characters are not allowed as indentation')); |
20 | 19 |
21 test('using a tab as indentation', () { | 20 test('using a tab as indentation', () { |
22 expect(() => loadYaml('foo:\n\tbar'), | 21 expect(() => loadYaml('foo:\n\tbar'), |
23 throwsA(tabError)); | 22 throwsA(tabError)); |
24 }); | 23 }); |
25 | 24 |
26 test('using a tab not as indentation', () { | 25 test('using a tab not as indentation', () { |
27 expect(() => loadYaml(''' | 26 expect(() => loadYaml(''' |
28 "foo | 27 "foo |
29 \tbar" | 28 \tbar" |
30 error'''), | 29 error'''), |
31 throwsA(isNot(tabError))); | 30 throwsA(isNot(tabError))); |
32 }); | 31 }); |
33 }); | 32 }); |
34 | 33 |
| 34 group("refuses documents that declare version", () { |
| 35 test("1.0", () { |
| 36 expectYamlFails(""" |
| 37 %YAML 1.0 |
| 38 --- text |
| 39 """); |
| 40 }); |
| 41 |
| 42 test("1.3", () { |
| 43 expectYamlFails(""" |
| 44 %YAML 1.3 |
| 45 --- text |
| 46 """); |
| 47 }); |
| 48 |
| 49 test("2.0", () { |
| 50 expectYamlFails(""" |
| 51 %YAML 2.0 |
| 52 --- text |
| 53 """); |
| 54 }); |
| 55 }); |
| 56 |
35 // The following tests are all taken directly from the YAML spec | 57 // The following tests are all taken directly from the YAML spec |
36 // (http://www.yaml.org/spec/1.2/spec.html). Most of them are code examples | 58 // (http://www.yaml.org/spec/1.2/spec.html). Most of them are code examples |
37 // that are directly included in the spec, but additional tests are derived | 59 // that are directly included in the spec, but additional tests are derived |
38 // from the prose. | 60 // from the prose. |
39 | 61 |
40 // A few examples from the spec are deliberately excluded, because they test | 62 // A few examples from the spec are deliberately excluded, because they test |
41 // features that this implementation doesn't intend to support (character | 63 // features that this implementation doesn't intend to support (character |
42 // encoding detection and user-defined tags). More tests are commented out, | 64 // encoding detection and user-defined tags). More tests are commented out, |
43 // because they're intended to be supported but not yet implemented. | 65 // because they're intended to be supported but not yet implemented. |
44 | 66 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 --- | 188 --- |
167 hr: # 1998 hr ranking | 189 hr: # 1998 hr ranking |
168 - Mark McGwire | 190 - Mark McGwire |
169 - Sammy Sosa | 191 - Sammy Sosa |
170 rbi: | 192 rbi: |
171 # 1998 rbi ranking | 193 # 1998 rbi ranking |
172 - Sammy Sosa | 194 - Sammy Sosa |
173 - Ken Griffey"""); | 195 - Ken Griffey"""); |
174 }); | 196 }); |
175 | 197 |
176 // test('[Example 2.10]', () { | 198 test('[Example 2.10]', () { |
177 // expectYamlLoads({ | 199 expectYamlLoads({ |
178 // "hr": ["Mark McGwire", "Sammy Sosa"], | 200 "hr": ["Mark McGwire", "Sammy Sosa"], |
179 // "rbi": ["Sammy Sosa", "Ken Griffey"] | 201 "rbi": ["Sammy Sosa", "Ken Griffey"] |
180 // }, | 202 }, |
181 // """ | 203 """ |
182 // --- | 204 --- |
183 // hr: | 205 hr: |
184 // - Mark McGwire | 206 - Mark McGwire |
185 // # Following node labeled SS | 207 # Following node labeled SS |
186 // - &SS Sammy Sosa | 208 - &SS Sammy Sosa |
187 // rbi: | 209 rbi: |
188 // - *SS # Subsequent occurrence | 210 - *SS # Subsequent occurrence |
189 // - Ken Griffey"""); | 211 - Ken Griffey"""); |
190 // }); | 212 }); |
191 | 213 |
192 test('[Example 2.11]', () { | 214 test('[Example 2.11]', () { |
193 var doc = deepEqualsMap(); | 215 var doc = deepEqualsMap(); |
194 doc[["Detroit Tigers", "Chicago cubs"]] = ["2001-07-23"]; | 216 doc[["Detroit Tigers", "Chicago cubs"]] = ["2001-07-23"]; |
195 doc[["New York Yankees", "Atlanta Braves"]] = | 217 doc[["New York Yankees", "Atlanta Braves"]] = |
196 ["2001-07-02", "2001-08-12", "2001-08-14"]; | 218 ["2001-07-02", "2001-08-12", "2001-08-14"]; |
197 expectYamlLoads(doc, | 219 expectYamlLoads(doc, |
198 """ | 220 """ |
199 ? - Detroit Tigers | 221 ? - Detroit Tigers |
200 - Chicago cubs | 222 - Chicago cubs |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 expectYamlLoads({ | 551 expectYamlLoads({ |
530 'single': "text", | 552 'single': "text", |
531 'double': "text" | 553 'double': "text" |
532 }, | 554 }, |
533 """ | 555 """ |
534 single: 'text' | 556 single: 'text' |
535 double: "text" | 557 double: "text" |
536 """); | 558 """); |
537 }); | 559 }); |
538 | 560 |
539 // test('[Example 5.9]', () { | 561 test('[Example 5.9]', () { |
540 // expectYamlLoads("text", | 562 expectYamlLoads("text", |
541 // """ | 563 """ |
542 // %YAML 1.2 | 564 %YAML 1.2 |
543 // --- text"""); | 565 --- text"""); |
544 // }); | 566 }); |
545 | 567 |
546 test('[Example 5.10]', () { | 568 test('[Example 5.10]', () { |
547 expectYamlFails("commercial-at: @text"); | 569 expectYamlFails("commercial-at: @text"); |
548 expectYamlFails("commercial-at: `text"); | 570 expectYamlFails("commercial-at: `text"); |
549 }); | 571 }); |
550 }); | 572 }); |
551 | 573 |
552 group('5.4: Line Break Characters', () { | 574 group('5.4: Line Break Characters', () { |
553 group('include', () { | 575 group('include', () { |
554 test('\\n', () => expectYamlLoads([1, 2], indentLiteral("- 1\n- 2"))); | 576 test('\\n', () => expectYamlLoads([1, 2], indentLiteral("- 1\n- 2"))); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 { first: Sammy, last: Sosa }: | 901 { first: Sammy, last: Sosa }: |
880 # Statistics: | 902 # Statistics: |
881 hr: # Home runs | 903 hr: # Home runs |
882 65 | 904 65 |
883 avg: # Average | 905 avg: # Average |
884 0.278"""); | 906 0.278"""); |
885 }); | 907 }); |
886 }); | 908 }); |
887 | 909 |
888 group('6.8: Directives', () { | 910 group('6.8: Directives', () { |
889 // // TODO(nweiz): assert that this produces a warning | 911 // TODO(nweiz): assert that this produces a warning |
890 // test('[Example 6.13]', () { | 912 test('[Example 6.13]', () { |
891 // expectYamlLoads("foo", | 913 expectYamlLoads("foo", |
892 // ''' | 914 ''' |
893 // %FOO bar baz # Should be ignored | 915 %FOO bar baz # Should be ignored |
894 // # with a warning. | 916 # with a warning. |
895 // --- "foo"'''); | 917 --- "foo"'''); |
896 // }); | 918 }); |
897 | 919 |
898 // // TODO(nweiz): assert that this produces a warning | 920 // TODO(nweiz): assert that this produces a warning. |
899 // test('[Example 6.14]', () { | 921 test('[Example 6.14]', () { |
900 // expectYamlLoads("foo", | 922 expectYamlLoads("foo", |
901 // ''' | 923 ''' |
902 // %YAML 1.3 # Attempt parsing | 924 %YAML 1.3 # Attempt parsing |
903 // # with a warning | 925 # with a warning |
904 // --- | 926 --- |
905 // "foo"'''); | 927 "foo"'''); |
906 // }); | 928 }); |
907 | 929 |
908 // test('[Example 6.15]', () { | 930 test('[Example 6.15]', () { |
909 // expectYamlFails( | 931 expectYamlFails( |
910 // """ | 932 """ |
911 // %YAML 1.2 | 933 %YAML 1.2 |
912 // %YAML 1.1 | 934 %YAML 1.1 |
913 // foo"""); | 935 foo"""); |
914 // }); | 936 }); |
915 | 937 |
916 // test('[Example 6.16]', () { | 938 test('[Example 6.16]', () { |
917 // expectYamlLoads("foo", | 939 expectYamlLoads("foo", |
918 // ''' | 940 ''' |
919 // %TAG !yaml! tag:yaml.org,2002: | 941 %TAG !yaml! tag:yaml.org,2002: |
920 // --- | 942 --- |
921 // !yaml!str "foo"'''); | 943 !yaml!str "foo"'''); |
922 // }); | 944 }); |
923 | 945 |
924 // test('[Example 6.17]', () { | 946 test('[Example 6.17]', () { |
925 // ExpectYamlFails( | 947 expectYamlFails( |
926 // """ | 948 """ |
927 // %TAG ! !foo | 949 %TAG ! !foo |
928 // %TAG ! !foo | 950 %TAG ! !foo |
929 // bar"""); | 951 bar"""); |
930 // }); | 952 }); |
931 | 953 |
932 // Examples 6.18 through 6.22 test custom tag URIs, which this | 954 // Examples 6.18 through 6.22 test custom tag URIs, which this |
933 // implementation currently doesn't plan to support. | 955 // implementation currently doesn't plan to support. |
934 }); | 956 }); |
935 | 957 |
936 group('6.9: Node Properties', () { | 958 group('6.9: Node Properties', () { |
937 // test('may be specified in any order', () { | 959 test('may be specified in any order', () { |
938 // expectYamlLoads(["foo", "bar"], | 960 expectYamlLoads(["foo", "bar"], |
939 // """ | 961 """ |
940 // - !!str &a1 foo | 962 - !!str &a1 foo |
941 // - &a2 !!str bar"""); | 963 - &a2 !!str bar"""); |
942 // }); | 964 }); |
943 | 965 |
944 // test('[Example 6.23]', () { | 966 test('[Example 6.23]', () { |
945 // expectYamlLoads({ | 967 expectYamlLoads({ |
946 // "foo": "bar", | 968 "foo": "bar", |
947 // "baz": "foo" | 969 "baz": "foo" |
948 // }, | 970 }, |
949 // ''' | 971 ''' |
950 // !!str &a1 "foo": | 972 !!str &a1 "foo": |
951 // !!str bar | 973 !!str bar |
952 // &a2 baz : *a1'''); | 974 &a2 baz : *a1'''); |
953 // }); | 975 }); |
954 | 976 |
955 // // Example 6.24 tests custom tag URIs, which this implementation currentl
y | 977 // Example 6.24 tests custom tag URIs, which this implementation currently |
956 // // doesn't plan to support. | 978 // doesn't plan to support. |
957 | 979 |
958 // test('[Example 6.25]', () { | 980 test('[Example 6.25]', () { |
959 // expectYamlFails("- !<!> foo"); | 981 expectYamlFails("- !<!> foo"); |
960 // expectYamlFails("- !<\$:?> foo"); | 982 expectYamlFails("- !<\$:?> foo"); |
961 // }); | 983 }); |
962 | 984 |
963 // // Examples 6.26 and 6.27 test custom tag URIs, which this implementation | 985 // Examples 6.26 and 6.27 test custom tag URIs, which this implementation |
964 // // currently doesn't plan to support. | 986 // currently doesn't plan to support. |
965 | 987 |
966 // test('[Example 6.28]', () { | 988 test('[Example 6.28]', () { |
967 // expectYamlLoads(["12", 12, "12"], | 989 expectYamlLoads(["12", 12, "12"], |
968 // ''' | 990 ''' |
969 // # Assuming conventional resolution: | 991 # Assuming conventional resolution: |
970 // - "12" | 992 - "12" |
971 // - 12 | 993 - 12 |
972 // - ! 12'''); | 994 - ! 12'''); |
973 // }); | 995 }); |
974 | 996 |
975 // test('[Example 6.29]', () { | 997 test('[Example 6.29]', () { |
976 // expectYamlLoads({ | 998 expectYamlLoads({ |
977 // "First occurrence": "Value", | 999 "First occurrence": "Value", |
978 // "Second occurrence": "anchor" | 1000 "Second occurrence": "Value" |
979 // }, | 1001 }, |
980 // """ | 1002 """ |
981 // First occurrence: &anchor Value | 1003 First occurrence: &anchor Value |
982 // Second occurrence: *anchor"""); | 1004 Second occurrence: *anchor"""); |
983 // }); | 1005 }); |
984 }); | 1006 }); |
985 | 1007 |
986 // Chapter 7: Flow Styles | 1008 // Chapter 7: Flow Styles |
987 group('7.1: Alias Nodes', () { | 1009 group('7.1: Alias Nodes', () { |
988 // test("must not use an anchor that doesn't previously occur", () { | 1010 test("must not use an anchor that doesn't previously occur", () { |
989 // expectYamlFails( | 1011 expectYamlFails( |
990 // """ | 1012 """ |
991 // - *anchor | 1013 - *anchor |
992 // - &anchor foo"""); | 1014 - &anchor foo"""); |
993 // }); | 1015 }); |
994 | 1016 |
995 // test("don't have to exist for a given anchor node", () { | 1017 test("don't have to exist for a given anchor node", () { |
996 // expectYamlLoads(["foo"], "- &anchor foo"); | 1018 expectYamlLoads(["foo"], "- &anchor foo"); |
997 // }); | 1019 }); |
998 | 1020 |
999 // group('must not specify', () { | 1021 group('must not specify', () { |
1000 // test('tag properties', () => expectYamlFails( | 1022 test('tag properties', () => expectYamlFails( |
1001 // """ | 1023 """ |
1002 // - &anchor foo | 1024 - &anchor foo |
1003 // - !str *anchor"""); | 1025 - !str *anchor""")); |
1004 | 1026 |
1005 // test('anchor properties', () => expectYamlFails( | 1027 test('anchor properties', () => expectYamlFails( |
1006 // """ | 1028 """ |
1007 // - &anchor foo | 1029 - &anchor foo |
1008 // - &anchor2 *anchor"""); | 1030 - &anchor2 *anchor""")); |
1009 | 1031 |
1010 // test('content', () => expectYamlFails( | 1032 test('content', () => expectYamlFails( |
1011 // """ | 1033 """ |
1012 // - &anchor foo | 1034 - &anchor foo |
1013 // - *anchor bar"""))); | 1035 - *anchor bar""")); |
1014 // }); | 1036 }); |
1015 | 1037 |
1016 // test('must preserve structural equality', () { | 1038 test('must preserve structural equality', () { |
1017 // var doc = loadYaml(cleanUpLiteral( | 1039 var doc = loadYaml(cleanUpLiteral( |
1018 // """ | 1040 """ |
1019 // anchor: &anchor [a, b, c] | 1041 anchor: &anchor [a, b, c] |
1020 // alias: *anchor"""); | 1042 alias: *anchor""")); |
1021 // var anchorList = doc['anchor']; | 1043 var anchorList = doc['anchor']; |
1022 // var aliasList = doc['alias']; | 1044 var aliasList = doc['alias']; |
1023 // expect(anchorList, same(aliasList)); | 1045 expect(anchorList, same(aliasList)); |
1024 | 1046 |
1025 // doc = loadYaml(cleanUpLiteral( | 1047 doc = loadYaml(cleanUpLiteral( |
1026 // """ | 1048 """ |
1027 // ? &anchor [a, b, c] | 1049 ? &anchor [a, b, c] |
1028 // : ? *anchor | 1050 : ? *anchor |
1029 // : bar"""); | 1051 : bar""")); |
1030 // anchorList = doc.keys[0]; | 1052 anchorList = doc.keys.first; |
1031 // aliasList = doc[['a', 'b', 'c']].keys[0]; | 1053 aliasList = doc[['a', 'b', 'c']].keys.first; |
1032 // expect(anchorList, same(aliasList)); | 1054 expect(anchorList, same(aliasList)); |
1033 // }); | 1055 }); |
1034 | 1056 |
1035 // test('[Example 7.1]', () { | 1057 test('[Example 7.1]', () { |
1036 // expectYamlLoads({ | 1058 expectYamlLoads({ |
1037 // "First occurence": "Foo", | 1059 "First occurrence": "Foo", |
1038 // "Second occurence": "Foo", | 1060 "Second occurrence": "Foo", |
1039 // "Override anchor": "Bar", | 1061 "Override anchor": "Bar", |
1040 // "Reuse anchor": "Bar", | 1062 "Reuse anchor": "Bar", |
1041 // }, | 1063 }, |
1042 // """ | 1064 """ |
1043 // First occurrence: &anchor Foo | 1065 First occurrence: &anchor Foo |
1044 // Second occurrence: *anchor | 1066 Second occurrence: *anchor |
1045 // Override anchor: &anchor Bar | 1067 Override anchor: &anchor Bar |
1046 // Reuse anchor: *anchor"""); | 1068 Reuse anchor: *anchor"""); |
1047 // }); | 1069 }); |
1048 }); | 1070 }); |
1049 | 1071 |
1050 group('7.2: Empty Nodes', () { | 1072 group('7.2: Empty Nodes', () { |
1051 // test('[Example 7.2]', () { | 1073 test('[Example 7.2]', () { |
1052 // expectYamlLoads({ | 1074 expectYamlLoads({ |
1053 // "foo": "", | 1075 "foo": "", |
1054 // "": "bar" | 1076 "": "bar" |
1055 // }, | 1077 }, |
1056 // """ | 1078 """ |
1057 // { | 1079 { |
1058 // foo : !!str, | 1080 foo : !!str, |
1059 // !!str : bar, | 1081 !!str : bar, |
1060 // }"""); | 1082 }"""); |
1061 // }); | 1083 }); |
1062 | 1084 |
1063 test('[Example 7.3]', () { | 1085 test('[Example 7.3]', () { |
1064 var doc = deepEqualsMap({"foo": null}); | 1086 var doc = deepEqualsMap({"foo": null}); |
1065 doc[null] = "bar"; | 1087 doc[null] = "bar"; |
1066 expectYamlLoads(doc, | 1088 expectYamlLoads(doc, |
1067 """ | 1089 """ |
1068 { | 1090 { |
1069 ? foo :, | 1091 ? foo :, |
1070 : bar, | 1092 : bar, |
1071 }"""); | 1093 }"""); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 var el2 = deepEqualsMap(); | 1299 var el2 = deepEqualsMap(); |
1278 el2[{"JSON": "like"}] = "adjacent"; | 1300 el2[{"JSON": "like"}] = "adjacent"; |
1279 | 1301 |
1280 expectYamlLoads([[{"YAML": "separate"}], [el1], [el2]], | 1302 expectYamlLoads([[{"YAML": "separate"}], [el1], [el2]], |
1281 """ | 1303 """ |
1282 - [ YAML : separate ] | 1304 - [ YAML : separate ] |
1283 - [ : empty key entry ] | 1305 - [ : empty key entry ] |
1284 - [ {JSON: like}:adjacent ]"""); | 1306 - [ {JSON: like}:adjacent ]"""); |
1285 }); | 1307 }); |
1286 | 1308 |
1287 test('[Example 7.22]', () { | 1309 // TODO(nweiz): enable this when we throw an error for long or multiline |
1288 expectYamlFails( | 1310 // keys. |
1289 """ | 1311 // test('[Example 7.22]', () { |
1290 [ foo | 1312 // expectYamlFails( |
1291 bar: invalid ]"""); | 1313 // """ |
1292 | 1314 // [ foo |
1293 // TODO(nweiz): enable this when we throw an error for long keys | 1315 // bar: invalid ]"""); |
1294 // var dotList = new List.filled(1024, ' '); | 1316 // |
1295 // var dots = dotList.join(); | 1317 // var dotList = new List.filled(1024, ' '); |
1296 // expectYamlFails('[ "foo...$dots...bar": invalid ]'); | 1318 // var dots = dotList.join(); |
1297 }); | 1319 // expectYamlFails('[ "foo...$dots...bar": invalid ]'); |
| 1320 // }); |
1298 }); | 1321 }); |
1299 | 1322 |
1300 group('7.5: Flow Nodes', () { | 1323 group('7.5: Flow Nodes', () { |
1301 test('[Example 7.23]', () { | 1324 test('[Example 7.23]', () { |
1302 expectYamlLoads([["a", "b"], {"a": "b"}, "a", "b", "c"], | 1325 expectYamlLoads([["a", "b"], {"a": "b"}, "a", "b", "c"], |
1303 """ | 1326 """ |
1304 - [ a, b ] | 1327 - [ a, b ] |
1305 - { a: b } | 1328 - { a: b } |
1306 - "a" | 1329 - "a" |
1307 - 'b' | 1330 - 'b' |
1308 - c"""); | 1331 - c"""); |
1309 }); | 1332 }); |
1310 | 1333 |
1311 // test('[Example 7.24]', () { | 1334 test('[Example 7.24]', () { |
1312 // expectYamlLoads(["a", "b", "c", "c", ""], | 1335 expectYamlLoads(["a", "b", "c", "c", ""], |
1313 // """ | 1336 """ |
1314 // - !!str "a" | 1337 - !!str "a" |
1315 // - 'b' | 1338 - 'b' |
1316 // - &anchor "c" | 1339 - &anchor "c" |
1317 // - *anchor | 1340 - *anchor |
1318 // - !!str"""); | 1341 - !!str"""); |
1319 // }); | 1342 }); |
1320 }); | 1343 }); |
1321 | 1344 |
1322 // Chapter 8: Block Styles | 1345 // Chapter 8: Block Styles |
1323 group('8.1: Block Scalar Styles', () { | 1346 group('8.1: Block Scalar Styles', () { |
1324 test('[Example 8.1]', () { | 1347 test('[Example 8.1]', () { |
1325 expectYamlLoads(["literal\n", " folded\n", "keep\n\n", " strip"], | 1348 expectYamlLoads(["literal\n", " folded\n", "keep\n\n", " strip"], |
1326 """ | 1349 """ |
1327 - | # Empty header | 1350 - | # Empty header |
1328 literal | 1351 literal |
1329 - >1 # Indentation indicator | 1352 - >1 # Indentation indicator |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 test('[Example 8.19]', () { | 1585 test('[Example 8.19]', () { |
1563 var el = deepEqualsMap(); | 1586 var el = deepEqualsMap(); |
1564 el[{'earth': 'blue'}] = {'moon': 'white'}; | 1587 el[{'earth': 'blue'}] = {'moon': 'white'}; |
1565 expectYamlLoads([{'sun': 'yellow'}, el], | 1588 expectYamlLoads([{'sun': 'yellow'}, el], |
1566 """ | 1589 """ |
1567 - sun: yellow | 1590 - sun: yellow |
1568 - ? earth: blue | 1591 - ? earth: blue |
1569 : moon: white"""); | 1592 : moon: white"""); |
1570 }); | 1593 }); |
1571 | 1594 |
1572 // test('[Example 8.20]', () { | 1595 test('[Example 8.20]', () { |
1573 // expectYamlLoads(["flow in block", "Block scalar\n", {"foo": "bar"}], | 1596 expectYamlLoads(["flow in block", "Block scalar\n", {"foo": "bar"}], |
1574 // ''' | 1597 ''' |
1575 // - | 1598 - |
1576 // "flow in block" | 1599 "flow in block" |
1577 // - > | 1600 - > |
1578 // Block scalar | 1601 Block scalar |
1579 // - !!map # Block collection | 1602 - !!map # Block collection |
1580 // foo : bar'''); | 1603 foo : bar'''); |
1581 // }); | 1604 }); |
1582 | 1605 |
1583 // test('[Example 8.21]', () { | 1606 test('[Example 8.21]', () { |
1584 // expectYamlLoads({"literal": "value", "folded": "value"}, | 1607 // The spec doesn't include a newline after "value" in the parsed map, but |
1585 // """ | 1608 // the block scalar is clipped so it should be retained. |
1586 // literal: |2 | 1609 expectYamlLoads({"literal": "value\n", "folded": "value"}, |
1587 // value | 1610 """ |
1588 // folded: | 1611 literal: |2 |
1589 // !!str | 1612 value |
1590 // >1 | 1613 folded: |
1591 // value"""); | 1614 !!str |
1592 // }); | 1615 >1 |
| 1616 value"""); |
| 1617 }); |
1593 | 1618 |
1594 // test('[Example 8.22]', () { | 1619 test('[Example 8.22]', () { |
1595 // expectYamlLoads({ | 1620 expectYamlLoads({ |
1596 // "sequence": ["entry", ["nested"]], | 1621 "sequence": ["entry", ["nested"]], |
1597 // "mapping": {"foo": "bar"} | 1622 "mapping": {"foo": "bar"} |
1598 // }, | 1623 }, |
1599 // """ | 1624 """ |
1600 // sequence: !!seq | 1625 sequence: !!seq |
1601 // - entry | 1626 - entry |
1602 // - !!seq | 1627 - !!seq |
1603 // - nested | 1628 - nested |
1604 // mapping: !!map | 1629 mapping: !!map |
1605 // foo: bar"""); | 1630 foo: bar"""); |
1606 // }); | 1631 }); |
1607 }); | 1632 }); |
1608 | 1633 |
1609 // Chapter 9: YAML Character Stream | 1634 // Chapter 9: YAML Character Stream |
1610 group('9.1: Documents', () { | 1635 group('9.1: Documents', () { |
1611 // Example 9.1 tests the use of a BOM, which this implementation currently | 1636 // Example 9.1 tests the use of a BOM, which this implementation currently |
1612 // doesn't plan to support. | 1637 // doesn't plan to support. |
1613 | 1638 |
1614 // test('[Example 9.2]', () { | 1639 test('[Example 9.2]', () { |
1615 // expectYamlLoads("Document", | 1640 expectYamlLoads("Document", |
1616 // """ | 1641 """ |
1617 // %YAML 1.2 | 1642 %YAML 1.2 |
1618 // --- | 1643 --- |
1619 // Document | 1644 Document |
1620 // ... # Suffix"""); | 1645 ... # Suffix"""); |
1621 // }); | 1646 }); |
1622 | 1647 |
1623 test('[Example 9.3]', () { | 1648 test('[Example 9.3]', () { |
1624 // The spec example indicates that the comment after "%!PS-Adobe-2.0" | 1649 // The spec example indicates that the comment after "%!PS-Adobe-2.0" |
1625 // should be stripped, which would imply that that line is not part of the | 1650 // should be stripped, which would imply that that line is not part of the |
1626 // literal defined by the "|". The rest of the spec is ambiguous on this | 1651 // literal defined by the "|". The rest of the spec is ambiguous on this |
1627 // point; the allowable indentation for non-indented literal content is | 1652 // point; the allowable indentation for non-indented literal content is |
1628 // not clearly explained. However, if both the "|" and the text were | 1653 // not clearly explained. However, if both the "|" and the text were |
1629 // indented the same amount, the text would be part of the literal, which | 1654 // indented the same amount, the text would be part of the literal, which |
1630 // implies that the spec's parse of this document is incorrect. | 1655 // implies that the spec's parse of this document is incorrect. |
1631 expectYamlStreamLoads( | 1656 expectYamlStreamLoads( |
(...skipping 14 matching lines...) Expand all Loading... |
1646 """ | 1671 """ |
1647 --- | 1672 --- |
1648 { matches | 1673 { matches |
1649 % : 20 } | 1674 % : 20 } |
1650 ... | 1675 ... |
1651 --- | 1676 --- |
1652 # Empty | 1677 # Empty |
1653 ..."""); | 1678 ..."""); |
1654 }); | 1679 }); |
1655 | 1680 |
1656 // test('[Example 9.5]', () { | 1681 test('[Example 9.5]', () { |
1657 // expectYamlStreamLoads(["%!PS-Adobe-2.0\n", null], | 1682 // The spec doesn't have a space between the second |
1658 // """ | 1683 // "YAML" and "1.2", but this seems to be a typo. |
1659 // %YAML 1.2 | 1684 expectYamlStreamLoads(["%!PS-Adobe-2.0\n", null], |
1660 // --- | | 1685 """ |
1661 // %!PS-Adobe-2.0 | 1686 %YAML 1.2 |
1662 // ... | 1687 --- | |
1663 // %YAML1.2 | 1688 %!PS-Adobe-2.0 |
1664 // --- | 1689 ... |
1665 // # Empty | 1690 %YAML 1.2 |
1666 // ..."""); | 1691 --- |
1667 // }); | 1692 # Empty |
| 1693 ..."""); |
| 1694 }); |
1668 | 1695 |
1669 // test('[Example 9.6]', () { | 1696 test('[Example 9.6]', () { |
1670 // expectYamlStreamLoads(["Document", null, {"matches %": 20}], | 1697 expectYamlStreamLoads(["Document", null, {"matches %": 20}], |
1671 // """ | 1698 """ |
1672 // Document | 1699 Document |
1673 // --- | 1700 --- |
1674 // # Empty | 1701 # Empty |
1675 // ... | 1702 ... |
1676 // %YAML 1.2 | 1703 %YAML 1.2 |
1677 // --- | 1704 --- |
1678 // matches %: 20"""); | 1705 matches %: 20"""); |
1679 // }); | 1706 }); |
1680 }); | 1707 }); |
1681 | 1708 |
1682 // Chapter 10: Recommended Schemas | 1709 // Chapter 10: Recommended Schemas |
1683 group('10.1: Failsafe Schema', () { | 1710 group('10.1: Failsafe Schema', () { |
1684 // test('[Example 10.1]', () { | 1711 test('[Example 10.1]', () { |
1685 // expectYamlStreamLoads({ | 1712 expectYamlLoads({ |
1686 // "Block style": { | 1713 "Block style": { |
1687 // "Clark": "Evans", | 1714 "Clark": "Evans", |
1688 // "Ingy": "döt Net", | 1715 "Ingy": "döt Net", |
1689 // "Oren": "Ben-Kiki" | 1716 "Oren": "Ben-Kiki" |
1690 // }, | 1717 }, |
1691 // "Flow style": { | 1718 "Flow style": { |
1692 // "Clark": "Evans", | 1719 "Clark": "Evans", |
1693 // "Ingy": "döt Net", | 1720 "Ingy": "döt Net", |
1694 // "Oren": "Ben-Kiki" | 1721 "Oren": "Ben-Kiki" |
1695 // } | 1722 } |
1696 // }, | 1723 }, |
1697 // """ | 1724 """ |
1698 // Block style: !!map | 1725 Block style: !!map |
1699 // Clark : Evans | 1726 Clark : Evans |
1700 // Ingy : döt Net | 1727 Ingy : döt Net |
1701 // Oren : Ben-Kiki | 1728 Oren : Ben-Kiki |
1702 | 1729 |
1703 // Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki }""")
; | 1730 Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki }"""); |
1704 // }); | 1731 }); |
1705 | 1732 |
1706 // test('[Example 10.2]', () { | 1733 test('[Example 10.2]', () { |
1707 // expectYamlStreamLoads({ | 1734 expectYamlLoads({ |
1708 // "Block style": ["Clark Evans", "Ingy döt Net", "Oren Ben-Kiki"], | 1735 "Block style": ["Clark Evans", "Ingy döt Net", "Oren Ben-Kiki"], |
1709 // "Flow style": ["Clark Evans", "Ingy döt Net", "Oren Ben-Kiki"] | 1736 "Flow style": ["Clark Evans", "Ingy döt Net", "Oren Ben-Kiki"] |
1710 // }, | 1737 }, |
1711 // """ | 1738 """ |
1712 // Block style: !!seq | 1739 Block style: !!seq |
1713 // - Clark Evans | 1740 - Clark Evans |
1714 // - Ingy döt Net | 1741 - Ingy döt Net |
1715 // - Oren Ben-Kiki | 1742 - Oren Ben-Kiki |
1716 | 1743 |
1717 // Flow style: !!seq [ Clark Evans, Ingy döt Net, Oren Ben-Kiki ]"""); | 1744 Flow style: !!seq [ Clark Evans, Ingy döt Net, Oren Ben-Kiki ]"""); |
1718 // }); | 1745 }); |
1719 | 1746 |
1720 // test('[Example 10.3]', () { | 1747 test('[Example 10.3]', () { |
1721 // expectYamlStreamLoads({ | 1748 expectYamlLoads({ |
1722 // "Block style": "String: just a theory.", | 1749 "Block style": "String: just a theory.", |
1723 // "Flow style": "String: just a theory." | 1750 "Flow style": "String: just a theory." |
1724 // }, | 1751 }, |
1725 // ''' | 1752 ''' |
1726 // Block style: !!str |- | 1753 Block style: !!str |- |
1727 // String: just a theory. | 1754 String: just a theory. |
1728 | 1755 |
1729 // Flow style: !!str "String: just a theory."'''); | 1756 Flow style: !!str "String: just a theory."'''); |
1730 // }); | 1757 }); |
1731 }); | 1758 }); |
1732 | 1759 |
1733 group('10.2: JSON Schema', () { | 1760 group('10.2: JSON Schema', () { |
1734 // test('[Example 10.4]', () { | 1761 // test('[Example 10.4]', () { |
1735 // var doc = deepEqualsMap({"key with null value": null}); | 1762 // var doc = deepEqualsMap({"key with null value": null}); |
1736 // doc[null] = "value for null key"; | 1763 // doc[null] = "value for null key"; |
1737 // expectYamlStreamLoads(doc, | 1764 // expectYamlStreamLoads(doc, |
1738 // """ | 1765 // """ |
1739 // !!null null: value for null key | 1766 // !!null null: value for null key |
1740 // key with null value: !!null null"""); | 1767 // key with null value: !!null null"""); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1812 A null: null | 1839 A null: null |
1813 Also a null: # Empty | 1840 Also a null: # Empty |
1814 Not a null: "" | 1841 Not a null: "" |
1815 Booleans: [ true, True, false, FALSE ] | 1842 Booleans: [ true, True, false, FALSE ] |
1816 Integers: [ 0, 0o7, 0x3A, -19 ] | 1843 Integers: [ 0, 0o7, 0x3A, -19 ] |
1817 Floats: [ 0., -0.0, .5, +12e03, -2E+05 ] | 1844 Floats: [ 0., -0.0, .5, +12e03, -2E+05 ] |
1818 Also floats: [ .inf, -.Inf, +.INF, .NAN ]'''); | 1845 Also floats: [ .inf, -.Inf, +.INF, .NAN ]'''); |
1819 }); | 1846 }); |
1820 }); | 1847 }); |
1821 } | 1848 } |
OLD | NEW |