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() => new B();''', |
| 26 const { |
| 27 MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT: ''' |
| 28 class B extends A { |
| 29 ^^^^^^^^^^^^^^^^^'''}), |
| 30 |
| 31 const Test(''' |
| 32 class I {} |
| 33 class A { A(b); } |
| 34 class B extends A implements I { |
| 35 a() {} |
| 36 |
| 37 lot() {} |
| 38 |
| 39 of() {} |
| 40 |
| 41 var members; |
| 42 } |
| 43 main() => new B();''', |
| 44 const { |
| 45 MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT: ''' |
| 46 class B extends A implements I { |
| 47 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'''}), |
| 48 |
| 49 const Test(''' |
| 50 class M<T> {} |
| 51 class A { A(b); } |
| 52 class B extends A with M<int> { |
| 53 a() {} |
| 54 |
| 55 lot() {} |
| 56 |
| 57 of() {} |
| 58 |
| 59 var members; |
| 60 } |
| 61 main() => new B();''', |
| 62 const { |
| 63 MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT: ''' |
| 64 class B extends A with M<int> { |
| 65 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^'''}), |
| 66 |
| 67 const Test(''' |
| 68 class A { A(b); } |
| 69 class B |
| 70 extends A { |
| 71 a() {} |
| 72 |
| 73 lot() {} |
| 74 |
| 75 of() {} |
| 76 |
| 77 var members; |
| 78 } |
| 79 main() => new B();''', |
| 80 const { |
| 81 MessageKind.NO_MATCHING_CONSTRUCTOR_FOR_IMPLICIT: ''' |
| 82 class B |
| 83 extends A { |
| 84 '''}), |
| 85 |
| 86 const Test(''' |
| 87 void foo(int a) { |
| 88 // a |
| 89 // non-empty |
| 90 // body |
| 91 } |
| 92 main() => foo('');''', |
| 93 const { |
| 94 MessageKind.THIS_IS_THE_METHOD: ''' |
| 95 void foo(int a) { |
| 96 ^^^^^^^^^^^^^^^'''}), |
| 97 |
| 98 const Test(''' |
| 99 void foo(int a, |
| 100 int b) { |
| 101 // a |
| 102 // non-empty |
| 103 // body |
| 104 } |
| 105 main() => foo('', 0);''', |
| 106 const { |
| 107 MessageKind.THIS_IS_THE_METHOD: ''' |
| 108 void foo(int a, |
| 109 int b) { |
| 110 '''}), |
| 111 |
| 112 const Test(''' |
| 113 class A { |
| 114 int foo() { |
| 115 // a |
| 116 // non-empty |
| 117 // body |
| 118 } |
| 119 } |
| 120 class B extends A { |
| 121 int get foo { |
| 122 // a |
| 123 // non-empty |
| 124 // body |
| 125 return 0; |
| 126 } |
| 127 } |
| 128 main() => new B();''', |
| 129 const { |
| 130 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER: ''' |
| 131 int get foo { |
| 132 ^^^^^^^^^^^''', |
| 133 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT: ''' |
| 134 int foo() { |
| 135 ^^^^^^^^^'''}), |
| 136 ]; |
| 137 |
| 138 class Test { |
| 139 final String code; |
| 140 final Map<MessageKind, String> kindToSpan; |
| 141 |
| 142 const Test(this.code, this.kindToSpan); |
| 143 } |
| 144 |
| 145 const String MARKER = '---marker---'; |
| 146 |
| 147 main() { |
| 148 asyncTest(() async { |
| 149 var cachedCompiler; |
| 150 for (Test test in TESTS) { |
| 151 DiagnosticCollector collector = new DiagnosticCollector(); |
| 152 CompilationResult result = await runCompiler( |
| 153 memorySourceFiles: {'main.dart': test.code}, |
| 154 options: [Flags.analyzeOnly], |
| 155 diagnosticHandler: collector, |
| 156 cachedCompiler: cachedCompiler); |
| 157 cachedCompiler = result.compiler; |
| 158 MemorySourceFileProvider provider = cachedCompiler.provider; |
| 159 Map<MessageKind, String> kindToSpan = |
| 160 new Map<MessageKind, String>.from(test.kindToSpan); |
| 161 for (CollectedMessage message in collector.messages) { |
| 162 String expectedSpanText = kindToSpan[message.messageKind]; |
| 163 if (expectedSpanText != null) { |
| 164 SourceFile sourceFile = provider.getSourceFile(message.uri); |
| 165 String locationMessage = |
| 166 sourceFile.getLocationMessage(MARKER, message.begin, message.end); |
| 167 // Remove `filename:line:column:` and message. |
| 168 String strippedLocationMessage = locationMessage.substring( |
| 169 locationMessage.indexOf(MARKER) + MARKER.length + 1); |
| 170 Expect.equals(expectedSpanText, strippedLocationMessage, |
| 171 "Unexpected span for ${message.messageKind} in\n${test.code}" |
| 172 "\nExpected:${expectedSpanText.codeUnits}" |
| 173 "\nActual :${strippedLocationMessage.codeUnits}"); |
| 174 kindToSpan.remove(message.messageKind); |
| 175 } |
| 176 } |
| 177 kindToSpan.forEach((MessageKind kind, _) { |
| 178 Expect.fail("Missing message kin $kind in\n${test.code}"); |
| 179 }); |
| 180 } |
| 181 }); |
| 182 } |
OLD | NEW |