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