split tests into separate files
This commit is contained in:
79
lang/parser_entity_test.go
Normal file
79
lang/parser_entity_test.go
Normal file
@ -0,0 +1,79 @@
|
||||
package lang
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseEntityDefinitions(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want AST
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "entity with enhanced fields and relationships",
|
||||
input: `entity User desc "User management"
|
||||
id: uuid required unique
|
||||
email: string required validate email validate min_length "5"
|
||||
name: string default "Anonymous"
|
||||
profile_id: uuid relates to Profile as one via "user_id"`,
|
||||
want: AST{
|
||||
Definitions: []Definition{
|
||||
{
|
||||
Entity: &Entity{
|
||||
Name: "User",
|
||||
Description: stringPtr("User management"),
|
||||
Fields: []Field{
|
||||
{
|
||||
Name: "id",
|
||||
Type: "uuid",
|
||||
Required: true,
|
||||
Unique: true,
|
||||
},
|
||||
{
|
||||
Name: "email",
|
||||
Type: "string",
|
||||
Required: true,
|
||||
Validations: []Validation{
|
||||
{Type: "email"},
|
||||
{Type: "min_length", Value: stringPtr("5")},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "name",
|
||||
Type: "string",
|
||||
Default: stringPtr("Anonymous"),
|
||||
},
|
||||
{
|
||||
Name: "profile_id",
|
||||
Type: "uuid",
|
||||
Relationship: &Relationship{
|
||||
Type: "Profile",
|
||||
Cardinality: "one",
|
||||
ForeignKey: stringPtr("user_id"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := ParseInput(tt.input)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("ParseInput() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
|
||||
if !tt.wantErr && !astEqual(got, tt.want) {
|
||||
t.Errorf("ParseInput() mismatch.\nGot: %+v\nWant: %+v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user