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

Side by Side Diff: pkg/yaml/test/yaml_node_wrapper_test.dart

Issue 343063002: Add new constructors to YamlNode subclasses. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: improve DummySpan.getLocationString Created 6 years, 6 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 yaml.node_wrapper_test;
6
7 import 'package:source_maps/source_maps.dart';
8 import 'package:unittest/unittest.dart';
9 import 'package:yaml/yaml.dart';
10
11 main() {
12 test("YamlMap() with no sourceName", () {
13 var map = new YamlMap();
14 expect(map, isEmpty);
15 expect(map.nodes, isEmpty);
16 expect(map.span, isDummySpan(isNull));
17 });
18
19 test("YamlMap() with a sourceName", () {
20 var map = new YamlMap(sourceName: "source");
21 expect(map.span, isDummySpan("source"));
22 });
23
24 test("YamlList() with no sourceName", () {
25 var list = new YamlList();
26 expect(list, isEmpty);
27 expect(list.nodes, isEmpty);
28 expect(list.span, isDummySpan(isNull));
29 });
30
31 test("YamlList() with a sourceName", () {
32 var list = new YamlList(sourceName: "source");
33 expect(list.span, isDummySpan("source"));
34 });
35
36 test("YamlMap.wrap() with no sourceName", () {
37 var map = new YamlMap.wrap({
38 "list": [1, 2, 3],
39 "map": {
40 "foo": "bar",
41 "nested": [4, 5, 6]
42 },
43 "scalar": "value"
44 });
45
46 expect(map, equals({
47 "list": [1, 2, 3],
48 "map": {
49 "foo": "bar",
50 "nested": [4, 5, 6]
51 },
52 "scalar": "value"
53 }));
54
55 expect(map.span, isDummySpan(isNull));
56 expect(map["list"], new isInstanceOf<YamlList>());
57 expect(map["list"].nodes[0], new isInstanceOf<YamlScalar>());
58 expect(map["list"].span, isDummySpan(isNull));
59 expect(map["map"], new isInstanceOf<YamlMap>());
60 expect(map["map"].nodes["foo"], new isInstanceOf<YamlScalar>());
61 expect(map["map"]["nested"], new isInstanceOf<YamlList>());
62 expect(map["map"].span, isDummySpan(isNull));
63 expect(map.nodes["scalar"], new isInstanceOf<YamlScalar>());
64 expect(map.nodes["scalar"].value, "value");
65 expect(map.nodes["scalar"].span, isDummySpan(isNull));
66 expect(map["scalar"], "value");
67 expect(map.keys, unorderedEquals(["list", "map", "scalar"]));
68 expect(map.nodes.keys, everyElement(new isInstanceOf<YamlScalar>()));
69 expect(map.nodes[new YamlScalar.wrap("list")], equals([1, 2, 3]));
70 });
71
72 test("YamlMap.wrap() with a sourceName", () {
73 var map = new YamlMap.wrap({
74 "list": [1, 2, 3],
75 "map": {
76 "foo": "bar",
77 "nested": [4, 5, 6]
78 },
79 "scalar": "value"
80 }, sourceName: "source");
81
82 expect(map.span, isDummySpan("source"));
83 expect(map["list"].span, isDummySpan("source"));
84 expect(map["map"].span, isDummySpan("source"));
85 expect(map.nodes["scalar"].span, isDummySpan("source"));
86 });
87
88 test("YamlList.wrap() with no sourceName", () {
89 var list = new YamlList.wrap([
90 [1, 2, 3],
91 {
92 "foo": "bar",
93 "nested": [4, 5, 6]
94 },
95 "value"
96 ]);
97
98 expect(list, equals([
99 [1, 2, 3],
100 {
101 "foo": "bar",
102 "nested": [4, 5, 6]
103 },
104 "value"
105 ]));
106
107 expect(list.span, isDummySpan(isNull));
108 expect(list[0], new isInstanceOf<YamlList>());
109 expect(list[0].nodes[0], new isInstanceOf<YamlScalar>());
110 expect(list[0].span, isDummySpan(isNull));
111 expect(list[1], new isInstanceOf<YamlMap>());
112 expect(list[1].nodes["foo"], new isInstanceOf<YamlScalar>());
113 expect(list[1]["nested"], new isInstanceOf<YamlList>());
114 expect(list[1].span, isDummySpan(isNull));
115 expect(list.nodes[2], new isInstanceOf<YamlScalar>());
116 expect(list.nodes[2].value, "value");
117 expect(list.nodes[2].span, isDummySpan(isNull));
118 expect(list[2], "value");
119 });
120
121 test("YamlList.wrap() with a sourceName", () {
122 var list = new YamlList.wrap([
123 [1, 2, 3],
124 {
125 "foo": "bar",
126 "nested": [4, 5, 6]
127 },
128 "value"
129 ]);
130
131 expect(list.span, isDummySpan(isNull));
132 expect(list[0].span, isDummySpan(isNull));
133 expect(list[1].span, isDummySpan(isNull));
134 expect(list.nodes[2].span, isDummySpan(isNull));
135 });
136 }
137
138 Matcher isDummySpan(sourceUrl) => predicate((span) {
139 expect(span, new isInstanceOf<Span>());
140 expect(span.length, equals(0));
141 expect(span.text, isEmpty);
142 expect(span.isIdentifier, isFalse);
143 expect(span.start, equals(span.end));
144 expect(span.start.offset, equals(0));
145 expect(span.start.line, equals(0));
146 expect(span.start.column, equals(0));
147 expect(span.sourceUrl, sourceUrl);
148 return true;
149 });
OLDNEW
« pkg/yaml/lib/src/yaml_node_wrapper.dart ('K') | « pkg/yaml/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698