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

Side by Side Diff: tests/compiler/dart2js/serialization/test_helper.dart

Issue 2663033004: Prepare equivalence strategies for testing entities. (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.serialization_test_helper; 5 library dart2js.serialization_test_helper;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'package:compiler/src/common/resolution.dart'; 8 import 'package:compiler/src/common/resolution.dart';
9 import 'package:compiler/src/constants/expressions.dart'; 9 import 'package:compiler/src/constants/expressions.dart';
10 import 'package:compiler/src/constants/values.dart'; 10 import 'package:compiler/src/constants/values.dart';
11 import 'package:compiler/src/elements/entities.dart';
11 import 'package:compiler/src/elements/resolution_types.dart'; 12 import 'package:compiler/src/elements/resolution_types.dart';
13 import 'package:compiler/src/elements/types.dart';
12 import 'package:compiler/src/compiler.dart'; 14 import 'package:compiler/src/compiler.dart';
13 import 'package:compiler/src/elements/elements.dart'; 15 import 'package:compiler/src/elements/elements.dart';
14 import 'package:compiler/src/serialization/equivalence.dart'; 16 import 'package:compiler/src/serialization/equivalence.dart';
15 import 'package:compiler/src/tree/nodes.dart'; 17 import 'package:compiler/src/tree/nodes.dart';
16 import 'package:expect/expect.dart'; 18 import 'package:expect/expect.dart';
17 import 'test_data.dart'; 19 import 'test_data.dart';
18 20
19 Check currentCheck; 21 Check currentCheck;
20 22
21 class Check { 23 class Check {
(...skipping 26 matching lines...) Expand all
48 StringBuffer sb = new StringBuffer(); 50 StringBuffer sb = new StringBuffer();
49 printOn(sb, ''); 51 printOn(sb, '');
50 return sb.toString(); 52 return sb.toString();
51 } 53 }
52 } 54 }
53 55
54 /// Strategy for checking equivalence. 56 /// Strategy for checking equivalence.
55 /// 57 ///
56 /// Use this strategy to fail early with contextual information in the event of 58 /// Use this strategy to fail early with contextual information in the event of
57 /// inequivalence. 59 /// inequivalence.
58 class CheckStrategy implements TestStrategy { 60 class CheckStrategy extends TestStrategy {
59 const CheckStrategy(); 61 const CheckStrategy(
62 {Equivalence<Entity> elementEquivalence: areElementsEquivalent,
63 Equivalence<DartType> typeEquivalence: areTypesEquivalent,
64 Equivalence<ConstantExpression> constantEquivalence:
65 areConstantsEquivalent,
66 Equivalence<ConstantValue> constantValueEquivalence:
67 areConstantValuesEquivalent})
68 : super(
69 elementEquivalence: elementEquivalence,
70 typeEquivalence: typeEquivalence,
71 constantEquivalence: constantEquivalence,
72 constantValueEquivalence: constantValueEquivalence);
73
74 TestStrategy get testOnly => new TestStrategy(
75 elementEquivalence: elementEquivalence,
76 typeEquivalence: typeEquivalence,
77 constantEquivalence: constantEquivalence,
78 constantValueEquivalence: constantValueEquivalence);
60 79
61 @override 80 @override
62 bool test(var object1, var object2, String property, var value1, var value2, 81 bool test(var object1, var object2, String property, var value1, var value2,
63 [bool equivalence(a, b) = equality]) { 82 [bool equivalence(a, b) = equality]) {
64 return check(object1, object2, property, value1, value2, equivalence); 83 return check(object1, object2, property, value1, value2, equivalence);
65 } 84 }
66 85
67 @override 86 @override
68 bool testLists( 87 bool testLists(
69 Object object1, Object object2, String property, List list1, List list2, 88 Object object1, Object object2, String property, List list1, List list2,
(...skipping 16 matching lines...) Expand all
86 object1, object2, property, set1, set2, elementEquivalence); 105 object1, object2, property, set1, set2, elementEquivalence);
87 } 106 }
88 107
89 @override 108 @override
90 bool testMaps(var object1, var object2, String property, Map map1, Map map2, 109 bool testMaps(var object1, var object2, String property, Map map1, Map map2,
91 [bool keyEquivalence(a, b) = equality, 110 [bool keyEquivalence(a, b) = equality,
92 bool valueEquivalence(a, b) = equality]) { 111 bool valueEquivalence(a, b) = equality]) {
93 return checkMapEquivalence(object1, object2, property, map1, map2, 112 return checkMapEquivalence(object1, object2, property, map1, map2,
94 keyEquivalence, valueEquivalence); 113 keyEquivalence, valueEquivalence);
95 } 114 }
96
97 @override
98 bool testElements(Object object1, Object object2, String property,
99 Element element1, Element element2) {
100 return checkElementIdentities(
101 object1, object2, property, element1, element2);
102 }
103
104 @override
105 bool testTypes(Object object1, Object object2, String property,
106 ResolutionDartType type1, ResolutionDartType type2) {
107 return checkTypes(object1, object2, property, type1, type2);
108 }
109
110 @override
111 bool testConstants(Object object1, Object object2, String property,
112 ConstantExpression exp1, ConstantExpression exp2) {
113 return checkConstants(object1, object2, property, exp1, exp2);
114 }
115
116 @override
117 bool testConstantValues(Object object1, Object object2, String property,
118 ConstantValue value1, ConstantValue value2) {
119 return areConstantValuesEquivalent(value1, value2);
120 }
121
122 @override
123 bool testTypeLists(Object object1, Object object2, String property,
124 List<ResolutionDartType> list1, List<ResolutionDartType> list2) {
125 return checkTypeLists(object1, object2, property, list1, list2);
126 }
127
128 @override
129 bool testConstantLists(Object object1, Object object2, String property,
130 List<ConstantExpression> list1, List<ConstantExpression> list2) {
131 return checkConstantLists(object1, object2, property, list1, list2);
132 }
133
134 @override
135 bool testConstantValueLists(Object object1, Object object2, String property,
136 List<ConstantValue> list1, List<ConstantValue> list2) {
137 return checkConstantValueLists(object1, object2, property, list1, list2);
138 }
139
140 @override
141 bool testNodes(
142 Object object1, Object object2, String property, Node node1, Node node2) {
143 return new NodeEquivalenceVisitor(this)
144 .testNodes(object1, object2, property, node1, node2);
145 }
146 } 115 }
147 116
148 /// Check that the values [property] of [object1] and [object2], [value1] and 117 /// Check that the values [property] of [object1] and [object2], [value1] and
149 /// [value2] respectively, are equal and throw otherwise. 118 /// [value2] respectively, are equal and throw otherwise.
150 bool check(var object1, var object2, String property, var value1, var value2, 119 bool check(var object1, var object2, String property, var value1, var value2,
151 [bool equivalence(a, b) = equality]) { 120 [bool equivalence(a, b) = equality]) {
152 currentCheck = 121 currentCheck =
153 new Check(currentCheck, object1, object2, property, value1, value2); 122 new Check(currentCheck, object1, object2, property, value1, value2);
154 if (!equivalence(value1, value2)) { 123 if (!equivalence(value1, value2)) {
155 throw currentCheck; 124 throw currentCheck;
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 } 623 }
655 624
656 if (index == 1 && skip != 0) { 625 if (index == 1 && skip != 0) {
657 return ['${skip}', segmentNumber(index)]; 626 return ['${skip}', segmentNumber(index)];
658 } else if (index == count) { 627 } else if (index == count) {
659 return [segmentNumber(index - 1)]; 628 return [segmentNumber(index - 1)];
660 } else { 629 } else {
661 return [segmentNumber(index - 1), segmentNumber(index)]; 630 return [segmentNumber(index - 1), segmentNumber(index)];
662 } 631 }
663 } 632 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698