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

Side by Side Diff: tests/compiler/dart2js/source_mapping_test.dart

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test Created 4 years, 3 months 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
OLDNEW
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 'package:compiler/src/io/source_information.dart';
11 import 'package:compiler/src/js_backend/js_backend.dart'; 11 import 'package:compiler/src/js_backend/js_backend.dart';
12 import 'package:compiler/src/js_emitter/full_emitter/emitter.dart' 12 import 'package:compiler/src/js_emitter/full_emitter/emitter.dart' as full
13 as full show Emitter; 13 show Emitter;
14 14
15 import 'mock_compiler.dart'; 15 import 'mock_compiler.dart';
16 16
17 Future<CodeBuffer> compileAll(SourceFile sourceFile) { 17 Future<CodeBuffer> compileAll(SourceFile sourceFile) {
18 MockCompiler compiler = new MockCompiler.internal(); 18 MockCompiler compiler = new MockCompiler.internal();
19 Uri uri = new Uri(path: sourceFile.filename); 19 Uri uri = new Uri(path: sourceFile.filename);
20 compiler.sourceFiles[uri.toString()] = sourceFile; 20 compiler.sourceFiles[uri.toString()] = sourceFile;
21 JavaScriptBackend backend = compiler.backend; 21 JavaScriptBackend backend = compiler.backend;
22 return compiler.run(uri).then((_) { 22 return compiler.run(uri).then((_) {
23 // TODO(floitsch): the outputBuffers are only accessible in the full 23 // TODO(floitsch): the outputBuffers are only accessible in the full
24 // emitter. 24 // emitter.
25 full.Emitter fullEmitter = backend.emitter.emitter; 25 full.Emitter fullEmitter = backend.emitter.emitter;
26 return fullEmitter 26 return fullEmitter.outputBuffers[compiler.deferredLoadTask.mainOutputUnit];
27 .outputBuffers[compiler.deferredLoadTask.mainOutputUnit];
28 }); 27 });
29 } 28 }
30 29
31 void testSourceMapLocations(String codeWithMarkers) { 30 void testSourceMapLocations(String codeWithMarkers) {
32 List<int> expectedLocations = new List<int>(); 31 List<int> expectedLocations = new List<int>();
33 for (int i = 0; i < codeWithMarkers.length; ++i) { 32 for (int i = 0; i < codeWithMarkers.length; ++i) {
34 if (codeWithMarkers[i] == '@') { 33 if (codeWithMarkers[i] == '@') {
35 expectedLocations.add(i - expectedLocations.length); 34 expectedLocations.add(i - expectedLocations.length);
36 } 35 }
37 } 36 }
38 String code = codeWithMarkers.replaceAll('@', ''); 37 String code = codeWithMarkers.replaceAll('@', '');
39 38
40 SourceFile sourceFile = new StringSourceFile.fromName('<test script>', code); 39 SourceFile sourceFile = new StringSourceFile.fromName('<test script>', code);
41 asyncTest(() => compileAll(sourceFile).then((CodeOutput output) { 40 asyncTest(() => compileAll(sourceFile).then((CodeOutput output) {
42 Set<int> locations = new Set<int>(); 41 Set<int> locations = new Set<int>();
43 output.forEachSourceLocation((int offset, SourceLocation sourcePosition) { 42 output
44 if (sourcePosition != null && 43 .forEachSourceLocation((int offset, SourceLocation sourcePosition) {
45 sourcePosition.sourceUri == sourceFile.uri) { 44 if (sourcePosition != null &&
46 locations.add(sourcePosition.offset); 45 sourcePosition.sourceUri == sourceFile.uri) {
47 } 46 locations.add(sourcePosition.offset);
48 }); 47 }
48 });
49 49
50 for (int i = 0; i < expectedLocations.length; ++i) { 50 for (int i = 0; i < expectedLocations.length; ++i) {
51 int expectedLocation = expectedLocations[i]; 51 int expectedLocation = expectedLocations[i];
52 if (!locations.contains(expectedLocation)) { 52 if (!locations.contains(expectedLocation)) {
53 int originalLocation = expectedLocation + i; 53 int originalLocation = expectedLocation + i;
54 SourceFile sourceFileWithMarkers = 54 SourceFile sourceFileWithMarkers =
55 new StringSourceFile.fromName('<test script>', codeWithMarkers); 55 new StringSourceFile.fromName('<test script>', codeWithMarkers);
56 String message = sourceFileWithMarkers.getLocationMessage( 56 String message = sourceFileWithMarkers.getLocationMessage(
57 'Missing location', originalLocation, originalLocation + 1); 57 'Missing location', originalLocation, originalLocation + 1);
58 Expect.fail(message); 58 Expect.fail(message);
59 } 59 }
60 } 60 }
61 })); 61 }));
62 } 62 }
63 63
64 String FUNCTIONS_TEST = ''' 64 String FUNCTIONS_TEST = '''
65 @void main() { print(test(15)); @} 65 @void main() { print(test(15)); @}
66 // The 'if' has been added to avoid inlining of 'test'. 66 // The 'if' has been added to avoid inlining of 'test'.
67 @int test(int x) { if (x != null) return x; else return null; @}'''; 67 @int test(int x) { if (x != null) return x; else return null; @}''';
68 68
69 String RETURN_TEST = 'void main() { print(((x) { @return x; })(0)); }'; 69 String RETURN_TEST = 'void main() { print(((x) { @return x; })(0)); }';
70 70
71 String NOT_TEST = 'void main() { ((x) { if (@!x) print(x); })(1==2); }'; 71 String NOT_TEST = 'void main() { ((x) { if (@!x) print(x); })(1==2); }';
72 72
73 String UNARY_TEST = 'void main() { ((x, y) { print(@-x + @~y); })(1,2); }'; 73 String UNARY_TEST = 'void main() { ((x, y) { print(@-x + @~y); })(1,2); }';
74 74
75 String BINARY_TEST = 'void main() { ((x, y) { if (x @!= y) print(x @* y); })(1,2 ); }'; 75 String BINARY_TEST =
76 'void main() { ((x, y) { if (x @!= y) print(x @* y); })(1,2); }';
76 77
77 String SEND_TEST = ''' 78 String SEND_TEST = '''
78 void main() { 79 void main() {
79 @staticSend(0); 80 @staticSend(0);
80 NewSend o = @new NewSend(); 81 NewSend o = @new NewSend();
81 @o.dynamicSend(0); 82 @o.dynamicSend(0);
82 var closureSend = (x) { print(x); }; 83 var closureSend = (x) { print(x); };
83 @closureSend(0); 84 @closureSend(0);
84 } 85 }
85 // The 'if' has been added to avoid inlining of 'staticSend'. 86 // The 'if' has been added to avoid inlining of 'staticSend'.
(...skipping 26 matching lines...) Expand all
112 testSourceMapLocations(FUNCTIONS_TEST); 113 testSourceMapLocations(FUNCTIONS_TEST);
113 testSourceMapLocations(RETURN_TEST); 114 testSourceMapLocations(RETURN_TEST);
114 testSourceMapLocations(NOT_TEST); 115 testSourceMapLocations(NOT_TEST);
115 testSourceMapLocations(UNARY_TEST); 116 testSourceMapLocations(UNARY_TEST);
116 testSourceMapLocations(BINARY_TEST); 117 testSourceMapLocations(BINARY_TEST);
117 testSourceMapLocations(SEND_TEST); 118 testSourceMapLocations(SEND_TEST);
118 testSourceMapLocations(SEND_SET_TEST); 119 testSourceMapLocations(SEND_SET_TEST);
119 testSourceMapLocations(LOOP_TEST); 120 testSourceMapLocations(LOOP_TEST);
120 testSourceMapLocations(INTERCEPTOR_TEST); 121 testSourceMapLocations(INTERCEPTOR_TEST);
121 } 122 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/source_map_validator_test_file.dart ('k') | tests/compiler/dart2js/sourcemaps/colors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698