@@ -1031,23 +1031,48 @@ class YamlReadingTest : DescribeSpec({
1031
1031
}
1032
1032
1033
1033
context("given some input representing an object with an unknown key, using a naming strategy") {
1034
- val input = " oneTwoThree: something" .trimIndent()
1034
+ context("given the unknown key does not match any of the known field names") {
1035
+ val input = " oneTwoThree: something" .trimIndent()
1035
1036
1036
- context("parsing that input") {
1037
- it("throws an exception with the naming strategy applied") {
1038
- val exception = shouldThrow<UnknownPropertyException > {
1039
- Yaml (
1040
- configuration = YamlConfiguration (yamlNamingStrategy = YamlNamingStrategy .SnakeCase ),
1041
- ).decodeFromString(ComplexStructure .serializer(), input)
1037
+ context("parsing that input") {
1038
+ it("throws an exception") {
1039
+ val exception = shouldThrow<UnknownPropertyException > {
1040
+ Yaml (
1041
+ configuration = YamlConfiguration (yamlNamingStrategy = YamlNamingStrategy .SnakeCase ),
1042
+ ).decodeFromString(NestedObjects .serializer(), input)
1043
+ }
1044
+
1045
+ exception.asClue {
1046
+ it.message shouldBe " Unknown property 'oneTwoThree'. Known properties are: first_person, second_person"
1047
+ it.line shouldBe 1
1048
+ it.column shouldBe 1
1049
+ it.propertyName shouldBe " oneTwoThree"
1050
+ it.validPropertyNames shouldBe setOf("first_person", "second_person")
1051
+ it.path shouldBe YamlPath .root.withMapElementKey("oneTwoThree", Location (1, 1))
1052
+ }
1042
1053
}
1054
+ }
1055
+ }
1043
1056
1044
- exception.asClue {
1045
- it.message shouldBe " Unknown property 'oneTwoThree'. Known properties are: boolean, byte, char, double, enum, float, int, long, nullable, short, string"
1046
- it.line shouldBe 1
1047
- it.column shouldBe 1
1048
- it.propertyName shouldBe " oneTwoThree"
1049
- it.validPropertyNames shouldBe setOf("boolean", "byte", "char", "double", "enum", "float", "int", "long", "nullable", "short", "string")
1050
- it.path shouldBe YamlPath .root.withMapElementKey("oneTwoThree", Location (1, 1))
1057
+ context("given the unknown key uses the Kotlin name of the field, rather than the name from the naming strategy") {
1058
+ val input = " firstPerson: something" .trimIndent()
1059
+
1060
+ context("parsing that input") {
1061
+ it("throws an exception") {
1062
+ val exception = shouldThrow<UnknownPropertyException > {
1063
+ Yaml (
1064
+ configuration = YamlConfiguration (yamlNamingStrategy = YamlNamingStrategy .SnakeCase ),
1065
+ ).decodeFromString(NestedObjects .serializer(), input)
1066
+ }
1067
+
1068
+ exception.asClue {
1069
+ it.message shouldBe " Unknown property 'firstPerson'. Known properties are: first_person, second_person"
1070
+ it.line shouldBe 1
1071
+ it.column shouldBe 1
1072
+ it.propertyName shouldBe " firstPerson"
1073
+ it.validPropertyNames shouldBe setOf("first_person", "second_person")
1074
+ it.path shouldBe YamlPath .root.withMapElementKey("firstPerson", Location (1, 1))
1075
+ }
1051
1076
}
1052
1077
}
1053
1078
}
0 commit comments