generated from JavierSegoviaCordoba/kotlin-template-javiersc
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
File.children
, resourceOrNull
and resource
functions
- Loading branch information
1 parent
2764934
commit ff7b747
Showing
13 changed files
with
342 additions
and
1 deletion.
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
This file was deleted.
Oops, something went wrong.
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
Empty file.
Empty file.
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions
11
kotlin-stdlib/jvm/main/kotlin/com/javiersc/kotlin/stdlib/Files.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,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 |
40 changes: 40 additions & 0 deletions
40
kotlin-stdlib/jvm/test/kotlin/com/javiersc/kotlin/stdlib/FilesTest.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,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 } | ||
} | ||
} |
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,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 { | ||
} | ||
|
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,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 { | ||
} | ||
|
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,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 { | ||
} | ||
|
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,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 { | ||
} | ||
|