OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 import 'package:async_helper/async_helper.dart'; | |
6 import 'package:compiler/src/commandline_options.dart'; | |
7 import 'package:compiler/src/diagnostics/messages.dart'; | |
8 import 'package:compiler/src/io/source_file.dart'; | |
9 import 'package:expect/expect.dart'; | |
10 import 'memory_compiler.dart'; | |
11 import 'memory_source_file_helper.dart'; | |
12 | |
13 const List<Test> TESTS = const <Test>[ | |
14 const Test(''' | |
15 class A { A(b); } | |
16 class B extends A { | |
17 a() {} | |
18 | |
19 lot() {} | |
20 | |
21 of() {} | |
22 | |
23 var members; | |
24 } | |
25 main() => B();''', | |
26 const { | |
27 MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT: ''' | |
28 class B extends A { | |
29 ^^^^^^^^^^^^^^^^^^^'''}), | |
ahe
2016/02/04 11:32:33
I suggest this becomes:
class B extends A {
^^^^^
Johnni Winther
2016/02/05 09:14:20
Done.
| |
30 | |
31 const Test(''' | |
32 class A { A(b); } | |
33 class B | |
34 extends A { | |
35 a() {} | |
36 | |
37 lot() {} | |
38 | |
39 of() {} | |
40 | |
41 var members; | |
42 } | |
43 main() => B();''', | |
44 const { | |
45 MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT: ''' | |
46 class B | |
47 extends A { | |
48 '''}), | |
49 | |
50 const Test(''' | |
51 void foo(int a) { | |
52 // a | |
53 // non-empty | |
54 // body | |
55 } | |
56 main() => foo('');''', | |
57 const { | |
58 MessageKind.THIS_IS_THE_METHOD: ''' | |
59 void foo(int a) { | |
60 ^^^^^^^^^^^^^^^'''}), | |
61 | |
62 const Test(''' | |
63 void foo(int a, | |
64 int b) { | |
65 // a | |
66 // non-empty | |
67 // body | |
68 } | |
69 main() => foo('', 0);''', | |
70 const { | |
71 MessageKind.THIS_IS_THE_METHOD: ''' | |
72 void foo(int a, | |
73 int b) { | |
74 '''}), | |
75 | |
76 const Test(''' | |
77 class A { | |
78 int foo() { | |
79 // a | |
80 // non-empty | |
81 // body | |
82 } | |
83 } | |
84 class B extends A { | |
85 int get foo { | |
86 // a | |
87 // non-empty | |
88 // body | |
89 return 0; | |
90 } | |
91 } | |
92 main() => new B();''', | |
93 const { | |
94 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER: ''' | |
95 int get foo { | |
96 ^^^^^^^^^^^''', | |
97 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT: ''' | |
98 int foo() { | |
99 ^^^^^^^^^'''}), | |
100 ]; | |
101 | |
102 class Test { | |
103 final String code; | |
104 final Map<MessageKind, String> kindToSpan; | |
105 | |
106 const Test(this.code, this.kindToSpan); | |
107 } | |
108 | |
109 const String MARKER = '---marker---'; | |
110 | |
111 main() { | |
112 asyncTest(() async { | |
113 var cachedCompiler; | |
114 for (Test test in TESTS) { | |
115 DiagnosticCollector collector = new DiagnosticCollector(); | |
116 CompilationResult result = await runCompiler( | |
117 memorySourceFiles: {'main.dart': test.code}, | |
118 options: [Flags.analyzeOnly], | |
119 diagnosticHandler: collector, | |
120 cachedCompiler: cachedCompiler); | |
121 cachedCompiler = result.compiler; | |
122 MemorySourceFileProvider provider = cachedCompiler.provider; | |
123 Map<MessageKind, String> kindToSpan = | |
124 new Map<MessageKind, String>.from(test.kindToSpan); | |
125 for (CollectedMessage message in collector.messages) { | |
126 String expectedSpanText = kindToSpan[message.messageKind]; | |
127 if (expectedSpanText != null) { | |
128 SourceFile sourceFile = provider.getSourceFile(message.uri); | |
129 String locationMessage = | |
130 sourceFile.getLocationMessage(MARKER, message.begin, message.end); | |
131 // Remove `filename:line:column:` and message. | |
132 String strippedLocationMessage = locationMessage.substring( | |
133 locationMessage.indexOf(MARKER) + MARKER.length + 1); | |
134 Expect.equals(expectedSpanText, strippedLocationMessage, | |
135 "Unexpected span for ${message.messageKind} in\n${test.code}" | |
136 "\nExpected:${expectedSpanText.codeUnits}" | |
137 "\nActual :${strippedLocationMessage.codeUnits}"); | |
138 kindToSpan.remove(message.messageKind); | |
139 } | |
140 } | |
141 kindToSpan.forEach((MessageKind kind, _) { | |
142 Expect.fail("Missing message kin $kind in\n${test.code}"); | |
143 }); | |
144 } | |
145 }); | |
146 } | |
OLD | NEW |