struct2map_test.go 351 B

1234567891011121314151617181920212223242526272829303132333435
  1. package parser
  2. import (
  3. "testing"
  4. )
  5. func TestStruct2Map(t *testing.T) {
  6. type Base struct {
  7. A int `json:"a"`
  8. }
  9. type p struct {
  10. Base
  11. B int `json:"b"`
  12. }
  13. d := p{
  14. Base: Base{
  15. A: 1,
  16. },
  17. B: 2,
  18. }
  19. result := StructToMap(d)
  20. if result["a"] != 1 {
  21. t.Error("a should be 1")
  22. }
  23. if result["b"] != 2 {
  24. t.Error("b should be 2")
  25. }
  26. }