-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
The decoder on the readme not working for badwords on latest version I also ran a rest on master with
import cc.ekblad.toml.model.TomlValue
import cc.ekblad.toml.tomlMapper
import java.nio.file.Path
import kotlin.test.Test
import kotlin.test.assertEquals
class CustomDecoderTest {
@Test
fun `can use custom string decoder to filter bad words`() {
val listOfBadWords = listOf("poop", "darn", "blockchain")
val mapper = tomlMapper {
decoder { it: TomlValue.String ->
if (it.value in listOfBadWords) {
// Replace bad words with asterisks
it.value.map { '*' }.joinToString("")
} else {
it.value
}
}
}
// Prepare a TOML file content
val tomlFile = Path.of("test.toml")
val tomlContent = """
[section]
dd = "poop" # This word should be replaced
good_word = "hello"
"""
// Write content to a temporary test file
tomlFile.toFile().writeText(tomlContent)
// Decode the TOML content using the custom decoder
val config = mapper.decode<Map<String, Any>>(tomlFile)
// Print the values output by the decoder
val section = config["section"] as? Map<*, *>
val dd = section?.get("dd")
val goodWord = section?.get("good_word")
println("dd: $dd") // This should print "****"
println("good_word: $goodWord") // This should print "hello"
// Assertions to verify the custom behavior
assertEquals("****", dd) // Should be replaced with asterisks
assertEquals("hello", goodWord) // Should remain unchanged
}
}
It seems to fail, nothing in the decoder block seems to work
Metadata
Metadata
Assignees
Labels
No labels