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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/src/util/test_all.dart ('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) 2015, 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 analyzer.test.util.yaml;
6
7 import 'package:analyzer/src/util/yaml.dart';
8 import 'package:unittest/unittest.dart';
9
10 import '../../utils.dart';
11
12 main() {
13 initializeTestEnvironment();
14
15 group('yaml', () {
16 group('merge', () {
17 test('map', () {
18 expect(
19 merge({
20 'one': true,
21 'two': false,
22 'three': {
23 'nested': {'four': true, 'six': true}
24 }
25 }, {
26 'three': {
27 'nested': {'four': false, 'five': true},
28 'five': true
29 },
30 'seven': true
31 }),
32 equals({
33 'one': true,
34 'two': false,
35 'three': {
36 'nested': {'four': false, 'five': true, 'six': true},
37 'five': true
38 },
39 'seven': true
40 }));
41 });
42
43 test('list', () {
44 expect(merge([1, 2, 3], [2, 3, 4, 5]), equals([1, 2, 3, 4, 5]));
45 });
46
47 test('list w/ promotion', () {
48 expect(merge(['one', 'two', 'three'], {'three': false, 'four': true}),
49 equals({'one': true, 'two': true, 'three': false, 'four': true}));
50 expect(merge({'one': false, 'two': false}, ['one', 'three']),
51 equals({'one': true, 'two': false, 'three': true}));
52 });
53
54 test('map w/ list promotion', () {
55 var map1 = {
56 'one': ['a', 'b', 'c']
57 };
58 var map2 = {
59 'one': {'a': true, 'b': false}
60 };
61 var map3 = {
62 'one': {'a': true, 'b': false, 'c': true}
63 };
64 expect(merge(map1, map2), map3);
65 });
66
67 test('map w/ no promotion', () {
68 var map1 = {
69 'one': ['a', 'b', 'c']
70 };
71 var map2 = {
72 'one': {'a': 'foo', 'b': 'bar'}
73 };
74 var map3 = {
75 'one': {'a': 'foo', 'b': 'bar'}
76 };
77 expect(merge(map1, map2), map3);
78 });
79
80 test('map w/ no promotion (2)', () {
81 var map1 = {
82 'one': {'a': 'foo', 'b': 'bar'}
83 };
84 var map2 = {
85 'one': ['a', 'b', 'c']
86 };
87 var map3 = {
88 'one': ['a', 'b', 'c']
89 };
90 expect(merge(map1, map2), map3);
91 });
92
93 test('object', () {
94 expect(merge(1, 2), 2);
95 expect(merge(1, 'foo'), 'foo');
96 expect(merge({'foo': 1}, 'foo'), 'foo');
97 });
98 });
99 });
100 }
101
102 final Merger merger = new Merger();
103
104 Object merge(Object o1, Object o2) => merger.merge(o1, o2);
OLDNEW
« 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