diff --git a/CHANGELOG.md b/CHANGELOG.md index 62fa09cc..ed95f493 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ### Added +- `resource(name: String): File` function +- `resourceOrNull(name: String): File?` function +- `File.children: Sequence` - `String.transformstring` function - `String.TRANSFORMSTRING` function - `String.transformString` function diff --git a/kotlin-stdlib/android/main/AndroidManifest.xml b/kotlin-stdlib/android/main/AndroidManifest.xml deleted file mode 100644 index bf0a1803..00000000 --- a/kotlin-stdlib/android/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/kotlin-stdlib/api/jvm/kotlin-stdlib.api b/kotlin-stdlib/api/jvm/kotlin-stdlib.api index 58d6df2e..30b6e8e3 100644 --- a/kotlin-stdlib/api/jvm/kotlin-stdlib.api +++ b/kotlin-stdlib/api/jvm/kotlin-stdlib.api @@ -159,6 +159,12 @@ public final class com/javiersc/kotlin/stdlib/CollectionsKt { public static final fun thirdOrNull (Ljava/lang/Iterable;)Ljava/lang/Object; } +public final class com/javiersc/kotlin/stdlib/FilesKt { + public static final fun getChildren (Ljava/io/File;)Lkotlin/sequences/Sequence; + public static final fun resource (Ljava/lang/String;)Ljava/io/File; + public static final fun resourceOrNull (Ljava/lang/String;)Ljava/io/File; +} + public final class com/javiersc/kotlin/stdlib/StringsKt { public static final fun endWithNewLine (Ljava/lang/String;)Ljava/lang/String; public static final fun getEmpty (Lkotlin/jvm/internal/StringCompanionObject;)Ljava/lang/String; diff --git a/kotlin-stdlib/common/test/resources/children-test/A.txt b/kotlin-stdlib/common/test/resources/children-test/A.txt new file mode 100644 index 00000000..e69de29b diff --git a/kotlin-stdlib/common/test/resources/children-test/B.txt b/kotlin-stdlib/common/test/resources/children-test/B.txt new file mode 100644 index 00000000..e69de29b diff --git a/kotlin-stdlib/common/test/resources/children-test/sub-children/C.txt b/kotlin-stdlib/common/test/resources/children-test/sub-children/C.txt new file mode 100644 index 00000000..e69de29b diff --git a/kotlin-stdlib/common/test/resources/children-test/sub-children/D.txt b/kotlin-stdlib/common/test/resources/children-test/sub-children/D.txt new file mode 100644 index 00000000..e69de29b diff --git a/kotlin-stdlib/jvm/main/kotlin/com/javiersc/kotlin/stdlib/Files.kt b/kotlin-stdlib/jvm/main/kotlin/com/javiersc/kotlin/stdlib/Files.kt new file mode 100644 index 00000000..98d2902e --- /dev/null +++ b/kotlin-stdlib/jvm/main/kotlin/com/javiersc/kotlin/stdlib/Files.kt @@ -0,0 +1,11 @@ +package com.javiersc.kotlin.stdlib + +import java.io.File + +public fun resource(name: String): File = resourceOrNull(name) ?: error("File not found") + +public fun resourceOrNull(name: String): File? = + Thread.currentThread().contextClassLoader?.getResource(name)?.file?.let(::File) + +public val File.children: Sequence + get() = walkTopDown().maxDepth(1) - this diff --git a/kotlin-stdlib/jvm/test/kotlin/com/javiersc/kotlin/stdlib/FilesTest.kt b/kotlin-stdlib/jvm/test/kotlin/com/javiersc/kotlin/stdlib/FilesTest.kt new file mode 100644 index 00000000..272d2da2 --- /dev/null +++ b/kotlin-stdlib/jvm/test/kotlin/com/javiersc/kotlin/stdlib/FilesTest.kt @@ -0,0 +1,40 @@ +package com.javiersc.kotlin.stdlib + +import java.io.File +import kotlin.test.Test +import kotlin.test.assertFailsWith +import kotlin.test.assertNotNull +import kotlin.test.assertNull +import kotlin.test.assertTrue + +internal class FilesTest { + + @Test + fun `given a directory when it exists then resource is not null`() { + val childrenTestDir = resourceOrNull("children-test") + assertNotNull(childrenTestDir) + assertTrue { childrenTestDir.exists() } + assertTrue { resource("children-test").exists() } + } + + @Test + fun `given a directory when it does not exist then resource is null`() { + assertFailsWith { resource("children-test-foo") } + assertNull(resourceOrNull("children-test-foo")) + } + + @Test + fun `given a directory when it has children a sub-children then children does not use sub children`() { + val childrenTestDir = resource("children-test") + + val children: Sequence = childrenTestDir.children + val actualChildren: List = children.toList().map { it.name }.sorted() + val expectChildren: List = listOf("A.txt", "B.txt", "sub-children").sorted() + assertTrue { actualChildren == expectChildren } + + val subChildren = children.first { it.isDirectory }.children + val actualSubChildren: List = subChildren.toList().map { it.name }.sorted() + val expectSubChildren: List = listOf("C.txt", "D.txt").sorted() + assertTrue { actualSubChildren == expectSubChildren } + } +} diff --git a/kotlin-test-junit/api/android/kotlin-test-junit.api b/kotlin-test-junit/api/android/kotlin-test-junit.api new file mode 100644 index 00000000..b8ea7897 --- /dev/null +++ b/kotlin-test-junit/api/android/kotlin-test-junit.api @@ -0,0 +1,72 @@ +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeArm32 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeX86 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreCommon : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreJs : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreJvm : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreLinuxArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreLinuxX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMacosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMacosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMingwX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWasm : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosArm32 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosDeviceArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosX64 : java/lang/annotation/Annotation { +} + diff --git a/kotlin-test-junit/api/jvm/kotlin-test-junit.api b/kotlin-test-junit/api/jvm/kotlin-test-junit.api new file mode 100644 index 00000000..1195c1b8 --- /dev/null +++ b/kotlin-test-junit/api/jvm/kotlin-test-junit.api @@ -0,0 +1,72 @@ +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroid : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeArm32 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeX86 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreCommon : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreJs : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreLinuxArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreLinuxX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMacosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMacosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMingwX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWasm : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosArm32 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosDeviceArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosX64 : java/lang/annotation/Annotation { +} + diff --git a/kotlin-test-junit5/api/kotlin-test-junit5.api b/kotlin-test-junit5/api/kotlin-test-junit5.api new file mode 100644 index 00000000..1049db88 --- /dev/null +++ b/kotlin-test-junit5/api/kotlin-test-junit5.api @@ -0,0 +1,69 @@ +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeArm32 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeX86 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreCommon : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreJs : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreLinuxArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreLinuxX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMacosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMacosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMingwX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWasm : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosArm32 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosDeviceArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosX64 : java/lang/annotation/Annotation { +} + diff --git a/kotlin-test-testng/api/kotlin-test-testng.api b/kotlin-test-testng/api/kotlin-test-testng.api new file mode 100644 index 00000000..1049db88 --- /dev/null +++ b/kotlin-test-testng/api/kotlin-test-testng.api @@ -0,0 +1,69 @@ +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeArm32 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreAndroidNativeX86 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreCommon : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreIosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreJs : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreLinuxArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreLinuxX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMacosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMacosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreMingwX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreTvosX64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWasm : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosArm32 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosDeviceArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosSimulatorArm64 : java/lang/annotation/Annotation { +} + +public abstract interface annotation class com/javiersc/kotlin/test/IgnoreWatchosX64 : java/lang/annotation/Annotation { +} +