Files
sdk/pkg/analyzer/test/parse_compilation_unit_test.dart
T
danrubel 718e1578a0 Update Analyzer AstBuilder to optionally parse function bodies
Change-Id: I4fa60b12315f1a16eb288b3431bb308d4d4f52db
Reviewed-on: https://dart-review.googlesource.com/57021
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
2018-05-29 18:18:56 +00:00

49 lines
1.8 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.
library analyzer.test.parse_compilation_unit_test;
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();"));
});
}