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

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

Issue 1248483008: Split MessageKind into a MessageKind key and a MessageTemplate. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 5 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/dart2jslib.dart"; 8 import "package:compiler/src/dart2jslib.dart";
9 import "package:compiler/src/elements/elements.dart"; 9 import "package:compiler/src/elements/elements.dart";
10 import "package:compiler/src/resolution/resolution.dart"; 10 import "package:compiler/src/resolution/resolution.dart";
11 import "package:compiler/src/util/util.dart"; 11 import "package:compiler/src/util/util.dart";
12 import "mock_compiler.dart"; 12 import "mock_compiler.dart";
13 13
14 14
15 class CallbackMockCompiler extends MockCompiler { 15 class CallbackMockCompiler extends MockCompiler {
16 CallbackMockCompiler() : super.internal(); 16 CallbackMockCompiler() : super.internal();
17 17
18 var onError; 18 var onError;
19 var onWarning; 19 var onWarning;
20 20
21 setOnError(var f) => onError = f; 21 setOnError(var f) => onError = f;
22 setOnWarning(var f) => onWarning = f; 22 setOnWarning(var f) => onWarning = f;
23 23
24 void reportWarning(Spannable node, 24 void reportWarning(Spannable node,
25 MessageKind messageKind, 25 MessageKind messageKind,
26 [Map arguments = const {}]) { 26 [Map arguments = const {}]) {
27 if (onWarning != null) { 27 if (onWarning != null) {
28 onWarning(this, node, messageKind.message(arguments)); 28 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind];
29 onWarning(this, node, template.message(arguments));
29 } 30 }
30 super.reportWarning(node, messageKind, arguments); 31 super.reportWarning(node, messageKind, arguments);
31 } 32 }
32 33
33 void reportError(Spannable node, 34 void reportError(Spannable node,
34 MessageKind messageKind, 35 MessageKind messageKind,
35 [Map arguments = const {}]) { 36 [Map arguments = const {}]) {
36 if (onError != null) { 37 if (onError != null) {
37 onError(this, node, messageKind.message(arguments)); 38 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind];
39 onError(this, node, template.message(arguments));
38 } 40 }
39 super.reportError(node, messageKind, arguments); 41 super.reportError(node, messageKind, arguments);
40 } 42 }
41 } 43 }
42 44
43 Future testErrorHandling() { 45 Future testErrorHandling() {
44 // Test that compiler.currentElement is set correctly when 46 // Test that compiler.currentElement is set correctly when
45 // reporting errors/warnings. 47 // reporting errors/warnings.
46 CallbackMockCompiler compiler = new CallbackMockCompiler(); 48 CallbackMockCompiler compiler = new CallbackMockCompiler();
47 return compiler.init().then((_) { 49 return compiler.init().then((_) {
48 ResolverVisitor visitor = compiler.resolverVisitor(); 50 ResolverVisitor visitor = compiler.resolverVisitor();
49 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}'); 51 compiler.parseScript('NoSuchPrefix.NoSuchType foo() {}');
50 FunctionElement foo = compiler.mainApp.find('foo'); 52 FunctionElement foo = compiler.mainApp.find('foo');
51 compiler.setOnWarning( 53 compiler.setOnWarning(
52 (c, n, m) => Expect.equals(foo, compiler.currentElement)); 54 (c, n, m) => Expect.equals(foo, compiler.currentElement));
53 foo.computeType(compiler); 55 foo.computeType(compiler);
54 Expect.equals(1, compiler.warnings.length); 56 Expect.equals(1, compiler.warnings.length);
55 }); 57 });
56 } 58 }
57 59
58 main() { 60 main() {
59 asyncTest(() => testErrorHandling()); 61 asyncTest(() => testErrorHandling());
60 } 62 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/compiler_helper.dart ('k') | tests/compiler/dart2js/import_mirrors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698