split tests into separate files
This commit is contained in:
139
lang/parser_page_test.go
Normal file
139
lang/parser_page_test.go
Normal file
@ -0,0 +1,139 @@
|
||||
package lang
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParsePageDefinitions(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want AST
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "page with container and sections",
|
||||
input: `page UserManagement at "/admin/users" layout AdminLayout title "User Management" auth
|
||||
meta description "Manage users"
|
||||
|
||||
container main class "grid grid-cols-2"
|
||||
section sidebar class "col-span-1"
|
||||
component UserStats for User
|
||||
data from "/users/stats"`,
|
||||
want: AST{
|
||||
Definitions: []Definition{
|
||||
{
|
||||
Page: &Page{
|
||||
Name: "UserManagement",
|
||||
Path: "/admin/users",
|
||||
Layout: "AdminLayout",
|
||||
Title: stringPtr("User Management"),
|
||||
Auth: true,
|
||||
Meta: []MetaTag{
|
||||
{Name: "description", Content: "Manage users"},
|
||||
},
|
||||
Containers: []Container{
|
||||
{
|
||||
Type: "main",
|
||||
Class: stringPtr("grid grid-cols-2"),
|
||||
Sections: []Section{
|
||||
{
|
||||
Name: "sidebar",
|
||||
Class: stringPtr("col-span-1"),
|
||||
Components: []Component{
|
||||
{
|
||||
Type: "UserStats",
|
||||
Entity: stringPtr("User"),
|
||||
Elements: []ComponentElement{
|
||||
{
|
||||
Config: &ComponentAttr{
|
||||
DataSource: &ComponentDataSource{
|
||||
Endpoint: "/users/stats",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "page with panel",
|
||||
input: `page PageWithPanel at "/panel" layout MainLayout
|
||||
container main
|
||||
section content
|
||||
panel UserEditPanel for User trigger "edit" position "slide-right"
|
||||
component UserForm for User
|
||||
field name type text required`,
|
||||
want: AST{
|
||||
Definitions: []Definition{
|
||||
{
|
||||
Page: &Page{
|
||||
Name: "PageWithPanel",
|
||||
Path: "/panel",
|
||||
Layout: "MainLayout",
|
||||
Containers: []Container{
|
||||
{
|
||||
Type: "main",
|
||||
Sections: []Section{
|
||||
{
|
||||
Name: "content",
|
||||
Panels: []Panel{
|
||||
{
|
||||
Name: "UserEditPanel",
|
||||
Entity: stringPtr("User"),
|
||||
Trigger: "edit",
|
||||
Position: stringPtr("slide-right"),
|
||||
Components: []Component{
|
||||
{
|
||||
Type: "UserForm",
|
||||
Entity: stringPtr("User"),
|
||||
Elements: []ComponentElement{
|
||||
{
|
||||
Field: &ComponentField{
|
||||
Name: "name",
|
||||
Type: "text",
|
||||
Attributes: []ComponentFieldAttribute{
|
||||
{Required: true},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
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