2024-11-11 05:36:55 +00:00
|
|
|
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) {
|
2024-11-19 15:30:42 +00:00
|
|
|
parsed, err := parsePath("", defPath)
|
2024-11-11 05:36:55 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|