@@ -8,10 +8,8 @@ library json_serializable.test.json_generator_test;
8
8
// TODO(kevmoo): test all flavors of `nullable` - class, fields, etc
9
9
10
10
import 'dart:async' ;
11
- import 'dart:io' ;
12
11
13
12
import 'package:analyzer/dart/ast/ast.dart' ;
14
- import 'package:analyzer/src/string_source.dart' ;
15
13
import 'package:dart_style/dart_style.dart' as dart_style;
16
14
import 'package:json_serializable/json_serializable.dart' ;
17
15
import 'package:json_serializable/src/constants.dart' ;
@@ -34,7 +32,7 @@ Matcher _throwsInvalidGenerationSourceError(messageMatcher, todoMatcher) =>
34
32
35
33
void main () {
36
34
setUpAll (() async {
37
- _compUnit = await _getCompilationUnitForString (getPackagePath () );
35
+ _compUnit = await _getCompilationUnitForString ();
38
36
});
39
37
40
38
group ('without wrappers' ,
@@ -512,14 +510,12 @@ abstract class _$SubTypeSerializerMixin {
512
510
513
511
final _formatter = new dart_style.DartFormatter ();
514
512
515
- Future <CompilationUnit > _getCompilationUnitForString (String projectPath) async {
516
- var fileName = 'json_serializable_test_input.dart' ;
517
- var filePath = p.join (getPackagePath (), 'test' , 'src' , fileName);
518
- var source =
519
- new StringSource (new File (filePath).readAsStringSync (), fileName);
520
-
521
- var context = await getAnalysisContextForProjectPath (projectPath);
513
+ Future <CompilationUnit > _getCompilationUnitForString () async {
514
+ var context = await getAnalysisContextForProjectPath (getPackagePath ());
522
515
516
+ var fileUri = p.toUri (p.join (
517
+ getPackagePath (), 'test' , 'src' , 'json_serializable_test_input.dart' ));
518
+ var source = context.sourceFactory.forUri2 (fileUri);
523
519
var libElement = context.computeLibraryElement (source);
524
520
return context.resolveCompilationUnit (source, libElement);
525
521
}
0 commit comments