mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
parser: time, resource_location, uuid
This commit is contained in:
parent
9c8bd67c06
commit
975c3002f1
@ -48,6 +48,7 @@ class DoubleParser(
|
||||
|
||||
companion object : ArgumentParserFactory<DoubleParser> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "brigadier:double".toResourceLocation()
|
||||
val DEFAULT = DoubleParser()
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer): DoubleParser {
|
||||
val flags = buffer.readUnsignedByte()
|
||||
|
@ -48,6 +48,7 @@ class FloatParser(
|
||||
|
||||
companion object : ArgumentParserFactory<FloatParser> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "brigadier:float".toResourceLocation()
|
||||
val DEFAULT = FloatParser()
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer): FloatParser {
|
||||
val flags = buffer.readUnsignedByte()
|
||||
|
@ -48,6 +48,7 @@ class IntParser(
|
||||
|
||||
companion object : ArgumentParserFactory<IntParser> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "brigadier:integer".toResourceLocation()
|
||||
val DEFAULT = IntParser()
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer): IntParser {
|
||||
val flags = buffer.readUnsignedByte()
|
||||
|
@ -48,6 +48,7 @@ class LongParser(
|
||||
|
||||
companion object : ArgumentParserFactory<LongParser> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "brigadier:long".toResourceLocation()
|
||||
val DEFAULT = LongParser()
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer): LongParser {
|
||||
val flags = buffer.readUnsignedByte()
|
||||
|
@ -23,9 +23,12 @@ import de.bixilon.minosoft.commands.parser.minecraft.range.RangeParserFactory
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.range._float.FloatRangeParser
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.range._int.IntRangeParser
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.resource.ResourceParser
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.resource.location.ResourceLocationParser
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.resource.tag.ResourceOrTagParser
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.score.holder.ScoreHolderParser
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.TargetParser
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.time.TimeParser
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.uuid.UUIDParser
|
||||
import de.bixilon.minosoft.commands.parser.minosoft.dummy.DummyParser
|
||||
import de.bixilon.minosoft.data.registries.factory.DefaultFactory
|
||||
|
||||
@ -43,6 +46,10 @@ object ArgumentParserFactories : DefaultFactory<ArgumentParserFactory<*>>(
|
||||
FloatRangeParser,
|
||||
IntRangeParser,
|
||||
|
||||
UUIDParser,
|
||||
ResourceLocationParser,
|
||||
TimeParser,
|
||||
|
||||
DummyParser,
|
||||
|
||||
ScoreHolderParser,
|
||||
@ -75,17 +82,14 @@ minecraft:score_holder
|
||||
minecraft:swizzle
|
||||
minecraft:team
|
||||
minecraft:item_slot
|
||||
minecraft:resource_location
|
||||
minecraft:mob_effect
|
||||
minecraft:function
|
||||
minecraft:entity_anchor
|
||||
minecraft:item_enchantment
|
||||
minecraft:entity_summon
|
||||
minecraft:dimension
|
||||
minecraft:uuid
|
||||
minecraft:nbt_tag
|
||||
minecraft:nbt_compound_tag
|
||||
minecraft:time
|
||||
minecraft:resource_or_tag
|
||||
minecraft:resource
|
||||
*/
|
||||
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.resource.location
|
||||
|
||||
import de.bixilon.minosoft.commands.errors.parser.ParserError
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import de.bixilon.minosoft.commands.util.ReadResult
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
|
||||
class InvalidResourceLocationError(
|
||||
reader: CommandReader,
|
||||
result: ReadResult<ResourceLocation?>,
|
||||
) : ParserError(reader, result)
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.resource.location
|
||||
|
||||
import de.bixilon.minosoft.commands.parser.ArgumentParser
|
||||
import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactory
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
|
||||
object ResourceLocationParser : ArgumentParser<ResourceLocation>, ArgumentParserFactory<ResourceLocationParser> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:resource_location".toResourceLocation()
|
||||
override val examples: List<Any> = listOf("dirt", "minecraft:dirt")
|
||||
override val placeholder = ChatComponent.of("<resource location>")
|
||||
|
||||
override fun parse(reader: CommandReader): ResourceLocation {
|
||||
reader.readResult { readResourceLocation() }.let { return it.result ?: throw InvalidResourceLocationError(reader, it) }
|
||||
}
|
||||
|
||||
override fun getSuggestions(reader: CommandReader): List<Any> {
|
||||
if (reader.readString()?.isBlank() != false) {
|
||||
return examples
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer) = this
|
||||
}
|
@ -20,13 +20,13 @@ import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactory
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.EntityTarget
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.name.InvalidNameError
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.name.NameEntityTarget
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.uuid.InvalidUUIDError
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.uuid.UUIDEntityTarget
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorEntityTarget
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidSelectorKeyError
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.error.InvalidTargetSelector
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperties
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.TargetProperty
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.uuid.InvalidUUIDError
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import de.bixilon.minosoft.commands.util.ReadResult
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.time
|
||||
|
||||
import de.bixilon.minosoft.commands.errors.ReaderError
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
|
||||
class InvalidTimeUnitError(
|
||||
reader: CommandReader,
|
||||
position: Int,
|
||||
read: Int?,
|
||||
) : ReaderError(reader, position, position + 1)
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.time
|
||||
|
||||
import de.bixilon.minosoft.commands.parser.ArgumentParser
|
||||
import de.bixilon.minosoft.commands.parser.brigadier._float.FloatParser
|
||||
import de.bixilon.minosoft.commands.parser.brigadier._float.FloatParser.Companion.readFloat
|
||||
import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactory
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
|
||||
object TimeParser : ArgumentParser<Int>, ArgumentParserFactory<TimeParser> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:time".toResourceLocation()
|
||||
override val examples: List<Any> = listOf(2400, "3d", "10s")
|
||||
override val placeholder = ChatComponent.of("<time>")
|
||||
|
||||
override fun parse(reader: CommandReader): Int {
|
||||
reader.readResult { readTime() }.let { return it.result }
|
||||
}
|
||||
|
||||
fun CommandReader.readTime(): Int {
|
||||
val time = FloatParser.DEFAULT.parse(this)
|
||||
|
||||
val unit: TimeUnit
|
||||
val peek = peekNext()
|
||||
try {
|
||||
unit = TimeUnit.fromUnit(peek)
|
||||
readNext()
|
||||
} catch (error: IllegalArgumentException) {
|
||||
throw InvalidTimeUnitError(this, this.pointer, peek)
|
||||
}
|
||||
return (time * unit.multiplier).toInt()
|
||||
}
|
||||
|
||||
override fun getSuggestions(reader: CommandReader): List<Any> {
|
||||
reader.readFloat() ?: return examples
|
||||
val peek = reader.peekNext() ?: return TimeUnit.UNITS
|
||||
try {
|
||||
TimeUnit.fromUnit(peek)
|
||||
} catch (error: IllegalArgumentException) {
|
||||
throw InvalidTimeUnitError(reader, reader.pointer, peek)
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer) = this
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.time
|
||||
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
|
||||
enum class TimeUnit(val multiplier: Int) {
|
||||
TICKS(1),
|
||||
SECONDS(ProtocolDefinition.TICKS_PER_SECOND),
|
||||
DAYS(ProtocolDefinition.TICKS_PER_DAY),
|
||||
;
|
||||
|
||||
companion object {
|
||||
val UNITS = listOf("t", "s", "d")
|
||||
|
||||
fun fromUnit(char: Int?): TimeUnit {
|
||||
return when (char) {
|
||||
null, 't'.code -> TICKS
|
||||
's'.code -> SECONDS
|
||||
'd'.code -> DAYS
|
||||
else -> throw IllegalArgumentException("Invalid unit: ${char.toChar()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.uuid
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.uuid
|
||||
|
||||
import de.bixilon.minosoft.commands.errors.parser.ParserError
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
@ -19,5 +19,5 @@ import de.bixilon.minosoft.commands.util.ReadResult
|
||||
|
||||
class InvalidUUIDError(
|
||||
reader: CommandReader,
|
||||
result: ReadResult<String?>,
|
||||
result: ReadResult<*>,
|
||||
) : ParserError(reader, result)
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.uuid
|
||||
|
||||
import de.bixilon.kutil.uuid.UUIDUtil.toUUID
|
||||
import de.bixilon.minosoft.commands.parser.ArgumentParser
|
||||
import de.bixilon.minosoft.commands.parser.factory.ArgumentParserFactory
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||
import de.bixilon.minosoft.data.text.ChatComponent
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import java.util.*
|
||||
|
||||
object UUIDParser : ArgumentParser<UUID>, ArgumentParserFactory<UUIDParser> {
|
||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:uuid".toResourceLocation()
|
||||
override val examples: List<Any> = listOf("9e6ce7c5-40d3-483e-8e5a-b6350987d65f")
|
||||
override val placeholder = ChatComponent.of("<uuid>")
|
||||
|
||||
override fun parse(reader: CommandReader): UUID {
|
||||
reader.readResult { readUUID() }.let { return it.result ?: throw InvalidUUIDError(reader, it) }
|
||||
}
|
||||
|
||||
fun CommandReader.readUUID(): UUID? {
|
||||
val string = readWord() ?: return null
|
||||
|
||||
return try {
|
||||
string.toUUID()
|
||||
} catch (ignored: Throwable) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSuggestions(reader: CommandReader): List<Any> {
|
||||
if (reader.readString()?.isBlank() != false) {
|
||||
return examples
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun read(buffer: PlayInByteBuffer) = this
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.resource.location
|
||||
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
internal class ResourceLocationParserTest {
|
||||
|
||||
@Test
|
||||
fun `read dirt`() {
|
||||
val reader = CommandReader("dirt")
|
||||
assertEquals(ResourceLocationParser.parse(reader), "minecraft:dirt".toResourceLocation())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `read minecraft dirt`() {
|
||||
val reader = CommandReader("minecraft:dirt")
|
||||
assertEquals(ResourceLocationParser.parse(reader), "minecraft:dirt".toResourceLocation())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun readEmpty() {
|
||||
val reader = CommandReader("")
|
||||
assertThrows<InvalidResourceLocationError> { ResourceLocationParser.parse(reader) }
|
||||
}
|
||||
}
|
@ -16,11 +16,11 @@ package de.bixilon.minosoft.commands.parser.minecraft.target
|
||||
import de.bixilon.minosoft.commands.errors.reader.map.DuplicatedKeyMapError
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.name.InvalidNameError
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.name.NameEntityTarget
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.uuid.InvalidUUIDError
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.identifier.uuid.UUIDEntityTarget
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.SelectorEntityTarget
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.GamemodeProperty
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.target.targets.selector.properties.NameProperty
|
||||
import de.bixilon.minosoft.commands.parser.minecraft.uuid.InvalidUUIDError
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import de.bixilon.minosoft.data.abilities.Gamemodes
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.time
|
||||
|
||||
import de.bixilon.minosoft.commands.parser.brigadier._float.FloatParseError
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
internal class TimeParserTest {
|
||||
|
||||
@Test
|
||||
fun testNoUnit() {
|
||||
val reader = CommandReader("1235")
|
||||
assertEquals(TimeParser.parse(reader), 1235)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTickUnit() {
|
||||
val reader = CommandReader("7382t")
|
||||
assertEquals(TimeParser.parse(reader), 7382)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSecondsUnit() {
|
||||
val reader = CommandReader("64s")
|
||||
assertEquals(TimeParser.parse(reader), 64 * ProtocolDefinition.TICKS_PER_SECOND)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDaysUnit() {
|
||||
val reader = CommandReader("89d")
|
||||
assertEquals(TimeParser.parse(reader), 89 * ProtocolDefinition.TICKS_PER_DAY)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmpty() {
|
||||
val reader = CommandReader("")
|
||||
assertThrows<FloatParseError> { TimeParser.parse(reader) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInvalidUnit() {
|
||||
val reader = CommandReader("48i")
|
||||
assertThrows<InvalidTimeUnitError> { TimeParser.parse(reader) }
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.commands.parser.minecraft.uuid
|
||||
|
||||
import de.bixilon.minosoft.commands.util.CommandReader
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
internal class UUIDParserTest {
|
||||
|
||||
@Test
|
||||
fun testNormalUUID() {
|
||||
val reader = CommandReader("9e6ce7c5-40d3-483e-8e5a-b6350987d65f")
|
||||
assertEquals(UUIDParser.parse(reader), UUID.fromString("9e6ce7c5-40d3-483e-8e5a-b6350987d65f"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTrimmedUUID() {
|
||||
val reader = CommandReader("9e6ce7c540d3483e8e5ab6350987d65f")
|
||||
assertEquals(UUIDParser.parse(reader), UUID.fromString("9e6ce7c5-40d3-483e-8e5a-b6350987d65f"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEmptyUUID() {
|
||||
val reader = CommandReader("")
|
||||
assertThrows<InvalidUUIDError> { UUIDParser.parse(reader) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTooShortUUID() {
|
||||
val reader = CommandReader("9e6ce7c540d3483")
|
||||
assertThrows<InvalidUUIDError> { UUIDParser.parse(reader) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTooLongUUID() {
|
||||
val reader = CommandReader("9e6ce7c540d3483e8e5ab6350987d65f9e6ce7c540d3483e8e5ab6350987d65f")
|
||||
assertThrows<InvalidUUIDError> { UUIDParser.parse(reader) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInvalidUUID() {
|
||||
val reader = CommandReader("9r6ce7c540d3483e8e5ab6350987d65f")
|
||||
assertThrows<InvalidUUIDError> { UUIDParser.parse(reader) }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user