OLD | NEW |
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:io'; | 7 import 'dart:io'; |
8 import '../memory_compiler.dart'; | 8 import '../memory_compiler.dart'; |
9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
10 import 'package:compiler/src/common/resolution.dart'; | 10 import 'package:compiler/src/common/resolution.dart'; |
11 import 'package:compiler/src/commandline_options.dart'; | 11 import 'package:compiler/src/commandline_options.dart'; |
12 import 'package:compiler/src/constants/constructors.dart'; | 12 import 'package:compiler/src/constants/constructors.dart'; |
13 import 'package:compiler/src/constants/expressions.dart'; | 13 import 'package:compiler/src/constants/expressions.dart'; |
14 import 'package:compiler/src/dart_types.dart'; | 14 import 'package:compiler/src/dart_types.dart'; |
15 import 'package:compiler/src/compiler.dart'; | 15 import 'package:compiler/src/compiler.dart'; |
16 import 'package:compiler/src/diagnostics/invariant.dart'; | 16 import 'package:compiler/src/diagnostics/invariant.dart'; |
17 import 'package:compiler/src/elements/elements.dart'; | 17 import 'package:compiler/src/elements/elements.dart'; |
18 import 'package:compiler/src/elements/visitor.dart'; | 18 import 'package:compiler/src/elements/visitor.dart'; |
19 import 'package:compiler/src/ordered_typeset.dart'; | 19 import 'package:compiler/src/ordered_typeset.dart'; |
20 import 'package:compiler/src/serialization/element_serialization.dart'; | 20 import 'package:compiler/src/serialization/element_serialization.dart'; |
21 import 'package:compiler/src/serialization/equivalence.dart'; | 21 import 'package:compiler/src/serialization/equivalence.dart'; |
22 import 'package:compiler/src/serialization/json_serializer.dart'; | 22 import 'package:compiler/src/serialization/json_serializer.dart'; |
23 import 'package:compiler/src/serialization/serialization.dart'; | 23 import 'package:compiler/src/serialization/serialization.dart'; |
24 | 24 import 'package:compiler/src/tree/nodes.dart'; |
25 | 25 |
26 /// Strategy for checking equivalence. | 26 /// Strategy for checking equivalence. |
27 /// | 27 /// |
28 /// Use this strategy to fail early with contextual information in the event of | 28 /// Use this strategy to fail early with contextual information in the event of |
29 /// inequivalence. | 29 /// inequivalence. |
30 class CheckStrategy implements TestStrategy { | 30 class CheckStrategy implements TestStrategy { |
31 const CheckStrategy(); | 31 const CheckStrategy(); |
32 | 32 |
33 @override | 33 @override |
34 bool test(var object1, var object2, String property, var value1, var value2, | 34 bool test(var object1, var object2, String property, var value1, var value2, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return checkTypeLists(object1, object2, property, list1, list2); | 90 return checkTypeLists(object1, object2, property, list1, list2); |
91 } | 91 } |
92 | 92 |
93 @override | 93 @override |
94 bool testConstantLists( | 94 bool testConstantLists( |
95 Object object1, Object object2, String property, | 95 Object object1, Object object2, String property, |
96 List<ConstantExpression> list1, | 96 List<ConstantExpression> list1, |
97 List<ConstantExpression> list2) { | 97 List<ConstantExpression> list2) { |
98 return checkConstantLists(object1, object2, property, list1, list2); | 98 return checkConstantLists(object1, object2, property, list1, list2); |
99 } | 99 } |
| 100 |
| 101 @override |
| 102 bool testNodes(Object object1, Object object2, String property, |
| 103 Node node1, Node node2) { |
| 104 return new NodeEquivalenceVisitor(this).testNodes( |
| 105 object1, object2, property, node1, node2); |
| 106 } |
100 } | 107 } |
101 | 108 |
102 /// Check that the values [property] of [object1] and [object2], [value1] and | 109 /// Check that the values [property] of [object1] and [object2], [value1] and |
103 /// [value2] respectively, are equal and throw otherwise. | 110 /// [value2] respectively, are equal and throw otherwise. |
104 bool check(var object1, var object2, String property, var value1, var value2, | 111 bool check(var object1, var object2, String property, var value1, var value2, |
105 [bool equivalence(a, b) = equality]) { | 112 [bool equivalence(a, b) = equality]) { |
106 if (!equivalence(value1, value2)) { | 113 if (!equivalence(value1, value2)) { |
107 throw "property='$property'\n " | 114 throw "property='$property'\n " |
108 "object1=$object1 (${object1.runtimeType})\n " | 115 "object1=$object1 (${object1.runtimeType})\n " |
109 "value=${value1 == null ? "null" : "'$value1'"} " | 116 "value=${value1 == null ? "null" : "'$value1'"} " |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 380 |
374 if (impact1 == null) { | 381 if (impact1 == null) { |
375 throw 'Missing impact for $member1. $member2 has $impact2'; | 382 throw 'Missing impact for $member1. $member2 has $impact2'; |
376 } | 383 } |
377 if (impact2 == null) { | 384 if (impact2 == null) { |
378 throw 'Missing impact for $member2. $member1 has $impact1'; | 385 throw 'Missing impact for $member2. $member1 has $impact1'; |
379 } | 386 } |
380 | 387 |
381 testResolutionImpactEquivalence(impact1, impact2, const CheckStrategy()); | 388 testResolutionImpactEquivalence(impact1, impact2, const CheckStrategy()); |
382 } | 389 } |
OLD | NEW |