| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// Unittest test of the CPS ir generated by the analyzer2dart compiler. | 5 /// Unittest test of the CPS ir generated by the analyzer2dart compiler. |
| 6 | 6 |
| 7 import 'mock_sdk.dart'; | 7 import 'mock_sdk.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
| 10 import 'package:analyzer/src/generated/sdk.dart'; | 10 import 'package:analyzer/src/generated/sdk.dart'; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 MemoryResourceProvider provider = new MemoryResourceProvider(); | 31 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 32 DartSdk sdk = new MockSdk(); | 32 DartSdk sdk = new MockSdk(); |
| 33 Driver driver = new Driver(provider, sdk, outputProvider); | 33 Driver driver = new Driver(provider, sdk, outputProvider); |
| 34 String rootFile = '/root.dart'; | 34 String rootFile = '/root.dart'; |
| 35 provider.newFile(rootFile, input); | 35 provider.newFile(rootFile, input); |
| 36 Source rootSource = driver.setRoot(rootFile); | 36 Source rootSource = driver.setRoot(rootFile); |
| 37 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource); | 37 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource); |
| 38 ClosedWorld world = driver.computeWorld(entryPoint); | 38 ClosedWorld world = driver.computeWorld(entryPoint); |
| 39 ConvertedWorld convertedWorld = convertWorld(world); | 39 ConvertedWorld convertedWorld = convertWorld(world); |
| 40 | 40 |
| 41 void checkOutput(dart2js.Element element, String expectedOutput) { | 41 void checkOutput(String elementName, |
| 42 dart2js.Element element, |
| 43 String expectedOutput) { |
| 42 expectedOutput = expectedOutput.trim(); | 44 expectedOutput = expectedOutput.trim(); |
| 43 String output = convertedWorld.getIr(element) | 45 String output = convertedWorld.getIr(element) |
| 44 .accept(new SExpressionStringifier()); | 46 .accept(new SExpressionStringifier()); |
| 45 expect(output, equals(expectedOutput), | 47 expect(output, equals(expectedOutput), |
| 46 reason: 'Input:\n$input\n' | 48 reason: "\nInput:\n${result.input}\n" |
| 47 'Expected:\n$expectedOutput\n' | 49 "Expected for '$elementName':\n$expectedOutput\n" |
| 48 'Actual:\n$output'); | 50 "Actual for '$elementName':\n$output\n"); |
| 49 } | 51 } |
| 50 | 52 |
| 51 if (result.output is String) { | 53 if (result.output is String) { |
| 52 checkOutput(convertedWorld.mainFunction, result.output); | 54 checkOutput('main', convertedWorld.mainFunction, result.output); |
| 53 } else { | 55 } else { |
| 54 assert(result.output is Map<String, String>); | 56 assert(result.output is Map<String, String>); |
| 55 dart2js.LibraryElement mainLibrary = convertedWorld.mainFunction.library; | 57 dart2js.LibraryElement mainLibrary = convertedWorld.mainFunction.library; |
| 56 result.output.forEach((String elementName, String output) { | 58 result.output.forEach((String elementName, String output) { |
| 59 bool found = false; |
| 60 List<String> names = <String>[]; |
| 57 convertedWorld.resolvedElements.forEach((dart2js.Element element) { | 61 convertedWorld.resolvedElements.forEach((dart2js.Element element) { |
| 58 if (element.name == elementName && | 62 if (element.library == mainLibrary) { |
| 59 element.library == mainLibrary) { | 63 String name = element.name; |
| 60 checkOutput(element, output); | 64 if (element.enclosingClass != null) { |
| 65 name = '${element.enclosingClass.name}.$name'; |
| 66 } |
| 67 if (name == elementName) { |
| 68 checkOutput(elementName, element, output); |
| 69 found = true; |
| 70 } |
| 71 names.add(name); |
| 61 } | 72 } |
| 62 }); | 73 }); |
| 74 expect(found, isTrue, reason: "'$elementName' not found in $names."); |
| 63 }); | 75 }); |
| 64 } | 76 } |
| 65 } | 77 } |
| 66 | 78 |
| OLD | NEW |