wip
This commit is contained in:
45
sqlgen/parse_test.go
Normal file
45
sqlgen/parse_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
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))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user