-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
NbtTag
-typed values not encoding correctly
- Loading branch information
1 parent
9278b40
commit d288924
Showing
3 changed files
with
68 additions
and
7 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.benwoodworth.knbt | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class NbtTagPolymorphismTest { | ||
private val nbt = Nbt { | ||
variant = NbtVariant.Java | ||
compression = NbtCompression.None | ||
} | ||
|
||
@Serializable | ||
@SerialName("") | ||
private data class NbtTagContainer( | ||
val nbtTag: NbtTag, | ||
) | ||
|
||
@Test | ||
fun Should_encode_NbtCompound_to_NbtTag_property_correctly() { | ||
val compound = buildNbtCompound { | ||
put("entry", "Hello, world!") | ||
} | ||
|
||
val toEncode = NbtTagContainer(compound) | ||
|
||
assertEquals( | ||
expected = buildNbtCompound("") { | ||
put(NbtTagContainer::nbtTag.name, compound) | ||
}, | ||
actual = nbt.encodeToNbtTag(NbtTagContainer.serializer(), toEncode), | ||
) | ||
} | ||
|
||
@Test | ||
fun Should_decode_NbtCompound_from_NbtTag_property_correctly() { | ||
val compound = buildNbtCompound { | ||
put("entry", "Hello, world!") | ||
} | ||
|
||
val toDecode = buildNbtCompound("") { | ||
put(NbtTagContainer::nbtTag.name, compound) | ||
} | ||
|
||
assertEquals( | ||
expected = NbtTagContainer(compound), | ||
actual = nbt.decodeFromNbtTag(NbtTagContainer.serializer(), toDecode), | ||
) | ||
} | ||
} |