package sqlgen import ( "encoding/json" "os" "path/filepath" "reflect" "strings" "testing" ) func TestParse(t *testing.T) { toString := func(v any) string { txt, _ := json.MarshalIndent(v, "", " ") return string(txt) } paths, err := filepath.Glob("test-files/TestParse/*.def") if err != nil { t.Fatal(err) } for _, defPath := range paths { t.Run(filepath.Base(defPath), func(t *testing.T) { parsed, err := parsePath("", defPath) if err != nil { t.Fatal(err) } b, err := os.ReadFile(strings.TrimSuffix(defPath, "def") + "json") if err != nil { t.Fatal(err) } expected := &schema{} if err := json.Unmarshal(b, expected); err != nil { t.Fatal(err) } if !reflect.DeepEqual(parsed, expected) { t.Fatalf("%s != %s", toString(parsed), toString(expected)) } }) } }