split tests into separate files
This commit is contained in:
138
lang/parser_test_helpers.go
Normal file
138
lang/parser_test_helpers.go
Normal file
@ -0,0 +1,138 @@
|
||||
package lang
|
||||
|
||||
// Helper functions and comparison utilities for parser tests
|
||||
|
||||
// Custom comparison functions (simplified for the new structure)
|
||||
func astEqual(got, want AST) bool {
|
||||
if len(got.Definitions) != len(want.Definitions) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := range got.Definitions {
|
||||
if !definitionEqual(got.Definitions[i], want.Definitions[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func definitionEqual(got, want Definition) bool {
|
||||
// Server comparison
|
||||
if (got.Server == nil) != (want.Server == nil) {
|
||||
return false
|
||||
}
|
||||
if got.Server != nil && want.Server != nil {
|
||||
if got.Server.Name != want.Server.Name {
|
||||
return false
|
||||
}
|
||||
if len(got.Server.Settings) != len(want.Server.Settings) {
|
||||
return false
|
||||
}
|
||||
// Simplified server settings comparison
|
||||
}
|
||||
|
||||
// Entity comparison
|
||||
if (got.Entity == nil) != (want.Entity == nil) {
|
||||
return false
|
||||
}
|
||||
if got.Entity != nil && want.Entity != nil {
|
||||
if got.Entity.Name != want.Entity.Name {
|
||||
return false
|
||||
}
|
||||
// Simplified entity comparison
|
||||
}
|
||||
|
||||
// Endpoint comparison
|
||||
if (got.Endpoint == nil) != (want.Endpoint == nil) {
|
||||
return false
|
||||
}
|
||||
if got.Endpoint != nil && want.Endpoint != nil {
|
||||
if got.Endpoint.Method != want.Endpoint.Method || got.Endpoint.Path != want.Endpoint.Path {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Page comparison (enhanced)
|
||||
if (got.Page == nil) != (want.Page == nil) {
|
||||
return false
|
||||
}
|
||||
if got.Page != nil && want.Page != nil {
|
||||
return pageEqual(*got.Page, *want.Page)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func pageEqual(got, want Page) bool {
|
||||
if got.Name != want.Name || got.Path != want.Path || got.Layout != want.Layout {
|
||||
return false
|
||||
}
|
||||
|
||||
if !stringPtrEqual(got.Title, want.Title) {
|
||||
return false
|
||||
}
|
||||
|
||||
if got.Auth != want.Auth {
|
||||
return false
|
||||
}
|
||||
|
||||
if !stringPtrEqual(got.LayoutType, want.LayoutType) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Compare meta tags
|
||||
if len(got.Meta) != len(want.Meta) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Compare containers
|
||||
if len(got.Containers) != len(want.Containers) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Compare components
|
||||
if len(got.Components) != len(want.Components) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Compare modals
|
||||
if len(got.Modals) != len(want.Modals) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Compare master-detail
|
||||
if (got.MasterDetail == nil) != (want.MasterDetail == nil) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func stringPtrEqual(got, want *string) bool {
|
||||
if (got == nil) != (want == nil) {
|
||||
return false
|
||||
}
|
||||
if got != nil && want != nil {
|
||||
return *got == *want
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func intPtrEqual(got, want *int) bool {
|
||||
if (got == nil) != (want == nil) {
|
||||
return false
|
||||
}
|
||||
if got != nil && want != nil {
|
||||
return *got == *want
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Helper functions for creating pointers
|
||||
func stringPtr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
func intPtr(i int) *int {
|
||||
return &i
|
||||
}
|
Reference in New Issue
Block a user