-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for orDefault and map accessors
- Loading branch information
Showing
8 changed files
with
79 additions
and
47 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
2 changes: 2 additions & 0 deletions
2
geary-core/src/commonMain/kotlin/com/mineinabyss/geary/systems/accessors/Aliases.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
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
1 change: 1 addition & 0 deletions
1
...core/src/commonMain/kotlin/com/mineinabyss/geary/systems/accessors/type/MappedAccessor.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
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
30 changes: 0 additions & 30 deletions
30
geary-core/src/jvmTest/kotlin/com/mineinabyss/geary/systems/accessors/AccessorHolderTest.kt
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
geary-core/src/jvmTest/kotlin/com/mineinabyss/geary/systems/accessors/MappedAccessorTests.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,45 @@ | ||
package com.mineinabyss.geary.systems.accessors | ||
|
||
import com.mineinabyss.geary.helpers.entity | ||
import com.mineinabyss.geary.helpers.tests.GearyTest | ||
import com.mineinabyss.geary.modules.geary | ||
import com.mineinabyss.geary.systems.builders.cachedQuery | ||
import com.mineinabyss.geary.systems.query.Query | ||
import io.kotest.matchers.collections.shouldContainExactly | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.jupiter.api.Test | ||
|
||
internal class MappedAccessorTests : GearyTest() { | ||
private class Marker | ||
|
||
private fun mappedQuery() = geary.cachedQuery(object : Query() { | ||
val mapped by get<Int>().map { it.toString() } | ||
}) | ||
|
||
private fun defaultingQuery() = geary.cachedQuery(object : Query() { | ||
val default by get<String>().orDefault { "empty!" } | ||
override fun ensure() = this { has<Marker>() } | ||
}) | ||
|
||
@Test | ||
fun `should correctly get mapped accessors`() { | ||
entity { | ||
set(1) | ||
} | ||
mappedQuery().forEach { | ||
mapped shouldBe "1" | ||
} | ||
} | ||
|
||
@Test | ||
fun `should correctly get default accessors`() { | ||
entity { | ||
set("Hello") | ||
add<Marker>() | ||
} | ||
entity { | ||
add<Marker>() | ||
} | ||
defaultingQuery().map { default }.shouldContainExactly("Hello", "empty!") | ||
} | ||
} |