mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:59:47 +00:00
9336e199fd
This CL is identical to the reverted CL 2990703002 which implements syntactic support for generalized void in the analyzer, plus two bug fixes in pkg/analyzer/test/generated/parser_test.dart and pkg/analyzer_cli/test/error_test.dart. In the former, a test on parsing `void,` was changed to expect an error: _isTypeIdentifier on a lone `void` will no longer return true, which is necessary because `void` can now be used as a type annotation alone. Another test on `void x` was added, which produces the behavior previously seen for `void,`. In error_test, the error which is used throughout was changed from `void foo;` to `var int foo;` (because the former is no longer an error). Review-Url: https://codereview.chromium.org/2992623002 .
56 lines
1.8 KiB
Dart
56 lines
1.8 KiB
Dart
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
library analyzer_cli.test.error;
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'utils.dart';
|
|
|
|
const badDeclaration = 'var int foo;';
|
|
const badDeclarationMessage = 'Error in test.dart: '
|
|
'Variables can\'t be declared using both \'var\' and a type name.\n';
|
|
|
|
void main() {
|
|
group('error', () {
|
|
test("a valid Dart file doesn't throw any errors", () {
|
|
expect(errorsForFile('void main() => print("Hello, world!");'), isNull);
|
|
});
|
|
|
|
test("an empty Dart file doesn't throw any errors", () {
|
|
expect(errorsForFile(''), isNull);
|
|
});
|
|
|
|
test("an error on the first line", () {
|
|
expect(errorsForFile('$badDeclaration\n'), equals(badDeclarationMessage));
|
|
});
|
|
|
|
test("an error on the last line", () {
|
|
expect(errorsForFile('\n$badDeclaration'), equals(badDeclarationMessage));
|
|
});
|
|
|
|
test("an error in the middle", () {
|
|
expect(
|
|
errorsForFile('\n$badDeclaration\n'), equals(badDeclarationMessage));
|
|
});
|
|
|
|
var veryLongString = new List.filled(107, ' ').join('');
|
|
|
|
test("an error at the end of a very long line", () {
|
|
expect(errorsForFile('$veryLongString $badDeclaration'),
|
|
equals(badDeclarationMessage));
|
|
});
|
|
|
|
test("an error at the beginning of a very long line", () {
|
|
expect(errorsForFile('$badDeclaration $veryLongString'),
|
|
equals(badDeclarationMessage));
|
|
});
|
|
|
|
test("an error in the middle of a very long line", () {
|
|
expect(errorsForFile('$veryLongString $badDeclaration$veryLongString'),
|
|
equals(badDeclarationMessage));
|
|
});
|
|
});
|
|
}
|