emit_jsonschema_test.go 726 B

123456789101112131415161718192021222324252627282930
  1. package main
  2. import "testing"
  3. func TestIntegerSchemaFormats(t *testing.T) {
  4. tests := []struct {
  5. name string
  6. goType string
  7. wantFormat string
  8. }{
  9. {name: "int", goType: "int"},
  10. {name: "int32", goType: "int32"},
  11. {name: "int64", goType: "int64", wantFormat: "int64"},
  12. {name: "uint64", goType: "uint64", wantFormat: "int64"},
  13. }
  14. gen := &schemaGen{}
  15. for _, tt := range tests {
  16. t.Run(tt.name, func(t *testing.T) {
  17. schema := gen.typeSchema(identType(tt.goType))
  18. if got := schema["type"]; got != "integer" {
  19. t.Fatalf("type = %v, want integer", got)
  20. }
  21. got, _ := schema["format"].(string)
  22. if got != tt.wantFormat {
  23. t.Fatalf("format = %q, want %q", got, tt.wantFormat)
  24. }
  25. })
  26. }
  27. }