OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
8 import "package:compiler/src/io/code_output.dart"; | 8 import "package:compiler/src/io/code_output.dart"; |
9 import 'package:compiler/src/source_file.dart'; | 9 import 'package:compiler/src/io/source_file.dart'; |
10 import "mock_compiler.dart"; | 10 import "mock_compiler.dart"; |
11 import 'package:compiler/src/js_backend/js_backend.dart'; | 11 import 'package:compiler/src/js_backend/js_backend.dart'; |
12 | 12 |
13 Future<CodeBuffer> compileAll(SourceFile sourceFile) { | 13 Future<CodeBuffer> compileAll(SourceFile sourceFile) { |
14 MockCompiler compiler = new MockCompiler.internal(); | 14 MockCompiler compiler = new MockCompiler.internal(); |
15 Uri uri = new Uri(path: sourceFile.filename); | 15 Uri uri = new Uri(path: sourceFile.filename); |
16 compiler.sourceFiles[uri.toString()] = sourceFile; | 16 compiler.sourceFiles[uri.toString()] = sourceFile; |
17 JavaScriptBackend backend = compiler.backend; | 17 JavaScriptBackend backend = compiler.backend; |
18 return compiler.runCompiler(uri).then((_) { | 18 return compiler.runCompiler(uri).then((_) { |
19 return backend.emitter.oldEmitter.mainBuffer; | 19 return backend.emitter.oldEmitter |
| 20 .outputBuffers[compiler.deferredLoadTask.mainOutputUnit]; |
20 }); | 21 }); |
21 } | 22 } |
22 | 23 |
23 void testSourceMapLocations(String codeWithMarkers) { | 24 void testSourceMapLocations(String codeWithMarkers) { |
24 List<int> expectedLocations = new List<int>(); | 25 List<int> expectedLocations = new List<int>(); |
25 for (int i = 0; i < codeWithMarkers.length; ++i) { | 26 for (int i = 0; i < codeWithMarkers.length; ++i) { |
26 if (codeWithMarkers[i] == '@') { | 27 if (codeWithMarkers[i] == '@') { |
27 expectedLocations.add(i - expectedLocations.length); | 28 expectedLocations.add(i - expectedLocations.length); |
28 } | 29 } |
29 } | 30 } |
30 String code = codeWithMarkers.replaceAll('@', ''); | 31 String code = codeWithMarkers.replaceAll('@', ''); |
31 | 32 |
32 SourceFile sourceFile = new StringSourceFile('<test script>', code); | 33 SourceFile sourceFile = new StringSourceFile('<test script>', code); |
33 asyncTest(() => compileAll(sourceFile).then((CodeBuffer buffer) { | 34 asyncTest(() => compileAll(sourceFile).then((CodeOutput output) { |
34 Set<int> locations = new Set<int>(); | 35 Set<int> locations = new Set<int>(); |
35 buffer.forEachSourceLocation((int offset, var sourcePosition) { | 36 output.forEachSourceLocation((int offset, var sourcePosition) { |
36 if (sourcePosition != null && sourcePosition.sourceFile == sourceFile) { | 37 if (sourcePosition != null && sourcePosition.sourceFile == sourceFile) { |
37 locations.add(sourcePosition.token.charOffset); | 38 locations.add(sourcePosition.token.charOffset); |
38 } | 39 } |
39 }); | 40 }); |
40 | 41 |
41 for (int i = 0; i < expectedLocations.length; ++i) { | 42 for (int i = 0; i < expectedLocations.length; ++i) { |
42 int expectedLocation = expectedLocations[i]; | 43 int expectedLocation = expectedLocations[i]; |
43 if (!locations.contains(expectedLocation)) { | 44 if (!locations.contains(expectedLocation)) { |
44 int originalLocation = expectedLocation + i; | 45 int originalLocation = expectedLocation + i; |
45 SourceFile sourceFileWithMarkers = | 46 SourceFile sourceFileWithMarkers = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 testSourceMapLocations(FUNCTIONS_TEST); | 104 testSourceMapLocations(FUNCTIONS_TEST); |
104 testSourceMapLocations(RETURN_TEST); | 105 testSourceMapLocations(RETURN_TEST); |
105 testSourceMapLocations(NOT_TEST); | 106 testSourceMapLocations(NOT_TEST); |
106 testSourceMapLocations(UNARY_TEST); | 107 testSourceMapLocations(UNARY_TEST); |
107 testSourceMapLocations(BINARY_TEST); | 108 testSourceMapLocations(BINARY_TEST); |
108 testSourceMapLocations(SEND_TEST); | 109 testSourceMapLocations(SEND_TEST); |
109 testSourceMapLocations(SEND_SET_TEST); | 110 testSourceMapLocations(SEND_SET_TEST); |
110 testSourceMapLocations(LOOP_TEST); | 111 testSourceMapLocations(LOOP_TEST); |
111 testSourceMapLocations(INTERCEPTOR_TEST); | 112 testSourceMapLocations(INTERCEPTOR_TEST); |
112 } | 113 } |
OLD | NEW |