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

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: code review Created 6 years, 5 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 | « pkg/yaml/pubspec.yaml ('k') | no next file » | no next file with comments »
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 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, isNullSpan(isNull));
17 });
18
19 test("YamlMap() with a sourceName", () {
20 var map = new YamlMap(sourceName: "source");
21 expect(map.span, isNullSpan("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, isNullSpan(isNull));
29 });
30
31 test("YamlList() with a sourceName", () {
32 var list = new YamlList(sourceName: "source");
33 expect(list.span, isNullSpan("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, isNullSpan(isNull));
56 expect(map["list"], new isInstanceOf<YamlList>());
57 expect(map["list"].nodes[0], new isInstanceOf<YamlScalar>());
58 expect(map["list"].span, isNullSpan(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, isNullSpan(isNull));
63 expect(map.nodes["scalar"], new isInstanceOf<YamlScalar>());
64 expect(map.nodes["scalar"].value, "value");
65 expect(map.nodes["scalar"].span, isNullSpan(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, isNullSpan("source"));
83 expect(map["list"].span, isNullSpan("source"));
84 expect(map["map"].span, isNullSpan("source"));
85 expect(map.nodes["scalar"].span, isNullSpan("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, isNullSpan(isNull));
108 expect(list[0], new isInstanceOf<YamlList>());
109 expect(list[0].nodes[0], new isInstanceOf<YamlScalar>());
110 expect(list[0].span, isNullSpan(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, isNullSpan(isNull));
115 expect(list.nodes[2], new isInstanceOf<YamlScalar>());
116 expect(list.nodes[2].value, "value");
117 expect(list.nodes[2].span, isNullSpan(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, isNullSpan(isNull));
132 expect(list[0].span, isNullSpan(isNull));
133 expect(list[1].span, isNullSpan(isNull));
134 expect(list.nodes[2].span, isNullSpan(isNull));
135 });
136
137 solo_test("re-wrapped objects equal one another", () {
138 var list = new YamlList.wrap([
139 [1, 2, 3],
140 {"foo": "bar"}
141 ]);
142
143 expect(list[0] == list[0], isTrue);
144 expect(list[0].nodes == list[0].nodes, isTrue);
145 expect(list[0] == new YamlList.wrap([1, 2, 3]), isFalse);
146 expect(list[1] == list[1], isTrue);
147 expect(list[1].nodes == list[1].nodes, isTrue);
148 expect(list[1] == new YamlMap.wrap({"foo": "bar"}), isFalse);
149 });
150 }
151
152 Matcher isNullSpan(sourceUrl) => predicate((span) {
153 expect(span, new isInstanceOf<Span>());
154 expect(span.length, equals(0));
155 expect(span.text, isEmpty);
156 expect(span.isIdentifier, isFalse);
157 expect(span.start, equals(span.end));
158 expect(span.start.offset, equals(0));
159 expect(span.start.line, equals(0));
160 expect(span.start.column, equals(0));
161 expect(span.sourceUrl, sourceUrl);
162 return true;
163 });
OLDNEW
« no previous file with comments | « pkg/yaml/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698