| 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 "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 6 | 7 import "package:async_helper/async_helper.dart"; |
| 7 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; | 8 import "../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart"; |
| 8 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; | 9 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
| 9 import "mock_compiler.dart"; | 10 import "mock_compiler.dart"; |
| 10 import 'parser_helper.dart'; | 11 import 'parser_helper.dart'; |
| 11 | 12 |
| 12 CodeBuffer compileAll(SourceFile sourceFile) { | 13 Future<CodeBuffer> compileAll(SourceFile sourceFile) { |
| 13 MockCompiler compiler = new MockCompiler(); | 14 MockCompiler compiler = new MockCompiler(); |
| 14 Uri uri = new Uri(path: sourceFile.filename); | 15 Uri uri = new Uri(path: sourceFile.filename); |
| 15 compiler.sourceFiles[uri.toString()] = sourceFile; | 16 compiler.sourceFiles[uri.toString()] = sourceFile; |
| 16 compiler.runCompiler(uri); | 17 return compiler.runCompiler(uri).then((_) { |
| 17 return compiler.backend.emitter.mainBuffer; | 18 return compiler.backend.emitter.mainBuffer; |
| 19 }); |
| 18 } | 20 } |
| 19 | 21 |
| 20 void testSourceMapLocations(String codeWithMarkers) { | 22 void testSourceMapLocations(String codeWithMarkers) { |
| 21 List<int> expectedLocations = new List<int>(); | 23 List<int> expectedLocations = new List<int>(); |
| 22 for (int i = 0; i < codeWithMarkers.length; ++i) { | 24 for (int i = 0; i < codeWithMarkers.length; ++i) { |
| 23 if (codeWithMarkers[i] == '@') { | 25 if (codeWithMarkers[i] == '@') { |
| 24 expectedLocations.add(i - expectedLocations.length); | 26 expectedLocations.add(i - expectedLocations.length); |
| 25 } | 27 } |
| 26 } | 28 } |
| 27 String code = codeWithMarkers.replaceAll('@', ''); | 29 String code = codeWithMarkers.replaceAll('@', ''); |
| 28 | 30 |
| 29 SourceFile sourceFile = new SourceFile('<test script>', code); | 31 SourceFile sourceFile = new SourceFile('<test script>', code); |
| 30 CodeBuffer buffer = compileAll(sourceFile); | 32 asyncTest(() => compileAll(sourceFile).then((CodeBuffer buffer) { |
| 33 Set<int> locations = new Set<int>(); |
| 34 buffer.forEachSourceLocation((int offset, var sourcePosition) { |
| 35 if (sourcePosition != null && sourcePosition.sourceFile == sourceFile) { |
| 36 locations.add(sourcePosition.token.charOffset); |
| 37 } |
| 38 }); |
| 31 | 39 |
| 32 Set<int> locations = new Set<int>(); | 40 for (int i = 0; i < expectedLocations.length; ++i) { |
| 33 buffer.forEachSourceLocation((int offset, var sourcePosition) { | 41 int expectedLocation = expectedLocations[i]; |
| 34 if (sourcePosition != null && sourcePosition.sourceFile == sourceFile) { | 42 if (!locations.contains(expectedLocation)) { |
| 35 locations.add(sourcePosition.token.charOffset); | 43 int originalLocation = expectedLocation + i; |
| 44 SourceFile sourceFileWithMarkers = new SourceFile('<test script>', |
| 45 codeWithMarkers); |
| 46 String message = sourceFileWithMarkers.getLocationMessage( |
| 47 'Missing location', originalLocation, originalLocation + 1, true, |
| 48 (s) => s); |
| 49 Expect.fail(message); |
| 50 } |
| 36 } | 51 } |
| 37 }); | 52 })); |
| 38 | |
| 39 for (int i = 0; i < expectedLocations.length; ++i) { | |
| 40 int expectedLocation = expectedLocations[i]; | |
| 41 if (!locations.contains(expectedLocation)) { | |
| 42 int originalLocation = expectedLocation + i; | |
| 43 SourceFile sourceFileWithMarkers = new SourceFile('<test script>', | |
| 44 codeWithMarkers); | |
| 45 String message = sourceFileWithMarkers.getLocationMessage( | |
| 46 'Missing location', originalLocation, originalLocation + 1, true, | |
| 47 (s) => s); | |
| 48 Expect.fail(message); | |
| 49 } | |
| 50 } | |
| 51 } | 53 } |
| 52 | 54 |
| 53 String FUNCTIONS_TEST = ''' | 55 String FUNCTIONS_TEST = ''' |
| 54 @void main() { print(test(15)); @} | 56 @void main() { print(test(15)); @} |
| 55 // The 'if' has been added to avoid inlining of 'test'. | 57 // The 'if' has been added to avoid inlining of 'test'. |
| 56 @int test(int x) { if (x != null) return x; else return null; @}'''; | 58 @int test(int x) { if (x != null) return x; else return null; @}'''; |
| 57 | 59 |
| 58 String RETURN_TEST = 'void main() { print(((x) { @return x; })(0)); }'; | 60 String RETURN_TEST = 'void main() { print(((x) { @return x; })(0)); }'; |
| 59 | 61 |
| 60 String NOT_TEST = 'void main() { ((x) { if (@!x) print(x); })(false); }'; | 62 String NOT_TEST = 'void main() { ((x) { if (@!x) print(x); })(false); }'; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 testSourceMapLocations(FUNCTIONS_TEST); | 103 testSourceMapLocations(FUNCTIONS_TEST); |
| 102 testSourceMapLocations(RETURN_TEST); | 104 testSourceMapLocations(RETURN_TEST); |
| 103 testSourceMapLocations(NOT_TEST); | 105 testSourceMapLocations(NOT_TEST); |
| 104 testSourceMapLocations(UNARY_TEST); | 106 testSourceMapLocations(UNARY_TEST); |
| 105 testSourceMapLocations(BINARY_TEST); | 107 testSourceMapLocations(BINARY_TEST); |
| 106 testSourceMapLocations(SEND_TEST); | 108 testSourceMapLocations(SEND_TEST); |
| 107 testSourceMapLocations(SEND_SET_TEST); | 109 testSourceMapLocations(SEND_SET_TEST); |
| 108 testSourceMapLocations(LOOP_TEST); | 110 testSourceMapLocations(LOOP_TEST); |
| 109 testSourceMapLocations(INTERCEPTOR_TEST); | 111 testSourceMapLocations(INTERCEPTOR_TEST); |
| 110 } | 112 } |
| OLD | NEW |