Skip to content

Commit

Permalink
Add File.children, resourceOrNull and resource functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierSegoviaCordoba committed Apr 17, 2023
1 parent 2764934 commit ff7b747
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Added

- `resource(name: String): File` function
- `resourceOrNull(name: String): File?` function
- `File.children: Sequence<File>`
- `String.transformstring` function
- `String.TRANSFORMSTRING` function
- `String.transformString` function
Expand Down
1 change: 0 additions & 1 deletion kotlin-stdlib/android/main/AndroidManifest.xml

This file was deleted.

6 changes: 6 additions & 0 deletions kotlin-stdlib/api/jvm/kotlin-stdlib.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions kotlin-stdlib/jvm/main/kotlin/com/javiersc/kotlin/stdlib/Files.kt
Original file line number Diff line number Diff line change
@@ -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<File>
get() = walkTopDown().maxDepth(1) - this
Original file line number Diff line number Diff line change
@@ -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<IllegalStateException> { 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<File> = childrenTestDir.children
val actualChildren: List<String> = children.toList().map { it.name }.sorted()
val expectChildren: List<String> = listOf("A.txt", "B.txt", "sub-children").sorted()
assertTrue { actualChildren == expectChildren }

val subChildren = children.first { it.isDirectory }.children
val actualSubChildren: List<String> = subChildren.toList().map { it.name }.sorted()
val expectSubChildren: List<String> = listOf("C.txt", "D.txt").sorted()
assertTrue { actualSubChildren == expectSubChildren }
}
}
72 changes: 72 additions & 0 deletions kotlin-test-junit/api/android/kotlin-test-junit.api
Original file line number Diff line number Diff line change
@@ -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 {
}

72 changes: 72 additions & 0 deletions kotlin-test-junit/api/jvm/kotlin-test-junit.api
Original file line number Diff line number Diff line change
@@ -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 {
}

69 changes: 69 additions & 0 deletions kotlin-test-junit5/api/kotlin-test-junit5.api
Original file line number Diff line number Diff line change
@@ -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 {
}

69 changes: 69 additions & 0 deletions kotlin-test-testng/api/kotlin-test-testng.api
Original file line number Diff line number Diff line change
@@ -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 {
}

0 comments on commit ff7b747

Please sign in to comment.