| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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_model_test; | 5 library dart2js.serialization_model_test; |
| 6 | |
| 7 import 'dart:async'; | 6 import 'dart:async'; |
| 8 import 'dart:io'; | 7 import 'dart:io'; |
| 9 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 10 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 11 import 'package:compiler/src/closure.dart'; | 10 import 'package:compiler/src/closure.dart'; |
| 12 import 'package:compiler/src/commandline_options.dart'; | 11 import 'package:compiler/src/commandline_options.dart'; |
| 13 import 'package:compiler/src/compiler.dart'; | 12 import 'package:compiler/src/compiler.dart'; |
| 14 import 'package:compiler/src/elements/elements.dart'; | 13 import 'package:compiler/src/elements/elements.dart'; |
| 15 import 'package:compiler/src/filenames.dart'; | 14 import 'package:compiler/src/filenames.dart'; |
| 16 import 'package:compiler/src/serialization/equivalence.dart'; | 15 import 'package:compiler/src/serialization/equivalence.dart'; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 verbose ? compiler2.coreClasses.objectClass : node2.cls)); | 232 verbose ? compiler2.coreClasses.objectClass : node2.cls)); |
| 234 } | 233 } |
| 235 Expect.isFalse(child.isInstantiated, | 234 Expect.isFalse(child.isInstantiated, |
| 236 'Missing subclass ${child.cls} of ${node1.cls} in ' | 235 'Missing subclass ${child.cls} of ${node1.cls} in ' |
| 237 '${node2.directSubclasses}'); | 236 '${node2.directSubclasses}'); |
| 238 } | 237 } |
| 239 } | 238 } |
| 240 checkMixinUses(compiler1, compiler2, node1.cls, node2.cls, verbose: verbose); | 239 checkMixinUses(compiler1, compiler2, node1.cls, node2.cls, verbose: verbose); |
| 241 } | 240 } |
| 242 | 241 |
| 243 void checkSets( | |
| 244 Iterable set1, | |
| 245 Iterable set2, | |
| 246 String messagePrefix, | |
| 247 bool sameElement(a, b), | |
| 248 {bool failOnUnfound: true, | |
| 249 bool verbose: false, | |
| 250 void onSameElement(a, b)}) { | |
| 251 List common = []; | |
| 252 List unfound = []; | |
| 253 Set remaining = computeSetDifference( | |
| 254 set1, set2, common, unfound, | |
| 255 sameElement: sameElement, | |
| 256 checkElements: onSameElement); | |
| 257 StringBuffer sb = new StringBuffer(); | |
| 258 sb.write("$messagePrefix:"); | |
| 259 if (verbose) { | |
| 260 sb.write("\n Common:\n ${common.join('\n ')}"); | |
| 261 } | |
| 262 if (unfound.isNotEmpty || verbose) { | |
| 263 sb.write("\n Unfound:\n ${unfound.join('\n ')}"); | |
| 264 } | |
| 265 if (remaining.isNotEmpty || verbose) { | |
| 266 sb.write("\n Extra: \n ${remaining.join('\n ')}"); | |
| 267 } | |
| 268 String message = sb.toString(); | |
| 269 if (unfound.isNotEmpty || remaining.isNotEmpty) { | |
| 270 | |
| 271 if (failOnUnfound || remaining.isNotEmpty) { | |
| 272 Expect.fail(message); | |
| 273 } else { | |
| 274 print(message); | |
| 275 } | |
| 276 } else if (verbose) { | |
| 277 print(message); | |
| 278 } | |
| 279 } | |
| 280 | |
| 281 String defaultToString(obj) => '$obj'; | |
| 282 | |
| 283 void checkMaps( | |
| 284 Map map1, | |
| 285 Map map2, | |
| 286 String messagePrefix, | |
| 287 bool sameKey(a, b), | |
| 288 bool sameValue(a, b), | |
| 289 {bool failOnUnfound: true, | |
| 290 bool failOnMismatch: true, | |
| 291 bool verbose: false, | |
| 292 String keyToString(key): defaultToString, | |
| 293 String valueToString(key): defaultToString}) { | |
| 294 List common = []; | |
| 295 List unfound = []; | |
| 296 List<List> mismatch = <List>[]; | |
| 297 Set remaining = computeSetDifference( | |
| 298 map1.keys, map2.keys, common, unfound, | |
| 299 sameElement: sameKey, | |
| 300 checkElements: (k1, k2) { | |
| 301 var v1 = map1[k1]; | |
| 302 var v2 = map2[k2]; | |
| 303 if (!sameValue(v1, v2)) { | |
| 304 mismatch.add([k1, k2]); | |
| 305 } | |
| 306 }); | |
| 307 StringBuffer sb = new StringBuffer(); | |
| 308 sb.write("$messagePrefix:"); | |
| 309 if (verbose) { | |
| 310 sb.write("\n Common: \n"); | |
| 311 for (List pair in common) { | |
| 312 var k1 = pair[0]; | |
| 313 var k2 = pair[1]; | |
| 314 var v1 = map1[k1]; | |
| 315 var v2 = map2[k2]; | |
| 316 sb.write(" key1 =${keyToString(k1)}\n"); | |
| 317 sb.write(" key2 =${keyToString(k2)}\n"); | |
| 318 sb.write(" value1=${valueToString(v1)}\n"); | |
| 319 sb.write(" value2=${valueToString(v2)}\n"); | |
| 320 } | |
| 321 } | |
| 322 if (unfound.isNotEmpty || verbose) { | |
| 323 sb.write("\n Unfound: \n"); | |
| 324 for (var k1 in unfound) { | |
| 325 var v1 = map1[k1]; | |
| 326 sb.write(" key1 =${keyToString(k1)}\n"); | |
| 327 sb.write(" value1=${valueToString(v1)}\n"); | |
| 328 } | |
| 329 } | |
| 330 if (remaining.isNotEmpty || verbose) { | |
| 331 sb.write("\n Extra: \n"); | |
| 332 for (var k2 in remaining) { | |
| 333 var v2 = map2[k2]; | |
| 334 sb.write(" key2 =${keyToString(k2)}\n"); | |
| 335 sb.write(" value2=${valueToString(v2)}\n"); | |
| 336 } | |
| 337 } | |
| 338 if (mismatch.isNotEmpty || verbose) { | |
| 339 sb.write("\n Mismatch: \n"); | |
| 340 for (List pair in mismatch) { | |
| 341 var k1 = pair[0]; | |
| 342 var k2 = pair[1]; | |
| 343 var v1 = map1[k1]; | |
| 344 var v2 = map2[k2]; | |
| 345 sb.write(" key1 =${keyToString(k1)}\n"); | |
| 346 sb.write(" key2 =${keyToString(k2)}\n"); | |
| 347 sb.write(" value1=${valueToString(v1)}\n"); | |
| 348 sb.write(" value2=${valueToString(v2)}\n"); | |
| 349 } | |
| 350 } | |
| 351 String message = sb.toString(); | |
| 352 if (unfound.isNotEmpty || mismatch.isNotEmpty || remaining.isNotEmpty) { | |
| 353 if ((unfound.isNotEmpty && failOnUnfound) || | |
| 354 (mismatch.isNotEmpty && failOnMismatch) || | |
| 355 remaining.isNotEmpty) { | |
| 356 Expect.fail(message); | |
| 357 } else { | |
| 358 print(message); | |
| 359 } | |
| 360 } else if (verbose) { | |
| 361 print(message); | |
| 362 } | |
| 363 } | |
| 364 | |
| 365 bool areLocalsEquivalent(Local a, Local b) { | 242 bool areLocalsEquivalent(Local a, Local b) { |
| 366 if (a == b) return true; | 243 if (a == b) return true; |
| 367 if (a == null || b == null) return false; | 244 if (a == null || b == null) return false; |
| 368 | 245 |
| 369 if (a is Element) { | 246 if (a is Element) { |
| 370 return b is Element && areElementsEquivalent(a as Element, b as Element); | 247 return b is Element && areElementsEquivalent(a as Element, b as Element); |
| 371 } else { | 248 } else { |
| 372 return a.runtimeType == b.runtimeType && | 249 return a.runtimeType == b.runtimeType && |
| 373 areElementsEquivalent(a.executableContext, b.executableContext); | 250 areElementsEquivalent(a.executableContext, b.executableContext); |
| 374 } | 251 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 403 return true; | 280 return true; |
| 404 } | 281 } |
| 405 | 282 |
| 406 String nodeToString(Node node) { | 283 String nodeToString(Node node) { |
| 407 String text = '$node'; | 284 String text = '$node'; |
| 408 if (text.length > 40) { | 285 if (text.length > 40) { |
| 409 return '(${node.runtimeType}) ${text.substring(0, 37)}...'; | 286 return '(${node.runtimeType}) ${text.substring(0, 37)}...'; |
| 410 } | 287 } |
| 411 return '(${node.runtimeType}) $text'; | 288 return '(${node.runtimeType}) $text'; |
| 412 } | 289 } |
| OLD | NEW |