| 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; | |
| 6 | |
| 7 import 'package:test/test.dart'; | 5 import 'package:test/test.dart'; |
| 8 import 'package:yaml/yaml.dart'; | 6 import 'package:yaml/yaml.dart'; |
| 9 | 7 |
| 10 import 'utils.dart'; | 8 import 'utils.dart'; |
| 11 | 9 |
| 12 main() { | 10 main() { |
| 13 var infinity = double.parse("Infinity"); | 11 var infinity = double.parse("Infinity"); |
| 14 var nan = double.parse("NaN"); | 12 var nan = double.parse("NaN"); |
| 15 | 13 |
| 16 group('has a friendly error message for', () { | 14 group('has a friendly error message for', () { |
| 17 var tabError = predicate((e) => | 15 var tabError = predicate((e) => |
| 18 e.toString().contains('Tab characters are not allowed as indentation')); | 16 e.toString().contains('Tab characters are not allowed as indentation')); |
| 19 | 17 |
| 20 test('using a tab as indentation', () { | 18 test('using a tab as indentation', () { |
| 21 expect(() => loadYaml('foo:\n\tbar'), | 19 expect(() => loadYaml('foo:\n\tbar'), |
| 22 throwsA(tabError)); | 20 throwsA(tabError)); |
| 23 }); | 21 }); |
| 24 | 22 |
| 25 test('using a tab not as indentation', () { | 23 test('using a tab not as indentation', () { |
| 26 expect(() => loadYaml(''' | 24 expect(() => loadYaml(''' |
| 27 "foo | 25 "foo |
| 28 \tbar" | 26 \tbar" |
| 29 error'''), | 27 error'''), |
| 30 throwsA(isNot(tabError))); | 28 throwsA(isNot(tabError))); |
| 31 }); | 29 }); |
| 32 }); | 30 }); |
| 33 | 31 |
| 34 group("refuses documents that declare version", () { | 32 group("refuses", () { |
| 35 test("1.0", () { | 33 // Regression test for #19. |
| 36 expectYamlFails(""" | 34 test("invalid contents", () { |
| 35 expectYamlFails("{"); |
| 36 }); |
| 37 |
| 38 test("duplicate mapping keys", () { |
| 39 expectYamlFails("{a: 1, a: 2}"); |
| 40 }); |
| 41 |
| 42 group("documents that declare version", () { |
| 43 test("1.0", () { |
| 44 expectYamlFails(""" |
| 37 %YAML 1.0 | 45 %YAML 1.0 |
| 38 --- text | 46 --- text |
| 39 """); | 47 """); |
| 40 }); | 48 }); |
| 41 | 49 |
| 42 test("1.3", () { | 50 test("1.3", () { |
| 43 expectYamlFails(""" | 51 expectYamlFails(""" |
| 44 %YAML 1.3 | 52 %YAML 1.3 |
| 45 --- text | 53 --- text |
| 46 """); | 54 """); |
| 47 }); | 55 }); |
| 48 | 56 |
| 49 test("2.0", () { | 57 test("2.0", () { |
| 50 expectYamlFails(""" | 58 expectYamlFails(""" |
| 51 %YAML 2.0 | 59 %YAML 2.0 |
| 52 --- text | 60 --- text |
| 53 """); | 61 """); |
| 62 }); |
| 54 }); | 63 }); |
| 55 }); | 64 }); |
| 56 | 65 |
| 57 test("includes source span information", () { | 66 test("includes source span information", () { |
| 58 var yaml = loadYamlNode(r""" | 67 var yaml = loadYamlNode(r""" |
| 59 - foo: | 68 - foo: |
| 60 bar | 69 bar |
| 61 - 123 | 70 - 123 |
| 62 """); | 71 """) as YamlList; |
| 63 | 72 |
| 64 expect(yaml.span.start.line, equals(0)); | 73 expect(yaml.span.start.line, equals(0)); |
| 65 expect(yaml.span.start.column, equals(0)); | 74 expect(yaml.span.start.column, equals(0)); |
| 66 expect(yaml.span.end.line, equals(3)); | 75 expect(yaml.span.end.line, equals(3)); |
| 67 expect(yaml.span.end.column, equals(0)); | 76 expect(yaml.span.end.column, equals(0)); |
| 68 | 77 |
| 69 var map = yaml.nodes.first; | 78 var map = yaml.nodes.first as YamlMap; |
| 70 expect(map.span.start.line, equals(0)); | 79 expect(map.span.start.line, equals(0)); |
| 71 expect(map.span.start.column, equals(2)); | 80 expect(map.span.start.column, equals(2)); |
| 72 expect(map.span.end.line, equals(2)); | 81 expect(map.span.end.line, equals(2)); |
| 73 expect(map.span.end.column, equals(0)); | 82 expect(map.span.end.column, equals(0)); |
| 74 | 83 |
| 75 var key = map.nodes.keys.first; | 84 var key = map.nodes.keys.first; |
| 76 expect(key.span.start.line, equals(0)); | 85 expect(key.span.start.line, equals(0)); |
| 77 expect(key.span.start.column, equals(2)); | 86 expect(key.span.start.column, equals(2)); |
| 78 expect(key.span.end.line, equals(0)); | 87 expect(key.span.end.line, equals(0)); |
| 79 expect(key.span.end.column, equals(5)); | 88 expect(key.span.end.column, equals(5)); |
| (...skipping 1796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 A null: null | 1885 A null: null |
| 1877 Also a null: # Empty | 1886 Also a null: # Empty |
| 1878 Not a null: "" | 1887 Not a null: "" |
| 1879 Booleans: [ true, True, false, FALSE ] | 1888 Booleans: [ true, True, false, FALSE ] |
| 1880 Integers: [ 0, 0o7, 0x3A, -19 ] | 1889 Integers: [ 0, 0o7, 0x3A, -19 ] |
| 1881 Floats: [ 0., -0.0, .5, +12e03, -2E+05 ] | 1890 Floats: [ 0., -0.0, .5, +12e03, -2E+05 ] |
| 1882 Also floats: [ .inf, -.Inf, +.INF, .NAN ]'''); | 1891 Also floats: [ .inf, -.Inf, +.INF, .NAN ]'''); |
| 1883 }); | 1892 }); |
| 1884 }); | 1893 }); |
| 1885 } | 1894 } |
| OLD | NEW |