| 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 dart2dart compiler. | 5 /// Unittest test of the CPS ir generated by the dart2dart compiler. |
| 6 library dart_backend.sexpr2_test; | 6 library dart_backend.sexpr2_test; |
| 7 | 7 |
| 8 import 'package:compiler/src/dart2jslib.dart'; | 8 import 'package:compiler/src/dart2jslib.dart'; |
| 9 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; | 9 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; |
| 10 import 'package:compiler/src/elements/elements.dart'; | 10 import 'package:compiler/src/elements/elements.dart'; |
| 11 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
| 12 | 12 |
| 13 import '../../../../pkg/analyzer2dart/test/test_helper.dart'; | 13 import '../../../../pkg/analyzer2dart/test/test_helper.dart'; |
| 14 import '../../../../pkg/analyzer2dart/test/sexpr_data.dart'; | 14 import '../../../../pkg/analyzer2dart/test/sexpr_data.dart'; |
| 15 | 15 |
| 16 import 'test_helper.dart'; | 16 import 'test_helper.dart'; |
| 17 | 17 |
| 18 main() { | 18 main() { |
| 19 performTests(TEST_DATA, asyncTester, (TestSpec result) { | 19 performTests(TEST_DATA, asyncTester, (TestSpec result) { |
| 20 return compilerFor(result.input).then((Compiler compiler) { | 20 return compilerFor(result.input).then((Compiler compiler) { |
| 21 void checkOutput(Element element, String expectedOutput) { | 21 void checkOutput(String elementName, |
| 22 Element element, |
| 23 String expectedOutput) { |
| 22 expectedOutput = expectedOutput.trim(); | 24 expectedOutput = expectedOutput.trim(); |
| 23 String output = compiler.irBuilder.getIr(element) | 25 String output = compiler.irBuilder.getIr(element) |
| 24 .accept(new SExpressionStringifier()).trim(); | 26 .accept(new SExpressionStringifier()).trim(); |
| 25 Expect.equals(expectedOutput, output, | 27 Expect.equals(expectedOutput, output, |
| 26 '\nInput:\n${result.input}\n' | 28 "\nInput:\n${result.input}\n" |
| 27 'Expected:\n$expectedOutput\n' | 29 "Expected for '$elementName':\n$expectedOutput\n" |
| 28 'Actual:\n$output\n'); | 30 "Actual for '$elementName':\n$output\n"); |
| 29 } | 31 } |
| 30 | 32 |
| 31 if (result.output is String) { | 33 if (result.output is String) { |
| 32 checkOutput(compiler.mainFunction, result.output); | 34 checkOutput('main', compiler.mainFunction, result.output); |
| 33 } else { | 35 } else { |
| 34 assert(result.output is Map<String, String>); | 36 assert(result.output is Map<String, String>); |
| 35 result.output.forEach((String elementName, String output) { | 37 result.output.forEach((String elementName, String output) { |
| 36 checkOutput(compiler.mainApp.localLookup(elementName), output); | 38 Element element; |
| 39 if (elementName.contains('.')) { |
| 40 ClassElement cls = compiler.mainApp.localLookup( |
| 41 elementName.substring(0, elementName.indexOf('.'))); |
| 42 element = cls.localLookup( |
| 43 elementName.substring(elementName.indexOf('.') + 1)); |
| 44 } else { |
| 45 element = compiler.mainApp.localLookup(elementName); |
| 46 } |
| 47 checkOutput(elementName, element, output); |
| 37 }); | 48 }); |
| 38 } | 49 } |
| 39 }); | 50 }); |
| 40 }); | 51 }); |
| 41 } | 52 } |
| OLD | NEW |