github.com/lingyao2333/mo-zero@v1.4.1/core/mapping/tomlunmarshaler_test.go (about) 1 package mapping 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestUnmarshalToml(t *testing.T) { 10 const input = `a = "foo" 11 b = 1 12 c = "${FOO}" 13 d = "abcd!@#$112" 14 ` 15 var val struct { 16 A string `json:"a"` 17 B int `json:"b"` 18 C string `json:"c"` 19 D string `json:"d"` 20 } 21 assert.Nil(t, UnmarshalTomlBytes([]byte(input), &val)) 22 assert.Equal(t, "foo", val.A) 23 assert.Equal(t, 1, val.B) 24 assert.Equal(t, "${FOO}", val.C) 25 assert.Equal(t, "abcd!@#$112", val.D) 26 } 27 28 func TestUnmarshalTomlErrorToml(t *testing.T) { 29 const input = `foo" 30 b = 1 31 c = "${FOO}" 32 d = "abcd!@#$112" 33 ` 34 var val struct { 35 A string `json:"a"` 36 B int `json:"b"` 37 C string `json:"c"` 38 D string `json:"d"` 39 } 40 assert.NotNil(t, UnmarshalTomlBytes([]byte(input), &val)) 41 }