Skip to content

Commit fd526b4

Browse files
authored
Add test to @EncodeDefault (#347)
1 parent 798ad39 commit fd526b4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/encoders/EncodingAnnotationTest.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.akuleshov7.ktoml.Toml
44
import com.akuleshov7.ktoml.TomlOutputConfig
55
import com.akuleshov7.ktoml.annotations.*
66
import com.akuleshov7.ktoml.writers.IntegerRepresentation.*
7+
import kotlinx.serialization.EncodeDefault
8+
import kotlinx.serialization.ExperimentalSerializationApi
79
import kotlinx.serialization.Serializable
810
import kotlin.test.Ignore
911
import kotlin.test.Test
@@ -315,4 +317,37 @@ class EncodingAnnotationTest {
315317
""".trimIndent()
316318
)
317319
}
320+
321+
@OptIn(ExperimentalSerializationApi::class)
322+
@Test
323+
fun encodeDefaultAnnotation() {
324+
@Serializable
325+
data class Foo(
326+
@EncodeDefault(EncodeDefault.Mode.ALWAYS)
327+
val a: Int = 1,
328+
@EncodeDefault(EncodeDefault.Mode.NEVER)
329+
val b: Int = 2,
330+
val c: Int = 3
331+
)
332+
333+
assertEncodedEquals(
334+
value = Foo(),
335+
expectedToml = """
336+
a = 1
337+
c = 3
338+
""".trimIndent(),
339+
)
340+
341+
assertEncodedEquals(
342+
value = Foo(),
343+
expectedToml = """
344+
a = 1
345+
""".trimIndent(),
346+
tomlInstance = Toml(
347+
outputConfig = TomlOutputConfig(
348+
ignoreDefaultValues = true,
349+
)
350+
)
351+
)
352+
}
318353
}

0 commit comments

Comments
 (0)