@@ -329,7 +329,8 @@ class B {}
329329 var parsedLibrary = session.getParsedLibraryValid (testFile);
330330
331331 var element = libraryResult.element2.getClass2 ('A' )! ;
332- var declaration = parsedLibrary.getFragmentDeclaration (element.firstFragment)! ;
332+ var declaration =
333+ parsedLibrary.getFragmentDeclaration (element.firstFragment)! ;
333334 var node = declaration.node as ClassDeclaration ;
334335 expect (node.name.lexeme, 'A' );
335336 expect (node.offset, 0 );
@@ -582,14 +583,16 @@ class B2 extends X {}
582583 expect (bUnitResult.unit.declarations, hasLength (2 ));
583584 expect (bUnitResult.errors, isNotEmpty);
584585
585- var aDeclaration = resolvedLibrary.getFragmentDeclaration (aClass.firstFragment)! ;
586+ var aDeclaration =
587+ resolvedLibrary.getFragmentDeclaration (aClass.firstFragment)! ;
586588 var aNode = aDeclaration.node as ClassDeclaration ;
587589 expect (aNode.name.lexeme, 'A' );
588590 expect (aNode.offset, 16 );
589591 expect (aNode.length, 16 );
590592 expect (aNode.declaredFragment! .name2, 'A' );
591593
592- var bDeclaration = resolvedLibrary.getFragmentDeclaration (bClass.firstFragment)! ;
594+ var bDeclaration =
595+ resolvedLibrary.getFragmentDeclaration (bClass.firstFragment)! ;
593596 var bNode = bDeclaration.node as ClassDeclaration ;
594597 expect (bNode.name.lexeme, 'B' );
595598 expect (bNode.offset, 19 );
@@ -708,6 +711,50 @@ part 'c.dart';
708711 expect (result, isA <NotElementOfThisSessionResult >());
709712 }
710713
714+ test_getResolvedLibraryContaining_library () async {
715+ var a = newFile ('$testPackageLibPath /a.dart' , '' );
716+ var currentSession = contextFor (a).currentSession;
717+ var filePath = a.toUri ().toFilePath ();
718+ var result = await currentSession.getResolvedLibraryContaining (filePath);
719+ var units = (result as ResolvedLibraryResult ).units;
720+ var paths = units.map ((unit) => unit.path);
721+ expect (paths, unorderedEquals ([a.path]));
722+ }
723+
724+ test_getResolvedLibraryContaining_part () async {
725+ var lib = newFile ('$testPackageLibPath /lib.dart' , r'''
726+ part 'part.dart';
727+ ''' );
728+ var part = newFile ('$testPackageLibPath /part.dart' , r'''
729+ part of 'lib.dart';
730+ ''' );
731+ var currentSession = contextFor (part).currentSession;
732+ var filePath = part.toUri ().toFilePath ();
733+ var result = await currentSession.getResolvedLibraryContaining (filePath);
734+ var units = (result as ResolvedLibraryResult ).units;
735+ var paths = units.map ((unit) => unit.path);
736+ expect (paths, unorderedEquals ([lib.path, part.path]));
737+ }
738+
739+ test_getResolvedLibraryContaining_part_part () async {
740+ var lib = newFile ('$testPackageLibPath /lib.dart' , r'''
741+ part 'part.dart';
742+ ''' );
743+ var part = newFile ('$testPackageLibPath /part.dart' , r'''
744+ part of 'lib.dart';
745+ part 'part_part.dart';
746+ ''' );
747+ var partPart = newFile ('$testPackageLibPath /part_part.dart' , r'''
748+ part of 'part.dart';
749+ ''' );
750+ var currentSession = contextFor (partPart).currentSession;
751+ var filePath = partPart.toUri ().toFilePath ();
752+ var result = await currentSession.getResolvedLibraryContaining (filePath);
753+ var units = (result as ResolvedLibraryResult ).units;
754+ var paths = units.map ((unit) => unit.path);
755+ expect (paths, unorderedEquals ([lib.path, part.path, partPart.path]));
756+ }
757+
711758 test_getResolvedUnit () async {
712759 var test = newFile (testFile.path, r'''
713760class A {}
@@ -907,7 +954,8 @@ unitElementResult
907954 var element = result.fragment as CompilationUnitElementImpl ;
908955 sink.writelnWithIndent ('reference: ${element .reference }' );
909956
910- var library = (element as LibraryFragment ).element as LibraryElementImpl ;
957+ var library =
958+ (element as LibraryFragment ).element as LibraryElementImpl ;
911959 sink.writelnWithIndent ('library: ${library .reference }' );
912960
913961 var classListStr = element.classes2.map ((e) => e.name2).join (', ' );
0 commit comments