@@ -568,6 +568,23 @@ public R8JniLayoutView (android.content.Context context, android.util.AttributeS
568568 appBuilder . Output . AssertTargetIsNotSkipped ( "_CompileToDalvik" ) ;
569569 }
570570
571+ [ Test ]
572+ public void R8MappingMemberAssertion_AllowsSourceFileMetadata ( )
573+ {
574+ var mappingFile = Path . GetTempFileName ( ) ;
575+ try {
576+ File . WriteAllText ( mappingFile , """
577+ com.example.R8JniLibraryPeer -> f:
578+ # {"id":"sourceFile","fileName":"R8JniLibraryPeer.java"}
579+ void nctor_0() -> a
580+ """ ) ;
581+
582+ AssertR8MappingContainsMember ( mappingFile , "com/example/R8JniLibraryPeer" , "nctor_0" ) ;
583+ } finally {
584+ File . Delete ( mappingFile ) ;
585+ }
586+ }
587+
571588 [ Test ]
572589 public void Build_WithTrimmableTypeMap_MissingJavaListPreservesGeneratedJava ( )
573590 {
@@ -1717,15 +1734,20 @@ static void AssertR8MappingKeepsClassName (string mappingFile, string originalJn
17171734 static void AssertR8MappingContainsMember ( string mappingFile , string originalJniName , string memberName )
17181735 {
17191736 string originalName = originalJniName . Replace ( '/' , '.' ) ;
1720- var classMapping = Regex . Match (
1721- File . ReadAllText ( mappingFile ) ,
1722- $ "^{ Regex . Escape ( originalName ) } -> [^:]+:\\ r?\\ n(?<members>(?: .*\\ r?\\ n)*)",
1723- RegexOptions . Multiline ) ;
1724- Assert . IsTrue ( classMapping . Success , $ "Expected { mappingFile } to contain a mapping for { originalName } .") ;
1725- Assert . That (
1726- classMapping . Groups [ "members" ] . Value ,
1727- Does . Match ( $@ "\b{ Regex . Escape ( memberName ) } \([^)]*\) -> ") ,
1728- $ "Expected { mappingFile } to retain and map { originalName } .{ memberName } .") ;
1737+ var lines = File . ReadAllLines ( mappingFile ) ;
1738+ string classHeader = $ "{ originalName } -> ";
1739+ int classIndex = Array . FindIndex ( lines , line =>
1740+ line . StartsWith ( classHeader , StringComparison . Ordinal ) &&
1741+ line . EndsWith ( ":" , StringComparison . Ordinal ) ) ;
1742+ Assert . That ( classIndex , Is . GreaterThanOrEqualTo ( 0 ) , $ "Expected { mappingFile } to contain a mapping for { originalName } .") ;
1743+
1744+ var classMapping = lines
1745+ . Skip ( classIndex + 1 )
1746+ . TakeWhile ( line => line . StartsWith ( " " , StringComparison . Ordinal ) || line . StartsWith ( "#" , StringComparison . Ordinal ) )
1747+ . ToArray ( ) ;
1748+ Assert . IsTrue (
1749+ classMapping . Any ( line => Regex . IsMatch ( line , $@ "\b{ Regex . Escape ( memberName ) } \([^)]*\) -> ") ) ,
1750+ $ "Expected { mappingFile } to retain and map { originalName } .{ memberName } . Matching class section:\n { string . Join ( "\n " , classMapping ) } ") ;
17291751 }
17301752
17311753 static Import CreateR8JniManifestMergerInputsAssertionImport ( )
0 commit comments