From 8caedaad2c1a50bda4ac53879f9ca2604238f0c3 Mon Sep 17 00:00:00 2001 From: Andrey Kuleshov Date: Mon, 18 Jul 2022 23:05:11 +0300 Subject: [PATCH] Adding test for required fields --- .../ktoml/decoders/RequiredAnnotation.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/decoders/RequiredAnnotation.kt diff --git a/ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/decoders/RequiredAnnotation.kt b/ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/decoders/RequiredAnnotation.kt new file mode 100644 index 00000000..1dc863ff --- /dev/null +++ b/ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/decoders/RequiredAnnotation.kt @@ -0,0 +1,24 @@ +package com.akuleshov7.ktoml.decoders + +import com.akuleshov7.ktoml.Toml +import com.akuleshov7.ktoml.exceptions.MissingRequiredPropertyException +import kotlinx.serialization.Required +import kotlinx.serialization.Serializable +import kotlinx.serialization.decodeFromString +import kotlin.test.Test +import kotlin.test.assertFailsWith + +@Serializable +data class RequiredStr( + val a: String = "a", + @Required + val b: String = "b", + val c: String, +) + +class RequiredAnnotation { + @Test + fun testMissingRequiredPropertyException() { + assertFailsWith { Toml.decodeFromString("c = \"100\"") } + } +}