forked from cashapp/paparazzi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to provide a file name for Snapshots
Adds a FileNameProvider that can be implemented in any way to specify file names for a recorded Snapshot. Closes feature request cashapp#549
- Loading branch information
Showing
7 changed files
with
108 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
paparazzi/src/main/java/app/cash/paparazzi/FileNameProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package app.cash.paparazzi | ||
|
||
import java.util.Locale | ||
|
||
public interface FileNameProvider { | ||
public fun snapshotFileName(snapshot: Snapshot, extension: String): String | ||
} | ||
|
||
internal class DefaultFileNameProvider( | ||
private val delimiter: String = "_" | ||
) : FileNameProvider { | ||
|
||
override fun snapshotFileName(snapshot: Snapshot, extension: String): String { | ||
val name = snapshot.name | ||
val formattedLabel = if (name != null) { | ||
"$delimiter${name.lowercase(Locale.US).replace("\\s".toRegex(), delimiter)}" | ||
} else { | ||
"" | ||
} | ||
|
||
val testName = snapshot.testName | ||
return "${testName.packageName}${delimiter}${testName.className}${delimiter}${testName.methodName}$formattedLabel.$extension" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters