File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -177,3 +177,13 @@ times = [
177177 assert toml.encode[Arrs](a) == s
178178 assert toml.decode[Arrs](s)! == a
179179}
180+
181+ fn test_unsupported_type () {
182+ s := 'name = "Peter"'
183+ err_msg := 'toml.decode: expected struct, found '
184+ toml.decode[string ](s) or { assert err.msg () == err_msg + 'string' }
185+ toml.decode[[]string ](s) or { assert err.msg () == err_msg + '[]string' }
186+ toml.decode[int ](s) or { assert err.msg () == err_msg + 'int' }
187+ toml.decode[[]f32 ](s) or { assert err.msg () == err_msg + '[]f32' }
188+ // ...
189+ }
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ pub fn decode[T](toml_txt string) !T {
2323 return typ
2424 }
2525 }
26+ $if T ! is $struct {
27+ return error ('toml.decode: expected struct, found ${T.name} ' )
28+ }
2629 decode_struct[T](doc.to_any (), mut typ)
2730 return typ
2831}
You can’t perform that action at this time.
0 commit comments