diff --git a/src/main/kotlin/io/arkosammy12/monkeyconfig/util/ElementPath.kt b/src/main/kotlin/io/arkosammy12/monkeyconfig/util/ElementPath.kt index 8a12d19..0b0367d 100644 --- a/src/main/kotlin/io/arkosammy12/monkeyconfig/util/ElementPath.kt +++ b/src/main/kotlin/io/arkosammy12/monkeyconfig/util/ElementPath.kt @@ -5,7 +5,7 @@ data class ElementPath(val string: String) { init { val nodes: List = this.string.split(".") for (node: String in nodes) { - if (node.contains("\\s+")) { + if (node.contains("\\s+") || node.contains(" ")) { throw IllegalArgumentException("Setting nodes cannot contain whitespaces!") } if (node.isBlank() || node.isEmpty()) { diff --git a/src/test/kotlin/io/arkosammy12/monkeyconfig/Main.kt b/src/test/kotlin/io/arkosammy12/monkeyconfig/Main.kt index d05b1c2..416194d 100644 --- a/src/test/kotlin/io/arkosammy12/monkeyconfig/Main.kt +++ b/src/test/kotlin/io/arkosammy12/monkeyconfig/Main.kt @@ -1,7 +1,7 @@ package io.arkosammy12.monkeyconfig import io.arkosammy12.monkeyconfig.builders.tomlConfigManager -import io.arkosammy12.monkeyconfig.settings.TestNumberSettingImplementation +import io.arkosammy12.monkeyconfig.settings.TestNumberSetting import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths @@ -22,13 +22,14 @@ object Main { booleanSetting("testTopLevelBooleanSetting", true) { comment = "Test comment" } + section("testSection") { comment = "Test comment here" numberSetting("testNumberSetting", 0) { comment = "Test comment" minValue = 0 maxValue = 10 - implementation = { builder -> TestNumberSettingImplementation(builder) } + implementation = { builder -> TestNumberSetting(builder) } } section("testSubsection") { comment = "Test comment" diff --git a/src/test/kotlin/io/arkosammy12/monkeyconfig/settings/TestNumberSettingImplementation.kt b/src/test/kotlin/io/arkosammy12/monkeyconfig/settings/TestNumberSetting.kt similarity index 56% rename from src/test/kotlin/io/arkosammy12/monkeyconfig/settings/TestNumberSettingImplementation.kt rename to src/test/kotlin/io/arkosammy12/monkeyconfig/settings/TestNumberSetting.kt index 47fba49..10052d9 100644 --- a/src/test/kotlin/io/arkosammy12/monkeyconfig/settings/TestNumberSettingImplementation.kt +++ b/src/test/kotlin/io/arkosammy12/monkeyconfig/settings/TestNumberSetting.kt @@ -2,7 +2,7 @@ package io.arkosammy12.monkeyconfig.settings import io.arkosammy12.monkeyconfig.builders.NumberSettingBuilder -class TestNumberSettingImplementation(settingBuilder: NumberSettingBuilder) : NumberSetting(settingBuilder) { +class TestNumberSetting(settingBuilder: NumberSettingBuilder) : NumberSetting(settingBuilder) { init { diff --git a/src/test/kotlin/io/arkosammy12/monkeyconfig/util/TestElementPath.kt b/src/test/kotlin/io/arkosammy12/monkeyconfig/util/TestElementPath.kt new file mode 100644 index 0000000..f6790b9 --- /dev/null +++ b/src/test/kotlin/io/arkosammy12/monkeyconfig/util/TestElementPath.kt @@ -0,0 +1,73 @@ +package io.arkosammy12.monkeyconfig.util + +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import kotlin.test.assertEquals + +class TestElementPath { + + @Test + fun `ElementPath should not accept empty nodes`() { + + assertThrows { + ElementPath("") + } + + assertThrows { + ElementPath("node1", "", "node3") + } + + assertThrows { + ElementPath(".") + } + + assertThrows { + ElementPath("node1..node3") + } + + } + + @Test + fun `Element Path should not accept nodes with whitespaces`() { + + assertThrows { + ElementPath(" ") + } + + assertThrows { + ElementPath("node1", " node2", "node3") + } + + assertThrows { + ElementPath(". ") + } + + assertThrows { + ElementPath("node1. .node3") + } + + } + + @Test + fun `Element Path creation with node lists results in proper string representation`() { + + assertEquals(ElementPath("node").string, "node") + + assertEquals(ElementPath("node1", "node2").string, "node1.node2") + + assertEquals(ElementPath(listOf("node1", "node2", "node3")).string, "node1.node2.node3") + + } + + @Test + fun `Element Path creation with strings results in proper list representation`() { + + assertEquals(ElementPath("node").asList, listOf("node")) + + assertEquals(ElementPath("node1.node2").asList, listOf("node1", "node2")) + + assertEquals(ElementPath("node1.node2.node3").asList, listOf("node1", "node2", "node3")) + + } + +} \ No newline at end of file