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