struct2map_test.go 346 B

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