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

Unified Diff: pkg/analyzer/test/src/util/yaml_test.dart

Issue 1425393002: Map merging. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Runtime type check fixes. Created 5 years, 1 month 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 | « pkg/analyzer/test/src/util/test_all.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/util/yaml_test.dart
diff --git a/pkg/analyzer/test/src/util/yaml_test.dart b/pkg/analyzer/test/src/util/yaml_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6cf00cc48b8ff65f06d7dbe74b6722ddfb53e9ac
--- /dev/null
+++ b/pkg/analyzer/test/src/util/yaml_test.dart
@@ -0,0 +1,104 @@
+// Copyright (c) 2015, 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 analyzer.test.util.yaml;
+
+import 'package:analyzer/src/util/yaml.dart';
+import 'package:unittest/unittest.dart';
+
+import '../../utils.dart';
+
+main() {
+ initializeTestEnvironment();
+
+ group('yaml', () {
+ group('merge', () {
+ test('map', () {
+ expect(
+ merge({
+ 'one': true,
+ 'two': false,
+ 'three': {
+ 'nested': {'four': true, 'six': true}
+ }
+ }, {
+ 'three': {
+ 'nested': {'four': false, 'five': true},
+ 'five': true
+ },
+ 'seven': true
+ }),
+ equals({
+ 'one': true,
+ 'two': false,
+ 'three': {
+ 'nested': {'four': false, 'five': true, 'six': true},
+ 'five': true
+ },
+ 'seven': true
+ }));
+ });
+
+ test('list', () {
+ expect(merge([1, 2, 3], [2, 3, 4, 5]), equals([1, 2, 3, 4, 5]));
+ });
+
+ test('list w/ promotion', () {
+ expect(merge(['one', 'two', 'three'], {'three': false, 'four': true}),
+ equals({'one': true, 'two': true, 'three': false, 'four': true}));
+ expect(merge({'one': false, 'two': false}, ['one', 'three']),
+ equals({'one': true, 'two': false, 'three': true}));
+ });
+
+ test('map w/ list promotion', () {
+ var map1 = {
+ 'one': ['a', 'b', 'c']
+ };
+ var map2 = {
+ 'one': {'a': true, 'b': false}
+ };
+ var map3 = {
+ 'one': {'a': true, 'b': false, 'c': true}
+ };
+ expect(merge(map1, map2), map3);
+ });
+
+ test('map w/ no promotion', () {
+ var map1 = {
+ 'one': ['a', 'b', 'c']
+ };
+ var map2 = {
+ 'one': {'a': 'foo', 'b': 'bar'}
+ };
+ var map3 = {
+ 'one': {'a': 'foo', 'b': 'bar'}
+ };
+ expect(merge(map1, map2), map3);
+ });
+
+ test('map w/ no promotion (2)', () {
+ var map1 = {
+ 'one': {'a': 'foo', 'b': 'bar'}
+ };
+ var map2 = {
+ 'one': ['a', 'b', 'c']
+ };
+ var map3 = {
+ 'one': ['a', 'b', 'c']
+ };
+ expect(merge(map1, map2), map3);
+ });
+
+ test('object', () {
+ expect(merge(1, 2), 2);
+ expect(merge(1, 'foo'), 'foo');
+ expect(merge({'foo': 1}, 'foo'), 'foo');
+ });
+ });
+ });
+}
+
+final Merger merger = new Merger();
+
+Object merge(Object o1, Object o2) => merger.merge(o1, o2);
« no previous file with comments | « pkg/analyzer/test/src/util/test_all.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698