Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: pkg/analyzer2dart/test/sexpr_test.dart

Issue 762213002: Support top-level field declaration and assignment in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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';
11 import 'package:analyzer/src/generated/source.dart'; 11 import 'package:analyzer/src/generated/source.dart';
12 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; 12 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart';
13 import 'package:compiler/src/elements/elements.dart' as dart2js;
13 import 'package:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
14 15
15 import '../lib/src/closed_world.dart'; 16 import '../lib/src/closed_world.dart';
16 import '../lib/src/driver.dart'; 17 import '../lib/src/driver.dart';
17 import '../lib/src/converted_world.dart'; 18 import '../lib/src/converted_world.dart';
18 import 'output_helper.dart'; 19 import 'output_helper.dart';
19 import 'test_helper.dart'; 20 import 'test_helper.dart';
20 import 'sexpr_data.dart'; 21 import 'sexpr_data.dart';
21 22
22 main() { 23 main() {
23 performTests(TEST_DATA, unittester, checkResult); 24 performTests(TEST_DATA, unittester, checkResult);
24 } 25 }
25 26
26 checkResult(TestSpec result) { 27 checkResult(TestSpec result) {
27 String input = result.input.trim(); 28 String input = result.input.trim();
28 String expectedOutput = result.output.trim();
29 CollectingOutputProvider outputProvider = new CollectingOutputProvider(); 29 CollectingOutputProvider outputProvider = new CollectingOutputProvider();
30 MemoryResourceProvider provider = new MemoryResourceProvider(); 30 MemoryResourceProvider provider = new MemoryResourceProvider();
31 DartSdk sdk = new MockSdk(); 31 DartSdk sdk = new MockSdk();
32 Driver driver = new Driver(provider, sdk, outputProvider); 32 Driver driver = new Driver(provider, sdk, outputProvider);
33 String rootFile = '/root.dart'; 33 String rootFile = '/root.dart';
34 provider.newFile(rootFile, input); 34 provider.newFile(rootFile, input);
35 Source rootSource = driver.setRoot(rootFile); 35 Source rootSource = driver.setRoot(rootFile);
36 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource); 36 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource);
37 ClosedWorld world = driver.computeWorld(entryPoint); 37 ClosedWorld world = driver.computeWorld(entryPoint);
38 ConvertedWorld convertedWorld = convertWorld(world); 38 ConvertedWorld convertedWorld = convertWorld(world);
39 String output = convertedWorld.getIr(convertedWorld.mainFunction) 39
40 .accept(new SExpressionStringifier()); 40 void checkOutput(dart2js.Element element, String expectedOutput) {
41 expect(output, equals(expectedOutput), 41 expectedOutput = expectedOutput.trim();
42 reason: 'Input:\n$input\n' 42 String output = convertedWorld.getIr(element)
43 'Expected:\n$expectedOutput\n' 43 .accept(new SExpressionStringifier());
44 'Actual:\n$output'); 44 expect(output, equals(expectedOutput),
45 reason: 'Input:\n$input\n'
46 'Expected:\n$expectedOutput\n'
47 'Actual:\n$output');
48 }
49
50 if (result.output is String) {
51 checkOutput(convertedWorld.mainFunction, result.output);
52 } else {
53 assert(result.output is Map<String, String>);
54 dart2js.LibraryElement mainLibrary = convertedWorld.mainFunction.library;
55 result.output.forEach((String elementName, String output) {
56 convertedWorld.resolvedElements.forEach((dart2js.Element element) {
57 if (element.name == elementName &&
58 element.library == mainLibrary) {
59 checkOutput(element, output);
60 }
61 });
62 });
63 }
45 } 64 }
46 65
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698