OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.test.parse_compilation_unit_test; | 5 library analyzer.test.parse_compilation_unit_test; |
6 | 6 |
7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 | 9 |
10 import 'utils.dart'; | 10 import 'utils.dart'; |
11 | 11 |
12 void main() { | 12 void main() { |
13 initializeTestEnvironment(); | 13 initializeTestEnvironment(); |
14 test("parses a valid compilation unit successfully", () { | 14 test("parses a valid compilation unit successfully", () { |
15 var unit = parseCompilationUnit("void main() => print('Hello, world!');"); | 15 var unit = parseCompilationUnit("void main() => print('Hello, world!');"); |
16 expect(unit.toString(), equals("void main() => print('Hello, world!');")); | 16 expect(unit.toString(), equals("void main() => print('Hello, world!');")); |
17 }); | 17 }); |
18 | 18 |
19 test("throws errors for an invalid compilation unit", () { | 19 test("throws errors for an invalid compilation unit", () { |
20 expect(() { | 20 expect(() { |
21 parseCompilationUnit("void main() => print('Hello, world!')", | 21 parseCompilationUnit("void main() => print('Hello, world!')", |
22 name: 'test.dart'); | 22 name: 'test.dart'); |
23 }, throwsA(predicate((error) { | 23 }, throwsA(predicate((error) { |
24 return error is AnalyzerErrorGroup && | 24 return error is AnalyzerErrorGroup && |
25 error.toString().contains("Error in test.dart: Expected to find ';'"); | 25 error.toString().contains("Error in test.dart: Expected to find ';'"); |
26 }))); | 26 }))); |
27 }); | 27 }); |
28 | 28 |
29 test("defaults to '<unknown source>' if no name is provided", () { | 29 test("defaults to 'null' if no name is provided", () { |
30 expect(() { | 30 expect(() { |
31 parseCompilationUnit("void main() => print('Hello, world!')"); | 31 parseCompilationUnit("void main() => print('Hello, world!')"); |
32 }, throwsA(predicate((error) { | 32 }, throwsA(predicate((error) { |
33 return error is AnalyzerErrorGroup && | 33 return error is AnalyzerErrorGroup && |
34 error | 34 error.toString().contains("Error in null: Expected to find ';'"); |
Paul Berry
2016/03/01 17:14:32
It seems like a shame to expose the user to the ph
Brian Wilkerson
2016/03/02 16:31:00
You're right, that is better. Done.
| |
35 .toString() | |
36 .contains("Error in <unknown source>: Expected to find ';'"); | |
37 }))); | 35 }))); |
38 }); | 36 }); |
39 | 37 |
40 test("allows you to specify whether or not to parse function bodies", () { | 38 test("allows you to specify whether or not to parse function bodies", () { |
41 var unit = parseCompilationUnit("void main() => print('Hello, world!');", | 39 var unit = parseCompilationUnit("void main() => print('Hello, world!');", |
42 parseFunctionBodies: false); | 40 parseFunctionBodies: false); |
43 expect(unit.toString(), equals("void main();")); | 41 expect(unit.toString(), equals("void main();")); |
44 }); | 42 }); |
45 } | 43 } |
OLD | NEW |