| 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.node_wrapper_test; | 5 library yaml.node_wrapper_test; |
| 6 | 6 |
| 7 import 'package:source_maps/source_maps.dart'; | 7 import 'package:source_maps/source_maps.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
| 9 import 'package:yaml/yaml.dart'; | 9 import 'package:yaml/yaml.dart'; |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 test("YamlMap() with no sourceUrl", () { | 12 test("YamlMap() with no sourceUrl", () { |
| 13 var map = new YamlMap(); | 13 var map = new YamlMap(); |
| 14 expect(map, isEmpty); | 14 expect(map, isEmpty); |
| 15 expect(map.nodes, isEmpty); | 15 expect(map.nodes, isEmpty); |
| 16 expect(map.span, isNullSpan(isNull)); | 16 expect(map.span, isNullSpan(isNull)); |
| 17 }); | 17 }); |
| 18 | 18 |
| 19 test("YamlMap() with a sourceUrl", () { | 19 test("YamlMap() with a sourceUrl", () { |
| 20 var map = new YamlMap(sourceUrl: "source"); | 20 var map = new YamlMap(sourceUrl: "source"); |
| 21 expect(map.span, isNullSpan("source")); | 21 expect(map.span, isNullSpan(Uri.parse("source"))); |
| 22 }); | 22 }); |
| 23 | 23 |
| 24 test("YamlList() with no sourceUrl", () { | 24 test("YamlList() with no sourceUrl", () { |
| 25 var list = new YamlList(); | 25 var list = new YamlList(); |
| 26 expect(list, isEmpty); | 26 expect(list, isEmpty); |
| 27 expect(list.nodes, isEmpty); | 27 expect(list.nodes, isEmpty); |
| 28 expect(list.span, isNullSpan(isNull)); | 28 expect(list.span, isNullSpan(isNull)); |
| 29 }); | 29 }); |
| 30 | 30 |
| 31 test("YamlList() with a sourceUrl", () { | 31 test("YamlList() with a sourceUrl", () { |
| 32 var list = new YamlList(sourceUrl: "source"); | 32 var list = new YamlList(sourceUrl: "source"); |
| 33 expect(list.span, isNullSpan("source")); | 33 expect(list.span, isNullSpan(Uri.parse("source"))); |
| 34 }); | 34 }); |
| 35 | 35 |
| 36 test("YamlMap.wrap() with no sourceUrl", () { | 36 test("YamlMap.wrap() with no sourceUrl", () { |
| 37 var map = new YamlMap.wrap({ | 37 var map = new YamlMap.wrap({ |
| 38 "list": [1, 2, 3], | 38 "list": [1, 2, 3], |
| 39 "map": { | 39 "map": { |
| 40 "foo": "bar", | 40 "foo": "bar", |
| 41 "nested": [4, 5, 6] | 41 "nested": [4, 5, 6] |
| 42 }, | 42 }, |
| 43 "scalar": "value" | 43 "scalar": "value" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 72 test("YamlMap.wrap() with a sourceUrl", () { | 72 test("YamlMap.wrap() with a sourceUrl", () { |
| 73 var map = new YamlMap.wrap({ | 73 var map = new YamlMap.wrap({ |
| 74 "list": [1, 2, 3], | 74 "list": [1, 2, 3], |
| 75 "map": { | 75 "map": { |
| 76 "foo": "bar", | 76 "foo": "bar", |
| 77 "nested": [4, 5, 6] | 77 "nested": [4, 5, 6] |
| 78 }, | 78 }, |
| 79 "scalar": "value" | 79 "scalar": "value" |
| 80 }, sourceUrl: "source"); | 80 }, sourceUrl: "source"); |
| 81 | 81 |
| 82 expect(map.span, isNullSpan("source")); | 82 var source = Uri.parse("source"); |
| 83 expect(map["list"].span, isNullSpan("source")); | 83 expect(map.span, isNullSpan(source)); |
| 84 expect(map["map"].span, isNullSpan("source")); | 84 expect(map["list"].span, isNullSpan(source)); |
| 85 expect(map.nodes["scalar"].span, isNullSpan("source")); | 85 expect(map["map"].span, isNullSpan(source)); |
| 86 expect(map.nodes["scalar"].span, isNullSpan(source)); |
| 86 }); | 87 }); |
| 87 | 88 |
| 88 test("YamlList.wrap() with no sourceUrl", () { | 89 test("YamlList.wrap() with no sourceUrl", () { |
| 89 var list = new YamlList.wrap([ | 90 var list = new YamlList.wrap([ |
| 90 [1, 2, 3], | 91 [1, 2, 3], |
| 91 { | 92 { |
| 92 "foo": "bar", | 93 "foo": "bar", |
| 93 "nested": [4, 5, 6] | 94 "nested": [4, 5, 6] |
| 94 }, | 95 }, |
| 95 "value" | 96 "value" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 }, | 128 }, |
| 128 "value" | 129 "value" |
| 129 ]); | 130 ]); |
| 130 | 131 |
| 131 expect(list.span, isNullSpan(isNull)); | 132 expect(list.span, isNullSpan(isNull)); |
| 132 expect(list[0].span, isNullSpan(isNull)); | 133 expect(list[0].span, isNullSpan(isNull)); |
| 133 expect(list[1].span, isNullSpan(isNull)); | 134 expect(list[1].span, isNullSpan(isNull)); |
| 134 expect(list.nodes[2].span, isNullSpan(isNull)); | 135 expect(list.nodes[2].span, isNullSpan(isNull)); |
| 135 }); | 136 }); |
| 136 | 137 |
| 137 solo_test("re-wrapped objects equal one another", () { | 138 test("re-wrapped objects equal one another", () { |
| 138 var list = new YamlList.wrap([ | 139 var list = new YamlList.wrap([ |
| 139 [1, 2, 3], | 140 [1, 2, 3], |
| 140 {"foo": "bar"} | 141 {"foo": "bar"} |
| 141 ]); | 142 ]); |
| 142 | 143 |
| 143 expect(list[0] == list[0], isTrue); | 144 expect(list[0] == list[0], isTrue); |
| 144 expect(list[0].nodes == list[0].nodes, isTrue); | 145 expect(list[0].nodes == list[0].nodes, isTrue); |
| 145 expect(list[0] == new YamlList.wrap([1, 2, 3]), isFalse); | 146 expect(list[0] == new YamlList.wrap([1, 2, 3]), isFalse); |
| 146 expect(list[1] == list[1], isTrue); | 147 expect(list[1] == list[1], isTrue); |
| 147 expect(list[1].nodes == list[1].nodes, isTrue); | 148 expect(list[1].nodes == list[1].nodes, isTrue); |
| 148 expect(list[1] == new YamlMap.wrap({"foo": "bar"}), isFalse); | 149 expect(list[1] == new YamlMap.wrap({"foo": "bar"}), isFalse); |
| 149 }); | 150 }); |
| 150 } | 151 } |
| 151 | 152 |
| 152 Matcher isNullSpan(sourceUrl) => predicate((span) { | 153 Matcher isNullSpan(sourceUrl) => predicate((span) { |
| 153 expect(span, new isInstanceOf<Span>()); | 154 expect(span, new isInstanceOf<SourceSpan>()); |
| 154 expect(span.length, equals(0)); | 155 expect(span.length, equals(0)); |
| 155 expect(span.text, isEmpty); | 156 expect(span.text, isEmpty); |
| 156 expect(span.isIdentifier, isFalse); | |
| 157 expect(span.start, equals(span.end)); | 157 expect(span.start, equals(span.end)); |
| 158 expect(span.start.offset, equals(0)); | 158 expect(span.start.offset, equals(0)); |
| 159 expect(span.start.line, equals(0)); | 159 expect(span.start.line, equals(0)); |
| 160 expect(span.start.column, equals(0)); | 160 expect(span.start.column, equals(0)); |
| 161 expect(span.sourceUrl, sourceUrl); | 161 expect(span.sourceUrl, sourceUrl); |
| 162 return true; | 162 return true; |
| 163 }); | 163 }); |
| OLD | NEW |