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

Unified Diff: packages/yaml/test/yaml_node_wrapper_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/yaml/test/utils.dart ('k') | packages/yaml/test/yaml_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/yaml/test/yaml_node_wrapper_test.dart
diff --git a/packages/yaml/test/yaml_node_wrapper_test.dart b/packages/yaml/test/yaml_node_wrapper_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b76a73ba830d9e2017362700a5ab1e9fe6f2aa03
--- /dev/null
+++ b/packages/yaml/test/yaml_node_wrapper_test.dart
@@ -0,0 +1,163 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library yaml.node_wrapper_test;
+
+import 'package:source_span/source_span.dart';
+import 'package:test/test.dart';
+import 'package:yaml/yaml.dart';
+
+main() {
+ test("YamlMap() with no sourceUrl", () {
+ var map = new YamlMap();
+ expect(map, isEmpty);
+ expect(map.nodes, isEmpty);
+ expect(map.span, isNullSpan(isNull));
+ });
+
+ test("YamlMap() with a sourceUrl", () {
+ var map = new YamlMap(sourceUrl: "source");
+ expect(map.span, isNullSpan(Uri.parse("source")));
+ });
+
+ test("YamlList() with no sourceUrl", () {
+ var list = new YamlList();
+ expect(list, isEmpty);
+ expect(list.nodes, isEmpty);
+ expect(list.span, isNullSpan(isNull));
+ });
+
+ test("YamlList() with a sourceUrl", () {
+ var list = new YamlList(sourceUrl: "source");
+ expect(list.span, isNullSpan(Uri.parse("source")));
+ });
+
+ test("YamlMap.wrap() with no sourceUrl", () {
+ var map = new YamlMap.wrap({
+ "list": [1, 2, 3],
+ "map": {
+ "foo": "bar",
+ "nested": [4, 5, 6]
+ },
+ "scalar": "value"
+ });
+
+ expect(map, equals({
+ "list": [1, 2, 3],
+ "map": {
+ "foo": "bar",
+ "nested": [4, 5, 6]
+ },
+ "scalar": "value"
+ }));
+
+ expect(map.span, isNullSpan(isNull));
+ expect(map["list"], new isInstanceOf<YamlList>());
+ expect(map["list"].nodes[0], new isInstanceOf<YamlScalar>());
+ expect(map["list"].span, isNullSpan(isNull));
+ expect(map["map"], new isInstanceOf<YamlMap>());
+ expect(map["map"].nodes["foo"], new isInstanceOf<YamlScalar>());
+ expect(map["map"]["nested"], new isInstanceOf<YamlList>());
+ expect(map["map"].span, isNullSpan(isNull));
+ expect(map.nodes["scalar"], new isInstanceOf<YamlScalar>());
+ expect(map.nodes["scalar"].value, "value");
+ expect(map.nodes["scalar"].span, isNullSpan(isNull));
+ expect(map["scalar"], "value");
+ expect(map.keys, unorderedEquals(["list", "map", "scalar"]));
+ expect(map.nodes.keys, everyElement(new isInstanceOf<YamlScalar>()));
+ expect(map.nodes[new YamlScalar.wrap("list")], equals([1, 2, 3]));
+ });
+
+ test("YamlMap.wrap() with a sourceUrl", () {
+ var map = new YamlMap.wrap({
+ "list": [1, 2, 3],
+ "map": {
+ "foo": "bar",
+ "nested": [4, 5, 6]
+ },
+ "scalar": "value"
+ }, sourceUrl: "source");
+
+ var source = Uri.parse("source");
+ expect(map.span, isNullSpan(source));
+ expect(map["list"].span, isNullSpan(source));
+ expect(map["map"].span, isNullSpan(source));
+ expect(map.nodes["scalar"].span, isNullSpan(source));
+ });
+
+ test("YamlList.wrap() with no sourceUrl", () {
+ var list = new YamlList.wrap([
+ [1, 2, 3],
+ {
+ "foo": "bar",
+ "nested": [4, 5, 6]
+ },
+ "value"
+ ]);
+
+ expect(list, equals([
+ [1, 2, 3],
+ {
+ "foo": "bar",
+ "nested": [4, 5, 6]
+ },
+ "value"
+ ]));
+
+ expect(list.span, isNullSpan(isNull));
+ expect(list[0], new isInstanceOf<YamlList>());
+ expect(list[0].nodes[0], new isInstanceOf<YamlScalar>());
+ expect(list[0].span, isNullSpan(isNull));
+ expect(list[1], new isInstanceOf<YamlMap>());
+ expect(list[1].nodes["foo"], new isInstanceOf<YamlScalar>());
+ expect(list[1]["nested"], new isInstanceOf<YamlList>());
+ expect(list[1].span, isNullSpan(isNull));
+ expect(list.nodes[2], new isInstanceOf<YamlScalar>());
+ expect(list.nodes[2].value, "value");
+ expect(list.nodes[2].span, isNullSpan(isNull));
+ expect(list[2], "value");
+ });
+
+ test("YamlList.wrap() with a sourceUrl", () {
+ var list = new YamlList.wrap([
+ [1, 2, 3],
+ {
+ "foo": "bar",
+ "nested": [4, 5, 6]
+ },
+ "value"
+ ]);
+
+ expect(list.span, isNullSpan(isNull));
+ expect(list[0].span, isNullSpan(isNull));
+ expect(list[1].span, isNullSpan(isNull));
+ expect(list.nodes[2].span, isNullSpan(isNull));
+ });
+
+ test("re-wrapped objects equal one another", () {
+ var list = new YamlList.wrap([
+ [1, 2, 3],
+ {"foo": "bar"}
+ ]);
+
+ expect(list[0] == list[0], isTrue);
+ expect(list[0].nodes == list[0].nodes, isTrue);
+ expect(list[0] == new YamlList.wrap([1, 2, 3]), isFalse);
+ expect(list[1] == list[1], isTrue);
+ expect(list[1].nodes == list[1].nodes, isTrue);
+ expect(list[1] == new YamlMap.wrap({"foo": "bar"}), isFalse);
+ });
+}
+
+Matcher isNullSpan(sourceUrl) => predicate((span) {
+ expect(span, new isInstanceOf<SourceSpan>());
+ expect(span.length, equals(0));
+ expect(span.text, isEmpty);
+ expect(span.start, equals(span.end));
+ expect(span.start.offset, equals(0));
+ expect(span.start.line, equals(0));
+ expect(span.start.column, equals(0));
+ expect(span.sourceUrl, sourceUrl);
+ return true;
+});
« no previous file with comments | « packages/yaml/test/utils.dart ('k') | packages/yaml/test/yaml_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698