tomlunmarshaler_test.go 760 B

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