| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Test that deprecated language features are diagnosed correctly. | |
| 6 | |
| 7 import "package:expect/expect.dart"; | |
| 8 import 'dart:async'; | |
| 9 | |
| 10 import '../../../sdk/lib/_internal/compiler/compiler.dart'; | |
| 11 import '../../utils/dummy_compiler_test.dart' as dummy; | |
| 12 | |
| 13 main() { | |
| 14 StringBuffer messages = new StringBuffer(); | |
| 15 void handler(Uri uri, int begin, int end, String message, Diagnostic kind) { | |
| 16 if (kind == Diagnostic.VERBOSE_INFO) return; | |
| 17 if (identical(kind.name, 'source map')) return; | |
| 18 if (uri == null) { | |
| 19 messages.write('$kind: $message\n'); | |
| 20 } else { | |
| 21 Expect.equals('main:${uri.path}', '$uri'); | |
| 22 String source = TEST_SOURCE[uri.path]; | |
| 23 Expect.isNotNull(source); | |
| 24 messages.write('$begin<${source.substring(begin, end)}>:${uri.path}:' | |
| 25 '$kind: $message\n'); | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 Future<String> provider(Uri uri) { | |
| 30 if (uri.scheme != "main") return dummy.provider(uri); | |
| 31 String source = TEST_SOURCE[uri.path]; | |
| 32 Expect.isNotNull(source); | |
| 33 return new Future<String>.value(source); | |
| 34 } | |
| 35 | |
| 36 String code = deprecatedFutureValue( | |
| 37 compile(new Uri(scheme: 'main'), | |
| 38 new Uri(scheme: 'lib', path: '/'), | |
| 39 new Uri(scheme: 'package', path: '/'), | |
| 40 provider, handler)); | |
| 41 if (code == null) { | |
| 42 throw 'Compilation failed: ${messages}'; | |
| 43 } | |
| 44 Expect.stringEquals( | |
| 45 // This string is composed of lines of the following format: | |
| 46 // | |
| 47 // offset<source>:path:kind: message | |
| 48 // | |
| 49 // "offset" is the character offset from the beginning of TEST_SOURCE. | |
| 50 // "source" is the substring of TEST_SOURCE that the compiler is | |
| 51 // indicating as erroneous. | |
| 52 // "path" is the URI path. | |
| 53 // "kind" is the result of calling toString on a [Diagnostic] object. | |
| 54 // "message" is the expected message as a [String]. This is a | |
| 55 // short-term solution and should eventually changed to include | |
| 56 // a symbolic reference to a MessageKind. | |
| 57 "", | |
| 58 messages.toString()); | |
| 59 } | |
| 60 | |
| 61 deprecatedMessage(feature) { | |
| 62 return | |
| 63 "warning: Warning: Deprecated language feature, $feature" | |
| 64 ", will be removed in a future Dart milestone."; | |
| 65 } | |
| 66 | |
| 67 const Map<String, String> TEST_SOURCE = | |
| 68 const <String, String>{ '': """ | |
| 69 class Foo { | |
| 70 } | |
| 71 | |
| 72 main() { | |
| 73 var a = new Foo(); | |
| 74 } | |
| 75 """, | |
| 76 }; | |
| OLD | NEW |