30f1c7cbab
Change-Id: I3b3affa957ed8cc8c66f2b32c45b7dcd820f9b1e Reviewed-on: https://dart-review.googlesource.com/c/82713 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
48 lines
1.7 KiB
Dart
48 lines
1.7 KiB
Dart
// Copyright (c) 2013, 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.
|
|
|
|
// ignore: deprecated_member_use
|
|
import 'package:analyzer/analyzer.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
void main() {
|
|
test("parses a valid compilation unit successfully", () {
|
|
var unit = parseCompilationUnit("void main() => print('Hello, world!');");
|
|
expect(unit.toString(), equals("void main() => print('Hello, world!');"));
|
|
});
|
|
|
|
test("throws errors for an invalid compilation unit", () {
|
|
expect(() {
|
|
parseCompilationUnit("void main() => print('Hello, world!')",
|
|
name: 'test.dart');
|
|
}, throwsA(predicate((error) {
|
|
return error is AnalyzerErrorGroup &&
|
|
error.toString().contains("Error in test.dart: Expected to find ';'");
|
|
})));
|
|
});
|
|
|
|
test("defaults to '<unknown source>' if no name is provided", () {
|
|
expect(() {
|
|
parseCompilationUnit("void main() => print('Hello, world!')");
|
|
}, throwsA(predicate((error) {
|
|
return error is AnalyzerErrorGroup &&
|
|
error
|
|
.toString()
|
|
.contains("Error in <unknown source>: Expected to find ';'");
|
|
})));
|
|
});
|
|
|
|
test("allows you to specify whether or not to parse function bodies", () {
|
|
var unit = parseCompilationUnit("void main() => print('Hello, world!');",
|
|
parseFunctionBodies: false);
|
|
expect(unit.toString(), equals("void main();"));
|
|
});
|
|
|
|
test("allows you to specify whether or not to parse function bodies 2", () {
|
|
var unit = parseCompilationUnit("void main() { print('Hello, world!'); }",
|
|
parseFunctionBodies: false);
|
|
expect(unit.toString(), equals("void main();"));
|
|
});
|
|
}
|