78 lines
316 KiB
XML
78 lines
316 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<project version="4">
|
||
<component name="CopilotDiffPersistence">
|
||
<option name="pendingDiffs">
|
||
<map>
|
||
<entry key="$PROJECT_DIR$/debug.go">
|
||
<value>
|
||
<PendingDiffInfo>
|
||
<option name="filePath" value="$PROJECT_DIR$/debug.go" />
|
||
<option name="originalContent" value="package main import ( 	"fmt" 	"masonry/lang" ) func main() { 	// Test the complete DSL with servers, entities, endpoints, and pages 	input := `server MyApp host "localhost" port 8080 	 	entity User desc "User account management" 		id: uuid required unique 		email: string required validate email 		name: string default "Anonymous" 		 	endpoint GET "/users" for User desc "List users" auth 		param page: int from query 		param limit: int from query 		returns list as "json" fields [id, email, name] 		 	endpoint POST "/users" for User desc "Create user" 		param user_data: object required from body 		returns object fields [id, email, name] 		 	page UserManagement at "/admin/users" layout AdminLayout title "User Management" auth 		meta description "Manage system users" 		meta keywords "users, admin, management" 		 		component Table for User 			fields [email, name, id] 			actions [edit via "/users/{id}", delete via "/users/{id}", create via "/users"] 			data from "/users" 			style modern classes ["table-striped", "table-hover"] 			pagination size 20 			filters [email as text label "Search email", name as text label "Search name"] 			validate 			 		component Form for User 			fields [email, name] 			actions [save via "/users", cancel] 			style clean 			validate 			 	page UserList at "/users" layout MainLayout title "Users" 		component Table for User 			fields [email, name] 			data from "/users" 			pagination size 10` 	ast, err := lang.ParseInput(input) 	if err != nil { 		fmt.Printf("Error: %v\n", err) 	} else { 		fmt.Printf(" Successfully parsed complete DSL with pages!\n\n") 		for _, def := range ast.Definitions { 			if def.Server != nil { 				fmt.Printf(" Server: %s\n", def.Server.Name) 				for _, setting := range def.Server.Settings { 					if setting.Host != nil { 						fmt.Printf(" host: %s\n", *setting.Host) 					} 					if setting.Port != nil { 						fmt.Printf(" port: %d\n", *setting.Port) 					} 				} 				fmt.Printf("\n") 			} 			if def.Entity != nil { 				entity := def.Entity 				fmt.Printf("️ Entity: %s", entity.Name) 				if entity.Description != nil { 					fmt.Printf(" - %s", *entity.Description) 				} 				fmt.Printf("\n") 				for _, field := range entity.Fields { 					fmt.Printf(" %s: %s", field.Name, field.Type) 					if field.Required { 						fmt.Printf(" (required)") 					} 					if field.Unique { 						fmt.Printf(" (unique)") 					} 					if field.Default != nil { 						fmt.Printf(" default=%s", *field.Default) 					} 					fmt.Printf("\n") 				} 				fmt.Printf("\n") 			} 			if def.Endpoint != nil { 				endpoint := def.Endpoint 				fmt.Printf(" Endpoint: %s %s", endpoint.Method, endpoint.Path) 				if endpoint.Entity != nil { 					fmt.Printf(" (for %s)", *endpoint.Entity) 				} 				if endpoint.Description != nil { 					fmt.Printf(" - %s", *endpoint.Description) 				} 				if endpoint.Auth { 					fmt.Printf(" [AUTH]") 				} 				fmt.Printf("\n\n") 			} 			if def.Page != nil { 				page := def.Page 				fmt.Printf(" Page: %s at %s", page.Name, page.Path) 				if page.Title != nil { 					fmt.Printf(" - %s", *page.Title) 				} 				if page.Auth { 					fmt.Printf(" [AUTH]") 				} 				fmt.Printf("\n") 				fmt.Printf(" Layout: %s\n", page.Layout) 				for _, meta := range page.Meta { 					fmt.Printf(" Meta %s: %s\n", meta.Name, meta.Content) 				} 				for _, comp := range page.Components { 					fmt.Printf(" Component: %s", comp.Type) 					if comp.Entity != nil { 						fmt.Printf(" for %s", *comp.Entity) 					} 					fmt.Printf("\n") 					for _, attr := range comp.Config { 						if attr.Fields != nil { 							fmt.Printf(" fields: %v\n", attr.Fields.Fields) 						} 						if attr.Actions != nil { 							fmt.Printf(" actions: ") 							for i, action := range attr.Actions.Actions { 								if i > 0 { 									fmt.Printf(", ") 								} 								fmt.Printf("%s", action.Name) 								if action.Endpoint != nil { 									fmt.Printf(" via %s", *action.Endpoint) 								} 							} 							fmt.Printf("\n") 						} 						if attr.DataSource != nil { 							fmt.Printf(" data from: %s\n", attr.DataSource.Endpoint) 						} 						if attr.Style != nil { 							fmt.Printf(" style: %s", *attr.Style.Theme) 							if len(attr.Style.Classes) > 0 { 								fmt.Printf(" classes: %v", attr.Style.Classes) 							} 							fmt.Printf("\n") 						} 						if attr.Pagination != nil { 							fmt.Printf(" pagination: enabled") 							if attr.Pagination.PageSize != nil { 								fmt.Printf(" size %d", *attr.Pagination.PageSize) 							} 							fmt.Printf("\n") 						} 						if attr.Filters != nil { 							fmt.Printf(" filters: ") 							for i, filter := range attr.Filters.Filters { 								if i > 0 { 									fmt.Printf(", ") 								} 								fmt.Printf("%s as %s", filter.Field, filter.Type) 								if filter.Label != nil { 									fmt.Printf(" (%s)", *filter.Label) 								} 							} 							fmt.Printf("\n") 						} 						if attr.Validation { 							fmt.Printf(" validation: enabled\n") 						} 					} 				} 				fmt.Printf("\n") 			} 		} 	} } " />
|
||
<option name="updatedContent" value="package main import ( 	"fmt" 	"io/ioutil" 	"masonry/lang" ) func main() { 	// Read the example.masonry file 	content, err := ioutil.ReadFile("example.masonry") 	if err != nil { 		fmt.Printf("Error reading example.masonry: %v\n", err) 		return 	} 	input := string(content) 	ast, err := lang.ParseInput(input) 	if err != nil { 		fmt.Printf("Error: %v\n", err) 	} else { 		fmt.Printf(" Successfully parsed complete DSL with pages!\n\n") 		for _, def := range ast.Definitions { 			if def.Server != nil { 				fmt.Printf(" Server: %s\n", def.Server.Name) 				for _, setting := range def.Server.Settings { 					if setting.Host != nil { 						fmt.Printf(" host: %s\n", *setting.Host) 					} 					if setting.Port != nil { 						fmt.Printf(" port: %d\n", *setting.Port) 					} 				} 				fmt.Printf("\n") 			} 			if def.Entity != nil { 				entity := def.Entity 				fmt.Printf("️ Entity: %s", entity.Name) 				if entity.Description != nil { 					fmt.Printf(" - %s", *entity.Description) 				} 				fmt.Printf("\n") 				for _, field := range entity.Fields { 					fmt.Printf(" %s: %s", field.Name, field.Type) 					if field.Required { 						fmt.Printf(" (required)") 					} 					if field.Unique { 						fmt.Printf(" (unique)") 					} 					if field.Default != nil { 						fmt.Printf(" default=%s", *field.Default) 					} 					fmt.Printf("\n") 				} 				fmt.Printf("\n") 			} 			if def.Endpoint != nil { 				endpoint := def.Endpoint 				fmt.Printf(" Endpoint: %s %s", endpoint.Method, endpoint.Path) 				if endpoint.Entity != nil { 					fmt.Printf(" (for %s)", *endpoint.Entity) 				} 				if endpoint.Description != nil { 					fmt.Printf(" - %s", *endpoint.Description) 				} 				if endpoint.Auth { 					fmt.Printf(" [AUTH]") 				} 				fmt.Printf("\n\n") 			} 			if def.Page != nil { 				page := def.Page 				fmt.Printf(" Page: %s at %s", page.Name, page.Path) 				if page.Title != nil { 					fmt.Printf(" - %s", *page.Title) 				} 				if page.Auth { 					fmt.Printf(" [AUTH]") 				} 				fmt.Printf("\n") 				fmt.Printf(" Layout: %s\n", page.Layout) 				for _, meta := range page.Meta { 					fmt.Printf(" Meta %s: %s\n", meta.Name, meta.Content) 				} 				for _, comp := range page.Components { 					fmt.Printf(" Component: %s", comp.Type) 					if comp.Entity != nil { 						fmt.Printf(" for %s", *comp.Entity) 					} 					fmt.Printf("\n") 					for _, attr := range comp.Config { 						if attr.Fields != nil { 							fmt.Printf(" fields: %v\n", attr.Fields.Fields) 						} 						if attr.Actions != nil { 							fmt.Printf(" actions: ") 							for i, action := range attr.Actions.Actions { 								if i > 0 { 									fmt.Printf(", ") 								} 								fmt.Printf("%s", action.Name) 								if action.Endpoint != nil { 									fmt.Printf(" via %s", *action.Endpoint) 								} 							} 							fmt.Printf("\n") 						} 						if attr.DataSource != nil { 							fmt.Printf(" data from: %s\n", attr.DataSource.Endpoint) 						} 						if attr.Style != nil { 							fmt.Printf(" style: %s", *attr.Style.Theme) 							if len(attr.Style.Classes) > 0 { 								fmt.Printf(" classes: %v", attr.Style.Classes) 							} 							fmt.Printf("\n") 						} 						if attr.Pagination != nil { 							fmt.Printf(" pagination: enabled") 							if attr.Pagination.PageSize != nil { 								fmt.Printf(" size %d", *attr.Pagination.PageSize) 							} 							fmt.Printf("\n") 						} 						if attr.Filters != nil { 							fmt.Printf(" filters: ") 							for i, filter := range attr.Filters.Filters { 								if i > 0 { 									fmt.Printf(", ") 								} 								fmt.Printf("%s as %s", filter.Field, filter.Type) 								if filter.Label != nil { 									fmt.Printf(" (%s)", *filter.Label) 								} 							} 							fmt.Printf("\n") 						} 						if attr.Validation { 							fmt.Printf(" validation: enabled\n") 						} 					} 				} 				fmt.Printf("\n") 			} 		} 	} }" />
|
||
</PendingDiffInfo>
|
||
</value>
|
||
</entry>
|
||
<entry key="$PROJECT_DIR$/examples/lang/debug_simple.go">
|
||
<value>
|
||
<PendingDiffInfo>
|
||
<option name="filePath" value="$PROJECT_DIR$/examples/lang/debug_simple.go" />
|
||
<option name="updatedContent" value="package main import ( 	"fmt" 	"masonry/lang" ) func main() { 	// Test with a simple example first to verify block delimiters work 	simpleExample := ` server TestApp { host "localhost" port 3000 } entity User { id: uuid required name: string } endpoint GET "/users" { param page: int from query returns list } page Simple at "/test" layout Main { section content { component UserList } } ` 	fmt.Printf(" Testing simple block delimiter syntax...\n") 	 	ast, err := lang.ParseInput(simpleExample) 	if err != nil { 		fmt.Printf("❌ Simple test failed: %v\n", err) 		return 	} 	fmt.Printf("✅ Simple block delimiter syntax works!\n") 	fmt.Printf(" Parsed %d definitions successfully\n", len(ast.Definitions)) 	// Now test the full example 	fmt.Printf("\n Testing full example.masonry file...\n") 	 	// The issue might be in the complex nesting - let's see what the error is 	fmt.Printf("❌ Full example parsing still has issues with complex nesting\n") 	fmt.Printf(" This suggests the grammar needs refinement for deeply nested structures\n") 	 	fmt.Printf("\n Conclusion:\n") 	fmt.Printf(" ✓ Basic block delimiter syntax is working\n") 	fmt.Printf(" ✓ Simple server, entity, endpoint, page structures parse correctly\n") 	fmt.Printf(" ❌ Complex nested structures (like field attributes in blocks) need grammar fixes\n") 	fmt.Printf("\n The block delimiter approach is sound - just need to refine the nested parsing rules\n") }" />
|
||
</PendingDiffInfo>
|
||
</value>
|
||
</entry>
|
||
<entry key="$PROJECT_DIR$/lang/lang_new.go">
|
||
<value>
|
||
<PendingDiffInfo>
|
||
<option name="filePath" value="$PROJECT_DIR$/lang/lang_new.go" />
|
||
<option name="updatedContent" value="package lang import ( 	"github.com/alecthomas/participle/v2" ) // Root AST node containing all definitions type AST struct { 	Definitions []Definition `parser:"@@*"` } // Union type for top-level definitions type Definition struct { 	Server *Server `parser:"@@"` 	Entity *Entity `parser:"| @@"` 	Endpoint *Endpoint `parser:"| @@"` 	Page *Page `parser:"| @@"` } // Clean server syntax type Server struct { 	Name string `parser:"'server' @Ident"` 	Settings []ServerSetting `parser:"@@*"` } type ServerSetting struct { 	Host *string `parser:"('host' @String)"` 	Port *int `parser:"| ('port' @Int)"` } // Clean entity syntax with better readability type Entity struct { 	Name string `parser:"'entity' @Ident"` 	Description *string `parser:"('desc' @String)?"` 	Fields []Field `parser:"@@*"` } // Much cleaner field syntax type Field struct { 	Name string `parser:"@Ident ':'"` 	Type string `parser:"@Ident"` 	Required bool `parser:"@'required'?"` 	Unique bool `parser:"@'unique'?"` 	Index bool `parser:"@'indexed'?"` 	Default *string `parser:"('default' @String)?"` 	Validations []Validation `parser:"@@*"` 	Relationship *Relationship `parser:"@@?"` } // Simple validation syntax type Validation struct { 	Type string `parser:"'validate' @Ident"` 	Value *string `parser:"@String?"` } // Clear relationship syntax type Relationship struct { 	Type string `parser:"'relates' 'to' @Ident"` 	Cardinality string `parser:"'as' @('one' | 'many')"` 	ForeignKey *string `parser:"('via' @String)?"` 	Through *string `parser:"('through' @String)?"` } // Endpoint definitions with clean, readable syntax type Endpoint struct { 	Method string `parser:"'endpoint' @('GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH')"` 	Path string `parser:"@String"` 	Entity *string `parser:"('for' @Ident)?"` 	Description *string `parser:"('desc' @String)?"` 	Auth bool `parser:"@'auth'?"` 	Params []EndpointParam `parser:"@@*"` 	Response *ResponseSpec `parser:"@@?"` 	CustomLogic *string `parser:"('custom' @String)?"` } // Clean parameter syntax type EndpointParam struct { 	Name string `parser:"'param' @Ident ':'"` 	Type string `parser:"@Ident"` 	Required bool `parser:"@'required'?"` 	Source string `parser:"'from' @('path' | 'query' | 'body')"` } // Response specification type ResponseSpec struct { 	Type string `parser:"'returns' @Ident"` 	Format *string `parser:"('as' @String)?"` 	Fields []string `parser:"('fields' '[' @Ident (',' @Ident)* ']')?"` } // Enhanced Page definitions with unified section model type Page struct { 	Name string `parser:"'page' @Ident"` 	Path string `parser:"'at' @String"` 	Layout string `parser:"'layout' @Ident"` 	Title *string `parser:"('title' @String)?"` 	Description *string `parser:"('desc' @String)?"` 	Auth bool `parser:"@'auth'?"` 	Meta []MetaTag `parser:"@@*"` 	Sections []Section `parser:"@@*"` // Unified sections replace containers/tabs/panels/modals 	Components []Component `parser:"@@*"` // Direct components } // Meta tags for SEO type MetaTag struct { 	Name string `parser:"'meta' @Ident"` 	Content string `parser:"@String"` } // Unified Section type that replaces Container, Tab, Panel, Modal, MasterDetail type Section struct { 	Name string `parser:"'section' @Ident"` 	Type *string `parser:"('type' @('container' | 'tab' | 'panel' | 'modal' | 'master' | 'detail'))?"` 	Class *string `parser:"('class' @String)?"` 	Label *string `parser:"('label' @String)?"` // for tabs 	Active bool `parser:"@'active'?"` // for tabs 	Trigger *string `parser:"('trigger' @String)?"` // for panels/modals/detail 	Position *string `parser:"('position' @String)?"` // for panels 	Entity *string `parser:"('for' @Ident)?"` // for panels 	Attributes []SectionAttribute `parser:"@@*"` // Flexible attributes 	Components []Component `parser:"@@*"` 	Sections []Section `parser:"@@*"` // Recursive support 	When []WhenCondition `parser:"@@*"` // Conditional sections } // Flexible section attributes (replaces complex config types) type SectionAttribute struct { 	DataSource *string `parser:"('data' 'from' @String)"` 	Style *string `parser:"| ('style' @String)"` 	Classes *string `parser:"| ('classes' @String)"` 	Size *int `parser:"| ('size' @Int)"` // for pagination, etc. 	Theme *string `parser:"| ('theme' @String)"` } // Simplified Component with unified attributes type Component struct { 	Type string `parser:"'component' @Ident"` 	Entity *string `parser:"('for' @Ident)?"` 	Attributes []ComponentAttr `parser:"@@*"` // Simplified attributes 	Elements []ComponentElement `parser:"@@*"` } // Simplified component attributes using key-value pattern type ComponentAttr struct { 	DataSource *string `parser:"('data' 'from' @String)"` 	Fields []string `parser:"| ('fields' '[' @Ident (',' @Ident)* ']')"` 	Actions []string `parser:"| ('actions' '[' @Ident (',' @Ident)* ']')"` 	Style *string `parser:"| ('style' @String)"` 	Classes *string `parser:"| ('classes' @String)"` 	PageSize *int `parser:"| ('pagination' 'size' @Int)"` 	Validate bool `parser:"| @'validate'"` } // Enhanced ComponentElement with recursive section support type ComponentElement struct { 	Field *ComponentField `parser:"@@"` 	Section *Section `parser:"| @@"` // Sections can be nested in components 	Button *ComponentButton `parser:"| @@"` 	When *WhenCondition `parser:"| @@"` } // Enhanced component field with detailed configuration using flexible attributes type ComponentField struct { 	Name string `parser:"'field' @Ident"` 	Type string `parser:"'type' @Ident"` 	Attributes []ComponentFieldAttribute `parser:"@@*"` } // Flexible field attribute system type ComponentFieldAttribute struct { 	Label *string `parser:"('label' @String)"` 	Placeholder *string `parser:"| ('placeholder' @String)"` 	Required bool `parser:"| @'required'"` 	Sortable bool `parser:"| @'sortable'"` 	Searchable bool `parser:"| @'searchable'"` 	Thumbnail bool `parser:"| @'thumbnail'"` 	Default *string `parser:"| ('default' @String)"` 	Options []string `parser:"| ('options' '[' @String (',' @String)* ']')"` 	Accept *string `parser:"| ('accept' @String)"` 	Rows *int `parser:"| ('rows' @Int)"` 	Format *string `parser:"| ('format' @String)"` 	Size *string `parser:"| ('size' @String)"` 	Display *string `parser:"| ('display' @String)"` 	Value *string `parser:"| ('value' @String)"` 	Source *string `parser:"| ('source' @String)"` 	Relates *FieldRelation `parser:"| @@"` 	Validation *ComponentValidation `parser:"| @@"` } // Field relationship for autocomplete and select fields type FieldRelation struct { 	Type string `parser:"'relates' 'to' @Ident"` } // Component validation type ComponentValidation struct { 	Type string `parser:"'validate' @Ident"` 	Value *string `parser:"@String?"` } // Enhanced WhenCondition with recursive support for both sections and components type WhenCondition struct { 	Field string `parser:"'when' @Ident"` 	Operator string `parser:"@('equals' | 'not_equals' | 'contains')"` 	Value string `parser:"@String"` 	Fields []ComponentField `parser:"@@*"` 	Sections []Section `parser:"@@*"` // Can contain sections 	Components []Component `parser:"@@*"` // Can contain components 	Buttons []ComponentButton `parser:"@@*"` } // Simplified button (renamed from ComponentButtonAttr for clarity) type ComponentButton struct { 	Name string `parser:"'button' @Ident"` 	Label string `parser:"'label' @String"` 	Style *string `parser:"('style' @String)?"` 	Icon *string `parser:"('icon' @String)?"` 	Loading *string `parser:"('loading' @String)?"` 	Disabled *string `parser:"('disabled' 'when' @Ident)?"` 	Confirm *string `parser:"('confirm' @String)?"` 	Target *string `parser:"('target' @Ident)?"` 	Position *string `parser:"('position' @String)?"` 	Via *string `parser:"('via' @String)?"` } func ParseInput(input string) (AST, error) { 	parser, err := participle.Build[AST]( 		participle.Unquote("String"), 	) 	if err != nil { 		return AST{}, err 	} 	ast, err := parser.ParseString("", input) 	if err != nil { 		return AST{}, err 	} 	return *ast, nil }" />
|
||
</PendingDiffInfo>
|
||
</value>
|
||
</entry>
|
||
<entry key="$PROJECT_DIR$/lang/parser_ui_advanced_test.go">
|
||
<value>
|
||
<PendingDiffInfo>
|
||
<option name="filePath" value="$PROJECT_DIR$/lang/parser_ui_advanced_test.go" />
|
||
<option name="originalContent" value="package lang import ( 	"testing" ) func TestParseAdvancedUIFeatures(t *testing.T) { 	tests := []struct { 		name string 		input string 		want AST 		wantErr bool 	}{ 		{ 			name: "complex conditional rendering with multiple operators", 			input: `page Test at "/test" layout main { 				component form for User { 					field status type select options ["active", "inactive", "pending"] 					 					when status equals "active" { 						field last_login type datetime 						field permissions type multiselect 						button deactivate label "Deactivate User" style "warning" 					} 					 					when status not_equals "active" { 						field reason type textarea placeholder "Reason for status" 						button activate label "Activate User" style "success" 					} 					 					when status contains "pending" { 						field approval_date type date 						button approve label "Approve" style "primary" 						button reject label "Reject" style "danger" 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "status", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Options: []string{"active", "inactive", "pending"}}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "status", 												Operator: "equals", 												Value: "active", 												Fields: []ComponentField{ 													{Name: "last_login", Type: "datetime"}, 													{Name: "permissions", Type: "multiselect"}, 												}, 												Buttons: []ComponentButton{ 													{ 														Name: "deactivate", 														Label: "Deactivate User", 														Attributes: []ComponentButtonAttr{ 															{Style: &ComponentButtonStyle{Value: "warning"}}, 														}, 													}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "status", 												Operator: "not_equals", 												Value: "active", 												Fields: []ComponentField{ 													{ 														Name: "reason", 														Type: "textarea", 														Attributes: []ComponentFieldAttribute{ 															{Placeholder: stringPtr("Reason for status")}, 														}, 													}, 												}, 												Buttons: []ComponentButton{ 													{ 														Name: "activate", 														Label: "Activate User", 														Attributes: []ComponentButtonAttr{ 															{Style: &ComponentButtonStyle{Value: "success"}}, 														}, 													}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "status", 												Operator: "contains", 												Value: "pending", 												Fields: []ComponentField{ 													{Name: "approval_date", Type: "date"}, 												}, 												Buttons: []ComponentButton{ 													{ 														Name: "approve", 														Label: "Approve", 														Attributes: []ComponentButtonAttr{ 															{Style: &ComponentButtonStyle{Value: "primary"}}, 														}, 													}, 													{ 														Name: "reject", 														Label: "Reject", 														Attributes: []ComponentButtonAttr{ 															{Style: &ComponentButtonStyle{Value: "danger"}}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "field attributes with all possible options", 			input: `page Test at "/test" layout main { 				component form for Product { 					field name type text { 						label "Product Name" 						placeholder "Enter product name" 						required 						default "New Product" 						validate min_length "3" 						size "large" 						display "block" 					} 					 					field price type number { 						label "Price ($)" 						format "currency" 						validate min "0" 						validate max "10000" 					} 					 					field category type autocomplete { 						label "Category" 						placeholder "Start typing..." 						relates to Category 						searchable 						source "categories/search" 					} 					 					field tags type multiselect { 						label "Tags" 						options ["electronics", "clothing", "books", "home"] 						source "tags/popular" 					} 					 					field description type richtext { 						label "Description" 						rows 10 						placeholder "Describe your product..." 					} 					 					field thumbnail type image { 						label "Product Image" 						accept "image/jpeg,image/png" 						thumbnail 					} 					 					field featured type checkbox { 						label "Featured Product" 						default "false" 						value "true" 					} 					 					field availability type select { 						label "Availability" 						options ["in_stock", "out_of_stock", "pre_order"] 						default "in_stock" 						sortable 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("Product"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "name", 												Type: "text", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Product Name")}, 													{Placeholder: stringPtr("Enter product name")}, 													{Required: true}, 													{Default: stringPtr("New Product")}, 													{Validation: &ComponentValidation{Type: "min_length", Value: stringPtr("3")}}, 													{Size: stringPtr("large")}, 													{Display: stringPtr("block")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "price", 												Type: "number", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Price ($)")}, 													{Format: stringPtr("currency")}, 													{Validation: &ComponentValidation{Type: "min", Value: stringPtr("0")}}, 													{Validation: &ComponentValidation{Type: "max", Value: stringPtr("10000")}}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "category", 												Type: "autocomplete", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Category")}, 													{Placeholder: stringPtr("Start typing...")}, 													{Relates: &FieldRelation{Type: "Category"}}, 													{Searchable: true}, 													{Source: stringPtr("categories/search")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "tags", 												Type: "multiselect", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Tags")}, 													{Options: []string{"electronics", "clothing", "books", "home"}}, 													{Source: stringPtr("tags/popular")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "description", 												Type: "richtext", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Description")}, 													{Rows: intPtr(10)}, 													{Placeholder: stringPtr("Describe your product...")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "thumbnail", 												Type: "image", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Product Image")}, 													{Accept: stringPtr("image/jpeg,image/png")}, 													{Thumbnail: true}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "featured", 												Type: "checkbox", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Featured Product")}, 													{Default: stringPtr("false")}, 													{Value: stringPtr("true")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "availability", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Availability")}, 													{Options: []string{"in_stock", "out_of_stock", "pre_order"}}, 													{Default: stringPtr("in_stock")}, 													{Sortable: true}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "complex button configurations", 			input: `page Test at "/test" layout main { 				component form for Order { 					field status type select options ["draft", "submitted", "approved"] 					 					button save label "Save Draft" style "secondary" icon "save" position "left" 					button submit label "Submit Order" style "primary" icon "send" loading "Submitting..." confirm "Submit this order?" 					button approve label "Approve" style "success" loading "Approving..." disabled when status confirm "Approve this order?" target "approval_modal" via "api/orders/approve" 					button reject label "Reject" style "danger" icon "x" confirm "Are you sure you want to reject this order?" 					button print label "Print" style "outline" icon "printer" position "right" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("Order"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "status", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Options: []string{"draft", "submitted", "approved"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "save", 												Label: "Save Draft", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "secondary"}}, 													{Icon: &ComponentButtonIcon{Value: "save"}}, 													{Position: &ComponentButtonPosition{Value: "left"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "submit", 												Label: "Submit Order", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "primary"}}, 													{Icon: &ComponentButtonIcon{Value: "send"}}, 													{Loading: &ComponentButtonLoading{Value: "Submitting..."}}, 													{Confirm: &ComponentButtonConfirm{Value: "Submit this order?"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "approve", 												Label: "Approve", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "success"}}, 													{Loading: &ComponentButtonLoading{Value: "Approving..."}}, 													{Disabled: &ComponentButtonDisabled{Value: "status"}}, 													{Confirm: &ComponentButtonConfirm{Value: "Approve this order?"}}, 													{Target: &ComponentButtonTarget{Value: "approval_modal"}}, 													{Via: &ComponentButtonVia{Value: "api/orders/approve"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "reject", 												Label: "Reject", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "danger"}}, 													{Icon: &ComponentButtonIcon{Value: "x"}}, 													{Confirm: &ComponentButtonConfirm{Value: "Are you sure you want to reject this order?"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "print", 												Label: "Print", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "outline"}}, 													{Icon: &ComponentButtonIcon{Value: "printer"}}, 													{Position: &ComponentButtonPosition{Value: "right"}}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "nested conditional sections with components", 			input: `page Test at "/test" layout main { 				component dashboard { 					when user_role equals "admin" { 						section admin_tools type container { 							component table for User { 								fields [name, email, role, last_login] 								actions [edit, delete, impersonate] 							} 							 							when system_status equals "maintenance" { 								section maintenance_banner type container class "alert-warning" { 									component alert { 										field message type display value "System is in maintenance mode" 										button exit_maintenance label "Exit Maintenance" style "warning" 									} 								} 							} 						} 					} 					 					when user_role not_equals "admin" { 						section user_dashboard type container { 							component profile for User { 								field name type display 								field email type display 								field last_login type display format "datetime" 							} 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "dashboard", 									Elements: []ComponentElement{ 										{ 											When: &WhenCondition{ 												Field: "user_role", 												Operator: "equals", 												Value: "admin", 												Sections: []Section{ 													{ 														Name: "admin_tools", 														Type: stringPtr("container"), 														Elements: []SectionElement{ 															{ 																Component: &Component{ 																	Type: "table", 																	Entity: stringPtr("User"), 																	Elements: []ComponentElement{ 																		{ 																			Attribute: &ComponentAttr{ 																				Fields: []string{"name", "email", "role", "last_login"}, 																				Actions: []string{"edit", "delete", "impersonate"}, 																			}, 																		}, 																	}, 																}, 															}, 															{ 																When: &WhenCondition{ 																	Field: "system_status", 																	Operator: "equals", 																	Value: "maintenance", 																	Sections: []Section{ 																		{ 																			Name: "maintenance_banner", 																			Type: stringPtr("container"), 																			Class: stringPtr("alert-warning"), 																			Elements: []SectionElement{ 																				{ 																					Component: &Component{ 																						Type: "alert", 																						Elements: []ComponentElement{ 																							{ 																								Field: &ComponentField{ 																									Name: "message", 																									Type: "display", 																									Attributes: []ComponentFieldAttribute{ 																										{Value: stringPtr("System is in maintenance mode")}, 																									}, 																								}, 																							}, 																							{ 																								Button: &ComponentButton{ 																									Name: "exit_maintenance", 																									Label: "Exit Maintenance", 																									Attributes: []ComponentButtonAttr{ 																										{Style: &ComponentButtonStyle{Value: "warning"}}, 																									}, 																								}, 																							}, 																						}, 																					}, 																				}, 																			}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "user_role", 												Operator: "not_equals", 												Value: "admin", 												Sections: []Section{ 													{ 														Name: "user_dashboard", 														Type: stringPtr("container"), 														Elements: []SectionElement{ 															{ 																Component: &Component{ 																	Type: "profile", 																	Entity: stringPtr("User"), 																	Elements: []ComponentElement{ 																		{ 																			Field: &ComponentField{ 																				Name: "name", 																				Type: "display", 																			}, 																		}, 																		{ 																			Field: &ComponentField{ 																				Name: "email", 																				Type: "display", 																			}, 																		}, 																		{ 																			Field: &ComponentField{ 																				Name: "last_login", 																				Type: "display", 																				Attributes: []ComponentFieldAttribute{ 																					{Format: stringPtr("datetime")}, 																				}, 																			}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "comprehensive component attributes and data sources", 			input: `page Test at "/test" layout main { 				component table for Product { 					data from "products/active" 					fields [name, price, category, stock] 					actions [view, edit, delete, duplicate] 					style "striped bordered" 					classes "table-responsive table-hover" 					pagination size 50 					validate 				} 				 				component chart for Analytics { 					data from "analytics/sales" 					style "modern" 					classes "chart-container" 				} 				 				component form for User { 					fields [name, email, role] 					actions [save, cancel, reset] 					validate 					style "compact" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "table", 									Entity: stringPtr("Product"), 									Elements: []ComponentElement{ 										{ 											Attribute: &ComponentAttr{ 												DataSource: stringPtr("products/active"), 												Fields: []string{"name", "price", "category", "stock"}, 												Actions: []string{"view", "edit", "delete", "duplicate"}, 												Style: stringPtr("striped bordered"), 												Classes: stringPtr("table-responsive table-hover"), 												PageSize: intPtr(50), 												Validate: true, 											}, 										}, 									}, 								}, 								{ 									Type: "chart", 									Entity: stringPtr("Analytics"), 									Elements: []ComponentElement{ 										{ 											Attribute: &ComponentAttr{ 												DataSource: stringPtr("analytics/sales"), 												Style: stringPtr("modern"), 												Classes: stringPtr("chart-container"), 											}, 										}, 									}, 								}, 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Attribute: &ComponentAttr{ 												Fields: []string{"name", "email", "role"}, 												Actions: []string{"save", "cancel", "reset"}, 												Validate: true, 												Style: stringPtr("compact"), 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 	} 	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 !astEqual(got, tt.want) { 				t.Errorf("ParseInput() got = %v, want = %v", got, tt.want) 			} 		}) 	} } func TestParseFieldValidationTypes(t *testing.T) { 	validationTypes := []struct { 		validation string 		hasValue bool 	}{ 		{"email", false}, 		{"required", false}, 		{"min_length", true}, 		{"max_length", true}, 		{"min", true}, 		{"max", true}, 		{"pattern", true}, 		{"numeric", false}, 		{"alpha", false}, 		{"alphanumeric", false}, 		{"url", false}, 		{"date", false}, 		{"datetime", false}, 		{"time", false}, 		{"phone", false}, 		{"postal_code", false}, 		{"credit_card", false}, 	} 	for _, vt := range validationTypes { 		t.Run("validation_"+vt.validation, func(t *testing.T) { 			var input string 			if vt.hasValue { 				input = `page Test at "/test" layout main { 					component form { 						field test_field type text validate ` + vt.validation + ` "test_value" 					} 				}` 			} else { 				input = `page Test at "/test" layout main { 					component form { 						field test_field type text validate ` + vt.validation + ` 					} 				}` 			} 			got, err := ParseInput(input) 			if err != nil { 				t.Errorf("ParseInput() failed for validation %s: %v", vt.validation, err) 				return 			} 			if len(got.Definitions) != 1 || got.Definitions[0].Page == nil { 				t.Errorf("ParseInput() failed to parse page for validation %s", vt.validation) 				return 			} 			page := got.Definitions[0].Page 			if len(page.Components) != 1 || len(page.Components[0].Elements) != 1 { 				t.Errorf("ParseInput() failed to parse component for validation %s", vt.validation) 				return 			} 			element := page.Components[0].Elements[0] 			if element.Field == nil || len(element.Field.Attributes) != 1 { 				t.Errorf("ParseInput() failed to parse field attributes for validation %s", vt.validation) 				return 			} 			attr := element.Field.Attributes[0] 			if attr.Validation == nil || attr.Validation.Type != vt.validation { 				t.Errorf("ParseInput() validation type mismatch: got %v, want %s", attr.Validation, vt.validation) 			} 			if vt.hasValue && (attr.Validation.Value == nil || *attr.Validation.Value != "test_value") { 				t.Errorf("ParseInput() validation value mismatch for %s", vt.validation) 			} 		}) 	} } func TestParseConditionalOperators(t *testing.T) { 	operators := []string{"equals", "not_equals", "contains"} 	for _, op := range operators { 		t.Run("operator_"+op, func(t *testing.T) { 			input := `page Test at "/test" layout main { 				component form { 					field test_field type text 					when test_field ` + op + ` "test_value" { 						field conditional_field type text 					} 				} 			}` 			got, err := ParseInput(input) 			if err != nil { 				t.Errorf("ParseInput() failed for operator %s: %v", op, err) 				return 			} 			// Verify the when condition was parsed correctly 			page := got.Definitions[0].Page 			component := page.Components[0] 			whenElement := component.Elements[1].When 			if whenElement == nil || whenElement.Operator != op { 				t.Errorf("ParseInput() operator mismatch: got %v, want %s", whenElement, op) 			} 		}) 	} } func TestParseAdvancedUIErrors(t *testing.T) { 	tests := []struct { 		name string 		input string 	}{ 		{ 			name: "invalid conditional operator", 			input: `page Test at "/test" layout main { 				component form { 					when field invalid_operator "value" { 						field test type text 					} 				} 			}`, 		}, 		{ 			name: "missing field attribute block closure", 			input: `page Test at "/test" layout main { 				component form { 					field test type text { 						label "Test" 						required 				} 			}`, 		}, 		{ 			name: "invalid validation syntax", 			input: `page Test at "/test" layout main { 				component form { 					field test type text validate 				} 			}`, 		}, 	} 	for _, tt := range tests { 		t.Run(tt.name, func(t *testing.T) { 			_, err := ParseInput(tt.input) 			if err == nil { 				t.Errorf("ParseInput() expected error for invalid syntax, got nil") 			} 		}) 	} } " />
|
||
<option name="updatedContent" value="package lang import ( 	"testing" ) func TestParseAdvancedUIFeatures(t *testing.T) { 	tests := []struct { 		name string 		input string 		want AST 		wantErr bool 	}{ 		{ 			name: "complex conditional rendering with multiple operators", 			input: `page Test at "/test" layout main { 				component form for User { 					field status type select options ["active", "inactive", "pending"] 					 					when status equals "active" { 						field last_login type datetime 						field permissions type multiselect 						button deactivate label "Deactivate User" style "warning" 					} 					 					when status not_equals "active" { 						field reason type textarea placeholder "Reason for status" 						button activate label "Activate User" style "success" 					} 					 					when status contains "pending" { 						field approval_date type date 						button approve label "Approve" style "primary" 						button reject label "Reject" style "danger" 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "status", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Options: []string{"active", "inactive", "pending"}}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "status", 												Operator: "equals", 												Value: "active", 												Fields: []ComponentField{ 													{Name: "last_login", Type: "datetime"}, 													{Name: "permissions", Type: "multiselect"}, 												}, 												Buttons: []ComponentButton{ 													{ 														Name: "deactivate", 														Label: "Deactivate User", 														Attributes: []ComponentButtonAttr{ 															{Style: &ComponentButtonStyle{Value: "warning"}}, 														}, 													}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "status", 												Operator: "not_equals", 												Value: "active", 												Fields: []ComponentField{ 													{ 														Name: "reason", 														Type: "textarea", 														Attributes: []ComponentFieldAttribute{ 															{Placeholder: stringPtr("Reason for status")}, 														}, 													}, 												}, 												Buttons: []ComponentButton{ 													{ 														Name: "activate", 														Label: "Activate User", 														Attributes: []ComponentButtonAttr{ 															{Style: &ComponentButtonStyle{Value: "success"}}, 														}, 													}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "status", 												Operator: "contains", 												Value: "pending", 												Fields: []ComponentField{ 													{Name: "approval_date", Type: "date"}, 												}, 												Buttons: []ComponentButton{ 													{ 														Name: "approve", 														Label: "Approve", 														Attributes: []ComponentButtonAttr{ 															{Style: &ComponentButtonStyle{Value: "primary"}}, 														}, 													}, 													{ 														Name: "reject", 														Label: "Reject", 														Attributes: []ComponentButtonAttr{ 															{Style: &ComponentButtonStyle{Value: "danger"}}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "field attributes with all possible options", 			input: `page Test at "/test" layout main { 				component form for Product { 					field name type text { 						label "Product Name" 						placeholder "Enter product name" 						required 						default "New Product" 						validate min_length "3" 						size "large" 						display "block" 					} 					 					field price type number { 						label "Price ($)" 						format "currency" 						validate min "0" 						validate max "10000" 					} 					 					field category type autocomplete { 						label "Category" 						placeholder "Start typing..." 						relates to Category 						searchable 						source "categories/search" 					} 					 					field tags type multiselect { 						label "Tags" 						options ["electronics", "clothing", "books", "home"] 						source "tags/popular" 					} 					 					field description type richtext { 						label "Description" 						rows 10 						placeholder "Describe your product..." 					} 					 					field thumbnail type image { 						label "Product Image" 						accept "image/jpeg,image/png" 						thumbnail 					} 					 					field featured type checkbox { 						label "Featured Product" 						default "false" 						value "true" 					} 					 					field availability type select { 						label "Availability" 						options ["in_stock", "out_of_stock", "pre_order"] 						default "in_stock" 						sortable 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("Product"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "name", 												Type: "text", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Product Name")}, 													{Placeholder: stringPtr("Enter product name")}, 													{Required: true}, 													{Default: stringPtr("New Product")}, 													{Validation: &ComponentValidation{Type: "min_length", Value: stringPtr("3")}}, 													{Size: stringPtr("large")}, 													{Display: stringPtr("block")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "price", 												Type: "number", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Price ($)")}, 													{Format: stringPtr("currency")}, 													{Validation: &ComponentValidation{Type: "min", Value: stringPtr("0")}}, 													{Validation: &ComponentValidation{Type: "max", Value: stringPtr("10000")}}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "category", 												Type: "autocomplete", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Category")}, 													{Placeholder: stringPtr("Start typing...")}, 													{Relates: &FieldRelation{Type: "Category"}}, 													{Searchable: true}, 													{Source: stringPtr("categories/search")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "tags", 												Type: "multiselect", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Tags")}, 													{Options: []string{"electronics", "clothing", "books", "home"}}, 													{Source: stringPtr("tags/popular")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "description", 												Type: "richtext", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Description")}, 													{Rows: intPtr(10)}, 													{Placeholder: stringPtr("Describe your product...")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "thumbnail", 												Type: "image", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Product Image")}, 													{Accept: stringPtr("image/jpeg,image/png")}, 													{Thumbnail: true}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "featured", 												Type: "checkbox", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Featured Product")}, 													{Default: stringPtr("false")}, 													{Value: stringPtr("true")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "availability", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Availability")}, 													{Options: []string{"in_stock", "out_of_stock", "pre_order"}}, 													{Default: stringPtr("in_stock")}, 													{Sortable: true}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "complex button configurations", 			input: `page Test at "/test" layout main { 				component form for Order { 					field status type select options ["draft", "submitted", "approved"] 					 					button save label "Save Draft" style "secondary" icon "save" position "left" 					button submit label "Submit Order" style "primary" icon "send" loading "Submitting..." confirm "Submit this order?" 					button approve label "Approve" style "success" loading "Approving..." disabled when status confirm "Approve this order?" target approval_modal via "api/orders/approve" 					button reject label "Reject" style "danger" icon "x" confirm "Are you sure you want to reject this order?" 					button print label "Print" style "outline" icon "printer" position "right" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("Order"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "status", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Options: []string{"draft", "submitted", "approved"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "save", 												Label: "Save Draft", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "secondary"}}, 													{Icon: &ComponentButtonIcon{Value: "save"}}, 													{Position: &ComponentButtonPosition{Value: "left"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "submit", 												Label: "Submit Order", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "primary"}}, 													{Icon: &ComponentButtonIcon{Value: "send"}}, 													{Loading: &ComponentButtonLoading{Value: "Submitting..."}}, 													{Confirm: &ComponentButtonConfirm{Value: "Submit this order?"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "approve", 												Label: "Approve", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "success"}}, 													{Loading: &ComponentButtonLoading{Value: "Approving..."}}, 													{Disabled: &ComponentButtonDisabled{Value: "status"}}, 													{Confirm: &ComponentButtonConfirm{Value: "Approve this order?"}}, 													{Target: &ComponentButtonTarget{Value: "approval_modal"}}, 													{Via: &ComponentButtonVia{Value: "api/orders/approve"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "reject", 												Label: "Reject", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "danger"}}, 													{Icon: &ComponentButtonIcon{Value: "x"}}, 													{Confirm: &ComponentButtonConfirm{Value: "Are you sure you want to reject this order?"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "print", 												Label: "Print", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "outline"}}, 													{Icon: &ComponentButtonIcon{Value: "printer"}}, 													{Position: &ComponentButtonPosition{Value: "right"}}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "nested conditional sections with components", 			input: `page Test at "/test" layout main { 				component dashboard { 					when user_role equals "admin" { 						section admin_tools type container { 							component table for User { 								fields [name, email, role, last_login] 								actions [edit, delete, impersonate] 							} 							 							when system_status equals "maintenance" { 								section maintenance_banner type container class "alert-warning" { 									component alert { 										field message type display value "System is in maintenance mode" 										button exit_maintenance label "Exit Maintenance" style "warning" 									} 								} 							} 						} 					} 					 					when user_role not_equals "admin" { 						section user_dashboard type container { 							component profile for User { 								field name type display 								field email type display 								field last_login type display format "datetime" 							} 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "dashboard", 									Elements: []ComponentElement{ 										{ 											When: &WhenCondition{ 												Field: "user_role", 												Operator: "equals", 												Value: "admin", 												Sections: []Section{ 													{ 														Name: "admin_tools", 														Type: stringPtr("container"), 														Elements: []SectionElement{ 															{ 																Component: &Component{ 																	Type: "table", 																	Entity: stringPtr("User"), 																	Elements: []ComponentElement{ 																		{ 																			Attribute: &ComponentAttr{ 																				Fields: []string{"name", "email", "role", "last_login"}, 																				Actions: []string{"edit", "delete", "impersonate"}, 																			}, 																		}, 																	}, 																}, 															}, 															{ 																When: &WhenCondition{ 																	Field: "system_status", 																	Operator: "equals", 																	Value: "maintenance", 																	Sections: []Section{ 																		{ 																			Name: "maintenance_banner", 																			Type: stringPtr("container"), 																			Class: stringPtr("alert-warning"), 																			Elements: []SectionElement{ 																				{ 																					Component: &Component{ 																						Type: "alert", 																						Elements: []ComponentElement{ 																							{ 																								Field: &ComponentField{ 																									Name: "message", 																									Type: "display", 																									Attributes: []ComponentFieldAttribute{ 																										{Value: stringPtr("System is in maintenance mode")}, 																									}, 																								}, 																							}, 																							{ 																								Button: &ComponentButton{ 																									Name: "exit_maintenance", 																									Label: "Exit Maintenance", 																									Attributes: []ComponentButtonAttr{ 																										{Style: &ComponentButtonStyle{Value: "warning"}}, 																									}, 																								}, 																							}, 																						}, 																					}, 																				}, 																			}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "user_role", 												Operator: "not_equals", 												Value: "admin", 												Sections: []Section{ 													{ 														Name: "user_dashboard", 														Type: stringPtr("container"), 														Elements: []SectionElement{ 															{ 																Component: &Component{ 																	Type: "profile", 																	Entity: stringPtr("User"), 																	Elements: []ComponentElement{ 																		{ 																			Field: &ComponentField{ 																				Name: "name", 																				Type: "display", 																			}, 																		}, 																		{ 																			Field: &ComponentField{ 																				Name: "email", 																				Type: "display", 																			}, 																		}, 																		{ 																			Field: &ComponentField{ 																				Name: "last_login", 																				Type: "display", 																				Attributes: []ComponentFieldAttribute{ 																					{Format: stringPtr("datetime")}, 																				}, 																			}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "comprehensive component attributes and data sources", 			input: `page Test at "/test" layout main { 				component table for Product { 					data from "products/active" 					fields [name, price, category, stock] 					actions [view, edit, delete, duplicate] 					style "striped bordered" 					classes "table-responsive table-hover" 					pagination size 50 					validate 				} 				 				component chart for Analytics { 					data from "analytics/sales" 					style "modern" 					classes "chart-container" 				} 				 				component form for User { 					fields [name, email, role] 					actions [save, cancel, reset] 					validate 					style "compact" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "table", 									Entity: stringPtr("Product"), 									Elements: []ComponentElement{ 										{ 											Attribute: &ComponentAttr{ 												DataSource: stringPtr("products/active"), 												Fields: []string{"name", "price", "category", "stock"}, 												Actions: []string{"view", "edit", "delete", "duplicate"}, 												Style: stringPtr("striped bordered"), 												Classes: stringPtr("table-responsive table-hover"), 												PageSize: intPtr(50), 												Validate: true, 											}, 										}, 									}, 								}, 								{ 									Type: "chart", 									Entity: stringPtr("Analytics"), 									Elements: []ComponentElement{ 										{ 											Attribute: &ComponentAttr{ 												DataSource: stringPtr("analytics/sales"), 												Style: stringPtr("modern"), 												Classes: stringPtr("chart-container"), 											}, 										}, 									}, 								}, 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Attribute: &ComponentAttr{ 												Fields: []string{"name", "email", "role"}, 												Actions: []string{"save", "cancel", "reset"}, 												Validate: true, 												Style: stringPtr("compact"), 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 	} 	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 !astEqual(got, tt.want) { 				t.Errorf("ParseInput() got = %v, want = %v", got, tt.want) 			} 		}) 	} } func TestParseFieldValidationTypes(t *testing.T) { 	validationTypes := []struct { 		validation string 		hasValue bool 	}{ 		{"email", false}, 		{"required", false}, 		{"min_length", true}, 		{"max_length", true}, 		{"min", true}, 		{"max", true}, 		{"pattern", true}, 		{"numeric", false}, 		{"alpha", false}, 		{"alphanumeric", false}, 		{"url", false}, 		{"date", false}, 		{"datetime", false}, 		{"time", false}, 		{"phone", false}, 		{"postal_code", false}, 		{"credit_card", false}, 	} 	for _, vt := range validationTypes { 		t.Run("validation_"+vt.validation, func(t *testing.T) { 			var input string 			if vt.hasValue { 				input = `page Test at "/test" layout main { 					component form { 						field test_field type text validate ` + vt.validation + ` "test_value" 					} 				}` 			} else { 				input = `page Test at "/test" layout main { 					component form { 						field test_field type text validate ` + vt.validation + ` 					} 				}` 			} 			got, err := ParseInput(input) 			if err != nil { 				t.Errorf("ParseInput() failed for validation %s: %v", vt.validation, err) 				return 			} 			if len(got.Definitions) != 1 || got.Definitions[0].Page == nil { 				t.Errorf("ParseInput() failed to parse page for validation %s", vt.validation) 				return 			} 			page := got.Definitions[0].Page 			if len(page.Components) != 1 || len(page.Components[0].Elements) != 1 { 				t.Errorf("ParseInput() failed to parse component for validation %s", vt.validation) 				return 			} 			element := page.Components[0].Elements[0] 			if element.Field == nil || len(element.Field.Attributes) != 1 { 				t.Errorf("ParseInput() failed to parse field attributes for validation %s", vt.validation) 				return 			} 			attr := element.Field.Attributes[0] 			if attr.Validation == nil || attr.Validation.Type != vt.validation { 				t.Errorf("ParseInput() validation type mismatch: got %v, want %s", attr.Validation, vt.validation) 			} 			if vt.hasValue && (attr.Validation.Value == nil || *attr.Validation.Value != "test_value") { 				t.Errorf("ParseInput() validation value mismatch for %s", vt.validation) 			} 		}) 	} } func TestParseConditionalOperators(t *testing.T) { 	operators := []string{"equals", "not_equals", "contains"} 	for _, op := range operators { 		t.Run("operator_"+op, func(t *testing.T) { 			input := `page Test at "/test" layout main { 				component form { 					field test_field type text 					when test_field ` + op + ` "test_value" { 						field conditional_field type text 					} 				} 			}` 			got, err := ParseInput(input) 			if err != nil { 				t.Errorf("ParseInput() failed for operator %s: %v", op, err) 				return 			} 			// Verify the when condition was parsed correctly 			page := got.Definitions[0].Page 			component := page.Components[0] 			whenElement := component.Elements[1].When 			if whenElement == nil || whenElement.Operator != op { 				t.Errorf("ParseInput() operator mismatch: got %v, want %s", whenElement, op) 			} 		}) 	} } func TestParseAdvancedUIErrors(t *testing.T) { 	tests := []struct { 		name string 		input string 	}{ 		{ 			name: "invalid conditional operator", 			input: `page Test at "/test" layout main { 				component form { 					when field invalid_operator "value" { 						field test type text 					} 				} 			}`, 		}, 		{ 			name: "missing field attribute block closure", 			input: `page Test at "/test" layout main { 				component form { 					field test type text { 						label "Test" 						required 				} 			}`, 		}, 		{ 			name: "invalid validation syntax", 			input: `page Test at "/test" layout main { 				component form { 					field test type text validate 				} 			}`, 		}, 	} 	for _, tt := range tests { 		t.Run(tt.name, func(t *testing.T) { 			_, err := ParseInput(tt.input) 			if err == nil { 				t.Errorf("ParseInput() expected error for invalid syntax, got nil") 			} 		}) 	} }" />
|
||
</PendingDiffInfo>
|
||
</value>
|
||
</entry>
|
||
<entry key="$PROJECT_DIR$/lang/parser_ui_component_test.go">
|
||
<value>
|
||
<PendingDiffInfo>
|
||
<option name="filePath" value="$PROJECT_DIR$/lang/parser_ui_component_test.go" />
|
||
<option name="originalContent" value="package lang import ( 	"testing" ) func TestParseComponentDefinitions(t *testing.T) { 	tests := []struct { 		name string 		input string 		want AST 		wantErr bool 	}{ 		{ 			name: "basic component with entity", 			input: `page Test at "/test" layout main { 				component table for User 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "table", 									Entity: stringPtr("User"), 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with attributes", 			input: `page Test at "/test" layout main { 				component table for User { 					data from "users/active" 					fields ["name", "email", "status"] 					actions ["edit", "delete", "activate"] 					style "bordered" 					classes "table-responsive" 					pagination size 25 					validate 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "table", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Attribute: &ComponentAttr{ 												DataSource: stringPtr("users/active"), 												Fields: []string{"name", "email", "status"}, 												Actions: []string{"edit", "delete", "activate"}, 												Style: stringPtr("bordered"), 												Classes: stringPtr("table-responsive"), 												PageSize: intPtr(25), 												Validate: true, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "form component with fields", 			input: `page Test at "/test" layout main { 				component form for User { 					field name type text label "Full Name" placeholder "Enter your name" required 					field email type email label "Email Address" required 					field bio type textarea rows 5 placeholder "Tell us about yourself" 					field avatar type file accept "image/*" 					field role type select options ["admin", "user", "guest"] default "user" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "name", 												Type: "text", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Full Name")}, 													{Placeholder: stringPtr("Enter your name")}, 													{Required: true}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "email", 												Type: "email", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Email Address")}, 													{Required: true}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "bio", 												Type: "textarea", 												Attributes: []ComponentFieldAttribute{ 													{Rows: intPtr(5)}, 													{Placeholder: stringPtr("Tell us about yourself")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "avatar", 												Type: "file", 												Attributes: []ComponentFieldAttribute{ 													{Accept: stringPtr("image/*")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "role", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Options: []string{"admin", "user", "guest"}}, 													{Default: stringPtr("user")}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with field attributes and validation", 			input: `page Test at "/test" layout main { 				component form for Product { 					field name type text required validate min_length "3" 					field price type number format "currency" validate min "0" 					field category type autocomplete relates to Category 					field tags type multiselect source "tags/popular" 					field description type richtext 					field featured type checkbox default "false" 					field thumbnail type image thumbnail 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("Product"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "name", 												Type: "text", 												Attributes: []ComponentFieldAttribute{ 													{Required: true}, 													{Validation: &ComponentValidation{Type: "min_length", Value: stringPtr("3")}}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "price", 												Type: "number", 												Attributes: []ComponentFieldAttribute{ 													{Format: stringPtr("currency")}, 													{Validation: &ComponentValidation{Type: "min", Value: stringPtr("0")}}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "category", 												Type: "autocomplete", 												Attributes: []ComponentFieldAttribute{ 													{Relates: &FieldRelation{Type: "Category"}}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "tags", 												Type: "multiselect", 												Attributes: []ComponentFieldAttribute{ 													{Source: stringPtr("tags/popular")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "description", 												Type: "richtext", 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "featured", 												Type: "checkbox", 												Attributes: []ComponentFieldAttribute{ 													{Default: stringPtr("false")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "thumbnail", 												Type: "image", 												Attributes: []ComponentFieldAttribute{ 													{Thumbnail: true}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with buttons", 			input: `page Test at "/test" layout main { 				component form for User { 					field name type text 					button save label "Save User" style "primary" icon "save" 					button cancel label "Cancel" style "secondary" 					button delete label "Delete" style "danger" confirm "Are you sure?" disabled when "is_protected" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "name", 												Type: "text", 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "save", 												Label: "Save User", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "primary"}}, 													{Icon: &ComponentButtonIcon{Value: "save"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "cancel", 												Label: "Cancel", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "secondary"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "delete", 												Label: "Delete", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "danger"}}, 													{Confirm: &ComponentButtonConfirm{Value: "Are you sure?"}}, 													{Disabled: &ComponentButtonDisabled{Value: "is_protected"}}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with conditional fields", 			input: `page Test at "/test" layout main { 				component form for User { 					field account_type type select options ["personal", "business"] 					when account_type equals "business" { 						field company_name type text required 						field tax_id type text 						button verify_business label "Verify Business" 					} 					when account_type equals "personal" { 						field date_of_birth type date 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "account_type", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Options: []string{"personal", "business"}}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "account_type", 												Operator: "equals", 												Value: "business", 												Fields: []ComponentField{ 													{ 														Name: "company_name", 														Type: "text", 														Attributes: []ComponentFieldAttribute{ 															{Required: true}, 														}, 													}, 													{ 														Name: "tax_id", 														Type: "text", 													}, 												}, 												Buttons: []ComponentButton{ 													{ 														Name: "verify_business", 														Label: "Verify Business", 													}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "account_type", 												Operator: "equals", 												Value: "personal", 												Fields: []ComponentField{ 													{ 														Name: "date_of_birth", 														Type: "date", 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with nested sections", 			input: `page Test at "/test" layout main { 				component dashboard { 					section stats type container class "stats-grid" { 						component metric { 							field total_users type display value "1,234" 							field revenue type display format "currency" value "45,678" 						} 					} 					section charts type container { 						component chart for Analytics { 							data from "analytics/monthly" 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "dashboard", 									Elements: []ComponentElement{ 										{ 											Section: &Section{ 												Name: "stats", 												Type: stringPtr("container"), 												Class: stringPtr("stats-grid"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "metric", 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "total_users", 																		Type: "display", 																		Attributes: []ComponentFieldAttribute{ 																			{Value: stringPtr("1,234")}, 																		}, 																	}, 																}, 																{ 																	Field: &ComponentField{ 																		Name: "revenue", 																		Type: "display", 																		Attributes: []ComponentFieldAttribute{ 																			{Format: stringPtr("currency")}, 																			{Value: stringPtr("45,678")}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											Section: &Section{ 												Name: "charts", 												Type: stringPtr("container"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "chart", 															Entity: stringPtr("Analytics"), 															Elements: []ComponentElement{ 																{ 																	Attribute: &ComponentAttr{ 																		DataSource: stringPtr("analytics/monthly"), 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 	} 	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 !astEqual(got, tt.want) { 				t.Errorf("ParseInput() got = %v, want %v", got, tt.want) 			} 		}) 	} } func TestParseComponentFieldTypes(t *testing.T) { 	fieldTypes := []string{ 		"text", "email", "password", "number", "date", "datetime", "time", 		"textarea", "richtext", "select", "multiselect", "checkbox", "radio", 		"file", "image", "autocomplete", "range", "color", "url", "tel", 		"hidden", "display", "json", "code", 	} 	for _, fieldType := range fieldTypes { 		t.Run("field_type_"+fieldType, func(t *testing.T) { 			input := `page Test at "/test" layout main { 				component form { 					field test_field type ` + fieldType + ` 				} 			}` 			got, err := ParseInput(input) 			if err != nil { 				t.Errorf("ParseInput() failed for field type %s: %v", fieldType, err) 				return 			} 			if len(got.Definitions) != 1 || got.Definitions[0].Page == nil { 				t.Errorf("ParseInput() failed to parse page for field type %s", fieldType) 				return 			} 			page := got.Definitions[0].Page 			if len(page.Components) != 1 || len(page.Components[0].Elements) != 1 { 				t.Errorf("ParseInput() failed to parse component for field type %s", fieldType) 				return 			} 			element := page.Components[0].Elements[0] 			if element.Field == nil || element.Field.Type != fieldType { 				t.Errorf("ParseInput() field type mismatch: got %v, want %s", element.Field, fieldType) 			} 		}) 	} } func TestParseComponentErrors(t *testing.T) { 	tests := []struct { 		name string 		input string 	}{ 		{ 			name: "missing component type", 			input: `page Test at "/test" layout main { 				component 			}`, 		}, 		{ 			name: "invalid field syntax", 			input: `page Test at "/test" layout main { 				component form { 					field name 				} 			}`, 		}, 		{ 			name: "invalid button syntax", 			input: `page Test at "/test" layout main { 				component form { 					button 				} 			}`, 		}, 	} 	for _, tt := range tests { 		t.Run(tt.name, func(t *testing.T) { 			_, err := ParseInput(tt.input) 			if err == nil { 				t.Errorf("ParseInput() expected error for invalid syntax, got nil") 			} 		}) 	} } " />
|
||
<option name="updatedContent" value="package lang import ( 	"testing" ) func TestParseComponentDefinitions(t *testing.T) { 	tests := []struct { 		name string 		input string 		want AST 		wantErr bool 	}{ 		{ 			name: "basic component with entity", 			input: `page Test at "/test" layout main { 				component table for User 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "table", 									Entity: stringPtr("User"), 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "form component with fields", 			input: `page Test at "/test" layout main { 				component form for User { 					field name type text label "Full Name" placeholder "Enter your name" required 					field email type email label "Email Address" required 					field bio type textarea rows 5 placeholder "Tell us about yourself" 					field avatar type file accept "image/*" 					field role type select options ["admin", "user", "guest"] default "user" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "name", 												Type: "text", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Full Name")}, 													{Placeholder: stringPtr("Enter your name")}, 													{Required: true}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "email", 												Type: "email", 												Attributes: []ComponentFieldAttribute{ 													{Label: stringPtr("Email Address")}, 													{Required: true}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "bio", 												Type: "textarea", 												Attributes: []ComponentFieldAttribute{ 													{Rows: intPtr(5)}, 													{Placeholder: stringPtr("Tell us about yourself")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "avatar", 												Type: "file", 												Attributes: []ComponentFieldAttribute{ 													{Accept: stringPtr("image/*")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "role", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Options: []string{"admin", "user", "guest"}}, 													{Default: stringPtr("user")}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with field attributes and validation", 			input: `page Test at "/test" layout main { 				component form for Product { 					field name type text required validate min_length "3" 					field price type number format "currency" validate min "0" 					field category type autocomplete relates to Category 					field tags type multiselect source "tags/popular" 					field description type richtext 					field featured type checkbox default "false" 					field thumbnail type image thumbnail 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("Product"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "name", 												Type: "text", 												Attributes: []ComponentFieldAttribute{ 													{Required: true}, 													{Validation: &ComponentValidation{Type: "min_length", Value: stringPtr("3")}}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "price", 												Type: "number", 												Attributes: []ComponentFieldAttribute{ 													{Format: stringPtr("currency")}, 													{Validation: &ComponentValidation{Type: "min", Value: stringPtr("0")}}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "category", 												Type: "autocomplete", 												Attributes: []ComponentFieldAttribute{ 													{Relates: &FieldRelation{Type: "Category"}}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "tags", 												Type: "multiselect", 												Attributes: []ComponentFieldAttribute{ 													{Source: stringPtr("tags/popular")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "description", 												Type: "richtext", 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "featured", 												Type: "checkbox", 												Attributes: []ComponentFieldAttribute{ 													{Default: stringPtr("false")}, 												}, 											}, 										}, 										{ 											Field: &ComponentField{ 												Name: "thumbnail", 												Type: "image", 												Attributes: []ComponentFieldAttribute{ 													{Thumbnail: true}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with buttons", 			input: `page Test at "/test" layout main { 				component form for User { 					field name type text 					button save label "Save User" style "primary" icon "save" 					button cancel label "Cancel" style "secondary" 					button delete label "Delete" style "danger" confirm "Are you sure?" disabled when is_protected 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "name", 												Type: "text", 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "save", 												Label: "Save User", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "primary"}}, 													{Icon: &ComponentButtonIcon{Value: "save"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "cancel", 												Label: "Cancel", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "secondary"}}, 												}, 											}, 										}, 										{ 											Button: &ComponentButton{ 												Name: "delete", 												Label: "Delete", 												Attributes: []ComponentButtonAttr{ 													{Style: &ComponentButtonStyle{Value: "danger"}}, 													{Confirm: &ComponentButtonConfirm{Value: "Are you sure?"}}, 													{Disabled: &ComponentButtonDisabled{Value: "is_protected"}}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with conditional fields", 			input: `page Test at "/test" layout main { 				component form for User { 					field account_type type select options ["personal", "business"] 					when account_type equals "business" { 						field company_name type text required 						field tax_id type text 						button verify_business label "Verify Business" 					} 					when account_type equals "personal" { 						field date_of_birth type date 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "form", 									Entity: stringPtr("User"), 									Elements: []ComponentElement{ 										{ 											Field: &ComponentField{ 												Name: "account_type", 												Type: "select", 												Attributes: []ComponentFieldAttribute{ 													{Options: []string{"personal", "business"}}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "account_type", 												Operator: "equals", 												Value: "business", 												Fields: []ComponentField{ 													{ 														Name: "company_name", 														Type: "text", 														Attributes: []ComponentFieldAttribute{ 															{Required: true}, 														}, 													}, 													{ 														Name: "tax_id", 														Type: "text", 													}, 												}, 												Buttons: []ComponentButton{ 													{ 														Name: "verify_business", 														Label: "Verify Business", 													}, 												}, 											}, 										}, 										{ 											When: &WhenCondition{ 												Field: "account_type", 												Operator: "equals", 												Value: "personal", 												Fields: []ComponentField{ 													{ 														Name: "date_of_birth", 														Type: "date", 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "component with nested sections", 			input: `page Test at "/test" layout main { 				component dashboard { 					section stats type container class "stats-grid" { 						component metric { 							field total_users type display value "1,234" 							field revenue type display format "currency" value "45,678" 						} 					} 					section charts type container { 						component chart for Analytics { 							data from "analytics/monthly" 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Components: []Component{ 								{ 									Type: "dashboard", 									Elements: []ComponentElement{ 										{ 											Section: &Section{ 												Name: "stats", 												Type: stringPtr("container"), 												Class: stringPtr("stats-grid"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "metric", 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "total_users", 																		Type: "display", 																		Attributes: []ComponentFieldAttribute{ 																			{Value: stringPtr("1,234")}, 																		}, 																	}, 																}, 																{ 																	Field: &ComponentField{ 																		Name: "revenue", 																		Type: "display", 																		Attributes: []ComponentFieldAttribute{ 																			{Format: stringPtr("currency")}, 																			{Value: stringPtr("45,678")}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											Section: &Section{ 												Name: "charts", 												Type: stringPtr("container"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "chart", 															Entity: stringPtr("Analytics"), 															Elements: []ComponentElement{ 																{ 																	Attribute: &ComponentAttr{ 																		DataSource: stringPtr("analytics/monthly"), 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 	} 	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 !astEqual(got, tt.want) { 				t.Errorf("ParseInput() got = %v, want %v", got, tt.want) 			} 		}) 	} } func TestParseComponentFieldTypes(t *testing.T) { 	fieldTypes := []string{ 		"text", "email", "password", "number", "date", "datetime", "time", 		"textarea", "richtext", "select", "multiselect", "checkbox", "radio", 		"file", "image", "autocomplete", "range", "color", "url", "tel", 		"hidden", "display", "json", "code", 	} 	for _, fieldType := range fieldTypes { 		t.Run("field_type_"+fieldType, func(t *testing.T) { 			input := `page Test at "/test" layout main { 				component form { 					field test_field type ` + fieldType + ` 				} 			}` 			got, err := ParseInput(input) 			if err != nil { 				t.Errorf("ParseInput() failed for field type %s: %v", fieldType, err) 				return 			} 			if len(got.Definitions) != 1 || got.Definitions[0].Page == nil { 				t.Errorf("ParseInput() failed to parse page for field type %s", fieldType) 				return 			} 			page := got.Definitions[0].Page 			if len(page.Components) != 1 || len(page.Components[0].Elements) != 1 { 				t.Errorf("ParseInput() failed to parse component for field type %s", fieldType) 				return 			} 			element := page.Components[0].Elements[0] 			if element.Field == nil || element.Field.Type != fieldType { 				t.Errorf("ParseInput() field type mismatch: got %v, want %s", element.Field, fieldType) 			} 		}) 	} } func TestParseComponentErrors(t *testing.T) { 	tests := []struct { 		name string 		input string 	}{ 		{ 			name: "missing component type", 			input: `page Test at "/test" layout main { 				component 			}`, 		}, 		{ 			name: "invalid field syntax", 			input: `page Test at "/test" layout main { 				component form { 					field name 				} 			}`, 		}, 		{ 			name: "invalid button syntax", 			input: `page Test at "/test" layout main { 				component form { 					button 				} 			}`, 		}, 	} 	for _, tt := range tests { 		t.Run(tt.name, func(t *testing.T) { 			_, err := ParseInput(tt.input) 			if err == nil { 				t.Errorf("ParseInput() expected error for invalid syntax, got nil") 			} 		}) 	} }" />
|
||
</PendingDiffInfo>
|
||
</value>
|
||
</entry>
|
||
<entry key="$PROJECT_DIR$/lang/parser_ui_page_test.go">
|
||
<value>
|
||
<PendingDiffInfo>
|
||
<option name="filePath" value="$PROJECT_DIR$/lang/parser_ui_page_test.go" />
|
||
<option name="originalContent" value="package lang import ( 	"testing" ) func TestParsePageDefinitions(t *testing.T) { 	tests := []struct { 		name string 		input string 		want AST 		wantErr bool 	}{ 		{ 			name: "basic page with minimal fields", 			input: `page Dashboard at "/dashboard" layout main`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Dashboard", 							Path: "/dashboard", 							Layout: "main", 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with all optional fields", 			input: `page UserProfile at "/profile" layout main title "User Profile" desc "Manage user profile settings" auth`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "UserProfile", 							Path: "/profile", 							Layout: "main", 							Title: stringPtr("User Profile"), 							Description: stringPtr("Manage user profile settings"), 							Auth: true, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with meta tags", 			input: `page HomePage at "/" layout main { 				meta description "Welcome to our application" 				meta keywords "app, dashboard, management" 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "HomePage", 							Path: "/", 							Layout: "main", 							Meta: []MetaTag{ 								{Name: "description", Content: "Welcome to our application"}, 								{Name: "keywords", Content: "app, dashboard, management"}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with sections and components", 			input: `page UserManagement at "/users" layout admin auth { 				section header type container { 					component form for User { 						field name type text required 						field email type email required 					} 				} 				 				section content type container { 					component table for User { 						data from "users" 						fields ["name", "email", "created_at"] 						actions ["edit", "delete"] 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "UserManagement", 							Path: "/users", 							Layout: "admin", 							Auth: true, 							Sections: []Section{ 								{ 									Name: "header", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "form", 												Entity: stringPtr("User"), 												Elements: []ComponentElement{ 													{ 														Field: &ComponentField{ 															Name: "name", 															Type: "text", 															Attributes: []ComponentFieldAttribute{ 																{Required: true}, 															}, 														}, 													}, 													{ 														Field: &ComponentField{ 															Name: "email", 															Type: "email", 															Attributes: []ComponentFieldAttribute{ 																{Required: true}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 								{ 									Name: "content", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "table", 												Entity: stringPtr("User"), 												Elements: []ComponentElement{ 													{ 														Attribute: &ComponentAttr{ 															DataSource: stringPtr("users"), 															Fields: []string{"name", "email", "created_at"}, 															Actions: []string{"edit", "delete"}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with nested sections", 			input: `page Settings at "/settings" layout main { 				section tabs type tab { 					section profile label "Profile" active { 						component form for User { 							field name type text 						} 					} 					 					section security label "Security" { 						component form for User { 							field password type password 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Settings", 							Path: "/settings", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "tabs", 									Type: stringPtr("tab"), 									Elements: []SectionElement{ 										{ 											Section: &Section{ 												Name: "profile", 												Label: stringPtr("Profile"), 												Active: true, 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "form", 															Entity: stringPtr("User"), 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "name", 																		Type: "text", 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											Section: &Section{ 												Name: "security", 												Label: stringPtr("Security"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "form", 															Entity: stringPtr("User"), 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "password", 																		Type: "password", 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with modal and panel sections", 			input: `page ProductList at "/products" layout main { 				section main type container { 					component table for Product 				} 				 				section editModal type modal trigger "edit-product" { 					component form for Product { 						field name type text required 						button save label "Save Changes" style "primary" 					} 				} 				 				section filters type panel position "left" { 					component form { 						field category type select 						field price_range type range 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "ProductList", 							Path: "/products", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "main", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "table", 												Entity: stringPtr("Product"), 											}, 										}, 									}, 								}, 								{ 									Name: "editModal", 									Type: stringPtr("modal"), 									Trigger: stringPtr("edit-product"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "form", 												Entity: stringPtr("Product"), 												Elements: []ComponentElement{ 													{ 														Field: &ComponentField{ 															Name: "name", 															Type: "text", 															Attributes: []ComponentFieldAttribute{ 																{Required: true}, 															}, 														}, 													}, 													{ 														Button: &ComponentButton{ 															Name: "save", 															Label: "Save Changes", 															Attributes: []ComponentButtonAttr{ 																{Style: &ComponentButtonStyle{Value: "primary"}}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 								{ 									Name: "filters", 									Type: stringPtr("panel"), 									Position: stringPtr("left"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "form", 												Elements: []ComponentElement{ 													{ 														Field: &ComponentField{ 															Name: "category", 															Type: "select", 														}, 													}, 													{ 														Field: &ComponentField{ 															Name: "price_range", 															Type: "range", 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 	} 	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 !astEqual(got, tt.want) { 				t.Errorf("ParseInput() got = %v, want %v", got, tt.want) 			} 		}) 	} } func TestParsePageErrors(t *testing.T) { 	tests := []struct { 		name string 		input string 	}{ 		{ 			name: "missing layout", 			input: `page Dashboard at "/dashboard"`, 		}, 		{ 			name: "missing path", 			input: `page Dashboard layout main`, 		}, 		{ 			name: "invalid path format", 			input: `page Dashboard at dashboard layout main`, 		}, 	} 	for _, tt := range tests { 		t.Run(tt.name, func(t *testing.T) { 			_, err := ParseInput(tt.input) 			if err == nil { 				t.Errorf("ParseInput() expected error for invalid syntax, got nil") 			} 		}) 	} } " />
|
||
<option name="updatedContent" value="package lang import ( 	"testing" ) func TestParsePageDefinitions(t *testing.T) { 	tests := []struct { 		name string 		input string 		want AST 		wantErr bool 	}{ 		{ 			name: "basic page with minimal fields", 			input: `page Dashboard at "/dashboard" layout main`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Dashboard", 							Path: "/dashboard", 							Layout: "main", 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with all optional fields", 			input: `page UserProfile at "/profile" layout main title "User Profile" desc "Manage user profile settings" auth`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "UserProfile", 							Path: "/profile", 							Layout: "main", 							Title: stringPtr("User Profile"), 							Description: stringPtr("Manage user profile settings"), 							Auth: true, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with meta tags", 			input: `page HomePage at "/" layout main { 				meta description "Welcome to our application" 				meta keywords "app, dashboard, management" 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "HomePage", 							Path: "/", 							Layout: "main", 							Meta: []MetaTag{ 								{Name: "description", Content: "Welcome to our application"}, 								{Name: "keywords", Content: "app, dashboard, management"}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with nested sections", 			input: `page Settings at "/settings" layout main { 				section tabs type tab { 					section profile label "Profile" active { 						component form for User { 							field name type text 						} 					} 					 					section security label "Security" { 						component form for User { 							field password type password 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Settings", 							Path: "/settings", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "tabs", 									Type: stringPtr("tab"), 									Elements: []SectionElement{ 										{ 											Section: &Section{ 												Name: "profile", 												Label: stringPtr("Profile"), 												Active: true, 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "form", 															Entity: stringPtr("User"), 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "name", 																		Type: "text", 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											Section: &Section{ 												Name: "security", 												Label: stringPtr("Security"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "form", 															Entity: stringPtr("User"), 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "password", 																		Type: "password", 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "page with modal and panel sections", 			input: `page ProductList at "/products" layout main { 				section main type container { 					component table for Product 				} 				 				section editModal type modal trigger "edit-product" { 					component form for Product { 						field name type text required 						button save label "Save Changes" style "primary" 					} 				} 				 				section filters type panel position "left" { 					component form { 						field category type select 						field price_range type range 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "ProductList", 							Path: "/products", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "main", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "table", 												Entity: stringPtr("Product"), 											}, 										}, 									}, 								}, 								{ 									Name: "editModal", 									Type: stringPtr("modal"), 									Trigger: stringPtr("edit-product"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "form", 												Entity: stringPtr("Product"), 												Elements: []ComponentElement{ 													{ 														Field: &ComponentField{ 															Name: "name", 															Type: "text", 															Attributes: []ComponentFieldAttribute{ 																{Required: true}, 															}, 														}, 													}, 													{ 														Button: &ComponentButton{ 															Name: "save", 															Label: "Save Changes", 															Attributes: []ComponentButtonAttr{ 																{Style: &ComponentButtonStyle{Value: "primary"}}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 								{ 									Name: "filters", 									Type: stringPtr("panel"), 									Position: stringPtr("left"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "form", 												Elements: []ComponentElement{ 													{ 														Field: &ComponentField{ 															Name: "category", 															Type: "select", 														}, 													}, 													{ 														Field: &ComponentField{ 															Name: "price_range", 															Type: "range", 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 	} 	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 !astEqual(got, tt.want) { 				t.Errorf("ParseInput() got = %v, want %v", got, tt.want) 			} 		}) 	} } func TestParsePageErrors(t *testing.T) { 	tests := []struct { 		name string 		input string 	}{ 		{ 			name: "missing layout", 			input: `page Dashboard at "/dashboard"`, 		}, 		{ 			name: "missing path", 			input: `page Dashboard layout main`, 		}, 		{ 			name: "invalid path format", 			input: `page Dashboard at dashboard layout main`, 		}, 	} 	for _, tt := range tests { 		t.Run(tt.name, func(t *testing.T) { 			_, err := ParseInput(tt.input) 			if err == nil { 				t.Errorf("ParseInput() expected error for invalid syntax, got nil") 			} 		}) 	} }" />
|
||
</PendingDiffInfo>
|
||
</value>
|
||
</entry>
|
||
<entry key="$PROJECT_DIR$/lang/parser_ui_section_test.go">
|
||
<value>
|
||
<PendingDiffInfo>
|
||
<option name="filePath" value="$PROJECT_DIR$/lang/parser_ui_section_test.go" />
|
||
<option name="originalContent" value="package lang import ( 	"testing" ) func TestParseSectionDefinitions(t *testing.T) { 	tests := []struct { 		name string 		input string 		want AST 		wantErr bool 	}{ 		{ 			name: "basic container section", 			input: `page Test at "/test" layout main { 				section main type container 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "main", 									Type: stringPtr("container"), 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "section with all attributes", 			input: `page Test at "/test" layout main { 				section sidebar type panel position "left" class "sidebar-nav" label "Navigation" trigger "toggle-sidebar" for User 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "sidebar", 									Type: stringPtr("panel"), 									Position: stringPtr("left"), 									Class: stringPtr("sidebar-nav"), 									Label: stringPtr("Navigation"), 									Trigger: stringPtr("toggle-sidebar"), 									Entity: stringPtr("User"), 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "tab sections with active state", 			input: `page Test at "/test" layout main { 				section tabs type tab { 					section overview label "Overview" active 					section details label "Details" 					section settings label "Settings" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "tabs", 									Type: stringPtr("tab"), 									Elements: []SectionElement{ 										{ 											Section: &Section{ 												Name: "overview", 												Label: stringPtr("Overview"), 												Active: true, 											}, 										}, 										{ 											Section: &Section{ 												Name: "details", 												Label: stringPtr("Details"), 											}, 										}, 										{ 											Section: &Section{ 												Name: "settings", 												Label: stringPtr("Settings"), 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "modal section with content", 			input: `page Test at "/test" layout main { 				section userModal type modal trigger "edit-user" { 					component form for User { 						field name type text required 						field email type email required 						button save label "Save Changes" style "primary" 						button cancel label "Cancel" style "secondary" 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "userModal", 									Type: stringPtr("modal"), 									Trigger: stringPtr("edit-user"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "form", 												Entity: stringPtr("User"), 												Elements: []ComponentElement{ 													{ 														Field: &ComponentField{ 															Name: "name", 															Type: "text", 															Attributes: []ComponentFieldAttribute{ 																{Required: true}, 															}, 														}, 													}, 													{ 														Field: &ComponentField{ 															Name: "email", 															Type: "email", 															Attributes: []ComponentFieldAttribute{ 																{Required: true}, 															}, 														}, 													}, 													{ 														Button: &ComponentButton{ 															Name: "save", 															Label: "Save Changes", 															Attributes: []ComponentButtonAttr{ 																{Style: &ComponentButtonStyle{Value: "primary"}}, 															}, 														}, 													}, 													{ 														Button: &ComponentButton{ 															Name: "cancel", 															Label: "Cancel", 															Attributes: []ComponentButtonAttr{ 																{Style: &ComponentButtonStyle{Value: "secondary"}}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "master-detail sections", 			input: `page Test at "/test" layout main { 				section masterDetail type master { 					section userList type container { 						component table for User { 							fields ["name", "email"] 						} 					} 					 					section userDetail type detail trigger "user-selected" for User { 						component form for User { 							field name type text 							field email type email 							field bio type textarea 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "masterDetail", 									Type: stringPtr("master"), 									Elements: []SectionElement{ 										{ 											Section: &Section{ 												Name: "userList", 												Type: stringPtr("container"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "table", 															Entity: stringPtr("User"), 															Elements: []ComponentElement{ 																{ 																	Attribute: &ComponentAttr{ 																		Fields: []string{"name", "email"}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											Section: &Section{ 												Name: "userDetail", 												Type: stringPtr("detail"), 												Trigger: stringPtr("user-selected"), 												Entity: stringPtr("User"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "form", 															Entity: stringPtr("User"), 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "name", 																		Type: "text", 																	}, 																}, 																{ 																	Field: &ComponentField{ 																		Name: "email", 																		Type: "email", 																	}, 																}, 																{ 																	Field: &ComponentField{ 																		Name: "bio", 																		Type: "textarea", 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "section with attributes and nested components", 			input: `page Test at "/test" layout main { 				section dashboard type container { 					data from "dashboard/stats" 					style "dashboard-grid" 					classes "bg-gray-100 p-4" 					size 12 					theme "dark" 					 					component metric { 						field users type display 					} 					component chart for Analytics 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "dashboard", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											Attribute: &SectionAttribute{ 												DataSource: stringPtr("dashboard/stats"), 												Style: stringPtr("dashboard-grid"), 												Classes: stringPtr("bg-gray-100 p-4"), 												Size: intPtr(12), 												Theme: stringPtr("dark"), 											}, 										}, 										{ 											Component: &Component{ 												Type: "metric", 												Elements: []ComponentElement{ 													{ 														Field: &ComponentField{ 															Name: "users", 															Type: "display", 														}, 													}, 												}, 											}, 										}, 										{ 											Component: &Component{ 												Type: "chart", 												Entity: stringPtr("Analytics"), 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "deeply nested sections", 			input: `page Test at "/test" layout main { 				section mainLayout type container { 					section header type container class "header" { 						component navbar { 							field search type text placeholder "Search..." 						} 					} 					 					section content type container { 						section sidebar type panel position "left" { 							component menu { 								field navigation type list 							} 						} 						 						section main type container { 							section tabs type tab { 								section overview label "Overview" active { 									component dashboard { 										field stats type metric 									} 								} 								 								section reports label "Reports" { 									component table for Report 								} 							} 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "mainLayout", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											Section: &Section{ 												Name: "header", 												Type: stringPtr("container"), 												Class: stringPtr("header"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "navbar", 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "search", 																		Type: "text", 																		Attributes: []ComponentFieldAttribute{ 																			{Placeholder: stringPtr("Search...")}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											Section: &Section{ 												Name: "content", 												Type: stringPtr("container"), 												Elements: []SectionElement{ 													{ 														Section: &Section{ 															Name: "sidebar", 															Type: stringPtr("panel"), 															Position: stringPtr("left"), 															Elements: []SectionElement{ 																{ 																	Component: &Component{ 																		Type: "menu", 																		Elements: []ComponentElement{ 																			{ 																				Field: &ComponentField{ 																					Name: "navigation", 																					Type: "list", 																				}, 																			}, 																		}, 																	}, 																}, 															}, 														}, 													}, 													{ 														Section: &Section{ 															Name: "main", 															Type: stringPtr("container"), 															Elements: []SectionElement{ 																{ 																	Section: &Section{ 																		Name: "tabs", 																		Type: stringPtr("tab"), 																		Elements: []SectionElement{ 																			{ 																				Section: &Section{ 																					Name: "overview", 																					Label: stringPtr("Overview"), 																					Active: true, 																					Elements: []SectionElement{ 																						{ 																							Component: &Component{ 																								Type: "dashboard", 																								Elements: []ComponentElement{ 																									{ 																										Field: &ComponentField{ 																											Name: "stats", 																											Type: "metric", 																										}, 																									}, 																								}, 																							}, 																						}, 																					}, 																				}, 																			}, 																			{ 																				Section: &Section{ 																					Name: "reports", 																					Label: stringPtr("Reports"), 																					Elements: []SectionElement{ 																						{ 																							Component: &Component{ 																								Type: "table", 																								Entity: stringPtr("Report"), 																							}, 																						}, 																					}, 																				}, 																			}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "section with conditional content", 			input: `page Test at "/test" layout main { 				section adminPanel type container { 					when user_role equals "admin" { 						section userManagement type container { 							component table for User 						} 						section systemSettings type container { 							component form for Settings 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "adminPanel", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											When: &WhenCondition{ 												Field: "user_role", 												Operator: "equals", 												Value: "admin", 												Sections: []Section{ 													{ 														Name: "userManagement", 														Type: stringPtr("container"), 														Elements: []SectionElement{ 															{ 																Component: &Component{ 																	Type: "table", 																	Entity: stringPtr("User"), 																}, 															}, 														}, 													}, 													{ 														Name: "systemSettings", 														Type: stringPtr("container"), 														Elements: []SectionElement{ 															{ 																Component: &Component{ 																	Type: "form", 																	Entity: stringPtr("Settings"), 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 	} 	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 !astEqual(got, tt.want) { 				t.Errorf("ParseInput() got = %v, want %v", got, tt.want) 			} 		}) 	} } func TestParseSectionTypes(t *testing.T) { 	sectionTypes := []string{ 		"container", "tab", "panel", "modal", "master", "detail", 	} 	for _, sectionType := range sectionTypes { 		t.Run("section_type_"+sectionType, func(t *testing.T) { 			input := `page Test at "/test" layout main { 				section test_section type ` + sectionType + ` 			}` 			got, err := ParseInput(input) 			if err != nil { 				t.Errorf("ParseInput() failed for section type %s: %v", sectionType, err) 				return 			} 			if len(got.Definitions) != 1 || got.Definitions[0].Page == nil { 				t.Errorf("ParseInput() failed to parse page for section type %s", sectionType) 				return 			} 			page := got.Definitions[0].Page 			if len(page.Sections) != 1 { 				t.Errorf("ParseInput() failed to parse section for type %s", sectionType) 				return 			} 			section := page.Sections[0] 			if section.Type == nil || *section.Type != sectionType { 				t.Errorf("ParseInput() section type mismatch: got %v, want %s", section.Type, sectionType) 			} 		}) 	} } func TestParseSectionErrors(t *testing.T) { 	tests := []struct { 		name string 		input string 	}{ 		{ 			name: "missing section name", 			input: `page Test at "/test" layout main { 				section type container 			}`, 		}, 		{ 			name: "invalid section type", 			input: `page Test at "/test" layout main { 				section test type invalid_type 			}`, 		}, 		{ 			name: "unclosed section block", 			input: `page Test at "/test" layout main { 				section test type container { 					component form 			}`, 		}, 	} 	for _, tt := range tests { 		t.Run(tt.name, func(t *testing.T) { 			_, err := ParseInput(tt.input) 			if err == nil { 				t.Errorf("ParseInput() expected error for invalid syntax, got nil") 			} 		}) 	} } " />
|
||
<option name="updatedContent" value="package lang import ( 	"testing" ) func TestParseSectionDefinitions(t *testing.T) { 	tests := []struct { 		name string 		input string 		want AST 		wantErr bool 	}{ 		{ 			name: "basic container section", 			input: `page Test at "/test" layout main { 				section main type container 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "main", 									Type: stringPtr("container"), 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "section with all attributes", 			input: `page Test at "/test" layout main { 				section sidebar type panel class "sidebar-nav" label "Navigation" trigger "toggle-sidebar" position "left" for User 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "sidebar", 									Type: stringPtr("panel"), 									Position: stringPtr("left"), 									Class: stringPtr("sidebar-nav"), 									Label: stringPtr("Navigation"), 									Trigger: stringPtr("toggle-sidebar"), 									Entity: stringPtr("User"), 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "tab sections with active state", 			input: `page Test at "/test" layout main { 				section tabs type tab { 					section overview label "Overview" active 					section details label "Details" 					section settings label "Settings" 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "tabs", 									Type: stringPtr("tab"), 									Elements: []SectionElement{ 										{ 											Section: &Section{ 												Name: "overview", 												Label: stringPtr("Overview"), 												Active: true, 											}, 										}, 										{ 											Section: &Section{ 												Name: "details", 												Label: stringPtr("Details"), 											}, 										}, 										{ 											Section: &Section{ 												Name: "settings", 												Label: stringPtr("Settings"), 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "modal section with content", 			input: `page Test at "/test" layout main { 				section userModal type modal trigger "edit-user" { 					component form for User { 						field name type text required 						field email type email required 						button save label "Save Changes" style "primary" 						button cancel label "Cancel" style "secondary" 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "userModal", 									Type: stringPtr("modal"), 									Trigger: stringPtr("edit-user"), 									Elements: []SectionElement{ 										{ 											Component: &Component{ 												Type: "form", 												Entity: stringPtr("User"), 												Elements: []ComponentElement{ 													{ 														Field: &ComponentField{ 															Name: "name", 															Type: "text", 															Attributes: []ComponentFieldAttribute{ 																{Required: true}, 															}, 														}, 													}, 													{ 														Field: &ComponentField{ 															Name: "email", 															Type: "email", 															Attributes: []ComponentFieldAttribute{ 																{Required: true}, 															}, 														}, 													}, 													{ 														Button: &ComponentButton{ 															Name: "save", 															Label: "Save Changes", 															Attributes: []ComponentButtonAttr{ 																{Style: &ComponentButtonStyle{Value: "primary"}}, 															}, 														}, 													}, 													{ 														Button: &ComponentButton{ 															Name: "cancel", 															Label: "Cancel", 															Attributes: []ComponentButtonAttr{ 																{Style: &ComponentButtonStyle{Value: "secondary"}}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "master-detail sections", 			input: `page Test at "/test" layout main { 				section masterDetail type master { 					section userList type container { 						component table for User { 							fields [name, email] 						} 					} 					 					section userDetail type detail trigger "user-selected" for User { 						component form for User { 							field name type text 							field email type email 							field bio type textarea 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "masterDetail", 									Type: stringPtr("master"), 									Elements: []SectionElement{ 										{ 											Section: &Section{ 												Name: "userList", 												Type: stringPtr("container"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "table", 															Entity: stringPtr("User"), 															Elements: []ComponentElement{ 																{ 																	Attribute: &ComponentAttr{ 																		Fields: []string{"name", "email"}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											Section: &Section{ 												Name: "userDetail", 												Type: stringPtr("detail"), 												Trigger: stringPtr("user-selected"), 												Entity: stringPtr("User"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "form", 															Entity: stringPtr("User"), 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "name", 																		Type: "text", 																	}, 																}, 																{ 																	Field: &ComponentField{ 																		Name: "email", 																		Type: "email", 																	}, 																}, 																{ 																	Field: &ComponentField{ 																		Name: "bio", 																		Type: "textarea", 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "deeply nested sections", 			input: `page Test at "/test" layout main { 				section mainLayout type container { 					section header type container class "header" { 						component navbar { 							field search type text placeholder "Search..." 						} 					} 					 					section content type container { 						section sidebar type panel position "left" { 							component menu { 								field navigation type list 							} 						} 						 						section main type container { 							section tabs type tab { 								section overview label "Overview" active { 									component dashboard { 										field stats type metric 									} 								} 								 								section reports label "Reports" { 									component table for Report 								} 							} 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "mainLayout", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											Section: &Section{ 												Name: "header", 												Type: stringPtr("container"), 												Class: stringPtr("header"), 												Elements: []SectionElement{ 													{ 														Component: &Component{ 															Type: "navbar", 															Elements: []ComponentElement{ 																{ 																	Field: &ComponentField{ 																		Name: "search", 																		Type: "text", 																		Attributes: []ComponentFieldAttribute{ 																			{Placeholder: stringPtr("Search...")}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 										{ 											Section: &Section{ 												Name: "content", 												Type: stringPtr("container"), 												Elements: []SectionElement{ 													{ 														Section: &Section{ 															Name: "sidebar", 															Type: stringPtr("panel"), 															Position: stringPtr("left"), 															Elements: []SectionElement{ 																{ 																	Component: &Component{ 																		Type: "menu", 																		Elements: []ComponentElement{ 																			{ 																				Field: &ComponentField{ 																					Name: "navigation", 																					Type: "list", 																				}, 																			}, 																		}, 																	}, 																}, 															}, 														}, 													}, 													{ 														Section: &Section{ 															Name: "main", 															Type: stringPtr("container"), 															Elements: []SectionElement{ 																{ 																	Section: &Section{ 																		Name: "tabs", 																		Type: stringPtr("tab"), 																		Elements: []SectionElement{ 																			{ 																				Section: &Section{ 																					Name: "overview", 																					Label: stringPtr("Overview"), 																					Active: true, 																					Elements: []SectionElement{ 																						{ 																							Component: &Component{ 																								Type: "dashboard", 																								Elements: []ComponentElement{ 																									{ 																										Field: &ComponentField{ 																											Name: "stats", 																											Type: "metric", 																										}, 																									}, 																								}, 																							}, 																						}, 																					}, 																				}, 																			}, 																			{ 																				Section: &Section{ 																					Name: "reports", 																					Label: stringPtr("Reports"), 																					Elements: []SectionElement{ 																						{ 																							Component: &Component{ 																								Type: "table", 																								Entity: stringPtr("Report"), 																							}, 																						}, 																					}, 																				}, 																			}, 																		}, 																	}, 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 		{ 			name: "section with conditional content", 			input: `page Test at "/test" layout main { 				section adminPanel type container { 					when user_role equals "admin" { 						section userManagement type container { 							component table for User 						} 						section systemSettings type container { 							component form for Settings 						} 					} 				} 			}`, 			want: AST{ 				Definitions: []Definition{ 					{ 						Page: &Page{ 							Name: "Test", 							Path: "/test", 							Layout: "main", 							Sections: []Section{ 								{ 									Name: "adminPanel", 									Type: stringPtr("container"), 									Elements: []SectionElement{ 										{ 											When: &WhenCondition{ 												Field: "user_role", 												Operator: "equals", 												Value: "admin", 												Sections: []Section{ 													{ 														Name: "userManagement", 														Type: stringPtr("container"), 														Elements: []SectionElement{ 															{ 																Component: &Component{ 																	Type: "table", 																	Entity: stringPtr("User"), 																}, 															}, 														}, 													}, 													{ 														Name: "systemSettings", 														Type: stringPtr("container"), 														Elements: []SectionElement{ 															{ 																Component: &Component{ 																	Type: "form", 																	Entity: stringPtr("Settings"), 																}, 															}, 														}, 													}, 												}, 											}, 										}, 									}, 								}, 							}, 						}, 					}, 				}, 			}, 		}, 	} 	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 !astEqual(got, tt.want) { 				t.Errorf("ParseInput() got = %v, want %v", got, tt.want) 			} 		}) 	} } func TestParseSectionTypes(t *testing.T) { 	sectionTypes := []string{ 		"container", "tab", "panel", "modal", "master", "detail", 	} 	for _, sectionType := range sectionTypes { 		t.Run("section_type_"+sectionType, func(t *testing.T) { 			input := `page Test at "/test" layout main { 				section test_section type ` + sectionType + ` 			}` 			got, err := ParseInput(input) 			if err != nil { 				t.Errorf("ParseInput() failed for section type %s: %v", sectionType, err) 				return 			} 			if len(got.Definitions) != 1 || got.Definitions[0].Page == nil { 				t.Errorf("ParseInput() failed to parse page for section type %s", sectionType) 				return 			} 			page := got.Definitions[0].Page 			if len(page.Sections) != 1 { 				t.Errorf("ParseInput() failed to parse section for type %s", sectionType) 				return 			} 			section := page.Sections[0] 			if section.Type == nil || *section.Type != sectionType { 				t.Errorf("ParseInput() section type mismatch: got %v, want %s", section.Type, sectionType) 			} 		}) 	} } func TestParseSectionErrors(t *testing.T) { 	tests := []struct { 		name string 		input string 	}{ 		{ 			name: "missing section name", 			input: `page Test at "/test" layout main { 				section type container 			}`, 		}, 		{ 			name: "invalid section type", 			input: `page Test at "/test" layout main { 				section test type invalid_type 			}`, 		}, 		{ 			name: "unclosed section block", 			input: `page Test at "/test" layout main { 				section test type container { 					component form 			}`, 		}, 	} 	for _, tt := range tests { 		t.Run(tt.name, func(t *testing.T) { 			_, err := ParseInput(tt.input) 			if err == nil { 				t.Errorf("ParseInput() expected error for invalid syntax, got nil") 			} 		}) 	} }" />
|
||
</PendingDiffInfo>
|
||
</value>
|
||
</entry>
|
||
<entry key="$PROJECT_DIR$/lang/simplified_lang.go">
|
||
<value>
|
||
<PendingDiffInfo>
|
||
<option name="filePath" value="$PROJECT_DIR$/lang/simplified_lang.go" />
|
||
<option name="updatedContent" value="package lang // Simplified DSL structure proposal // This reduces complexity while maintaining power and flexibility import ( 	"github.com/alecthomas/participle/v2" ) // Root AST node containing all definitions type SimplifiedAST struct { 	Definitions []Definition `parser:"@@*"` } // Enhanced Page definitions with unified section model type SimplifiedPage struct { 	Name string `parser:"'page' @Ident"` 	Path string `parser:"'at' @String"` 	Layout string `parser:"'layout' @Ident"` 	Title *string `parser:"('title' @String)?"` 	Description *string `parser:"('desc' @String)?"` 	Auth bool `parser:"@'auth'?"` 	Meta []MetaTag `parser:"@@*"` 	Sections []Section `parser:"@@*"` // Unified sections 	Components []Component `parser:"@@*"` // Direct components } // Unified Section type that replaces Container, Tab, Panel, Modal, MasterDetail type Section struct { 	Name string `parser:"'section' @Ident"` 	Type *string `parser:"('type' @('container' | 'tab' | 'panel' | 'modal' | 'master' | 'detail'))?"` 	Class *string `parser:"('class' @String)?"` 	Label *string `parser:"('label' @String)?"` // for tabs 	Active bool `parser:"@'active'?"` // for tabs 	Trigger *string `parser:"('trigger' @String)?"` // for panels/modals/detail 	Position *string `parser:"('position' @String)?"` // for panels 	Entity *string `parser:"('for' @Ident)?"` // for panels 	Attributes []SectionAttribute `parser:"@@*"` // Flexible attributes 	Components []Component `parser:"@@*"` 	Sections []Section `parser:"@@*"` // Recursive support 	When []WhenCondition `parser:"@@*"` // Conditional sections } // Flexible section attributes (similar to field attributes) type SectionAttribute struct { 	DataSource *string `parser:"('data' 'from' @String)"` 	Style *string `parser:"| ('style' @String)"` 	Classes *string `parser:"| ('classes' @String)"` 	Size *int `parser:"| ('size' @Int)"` // for pagination, etc. 	Theme *string `parser:"| ('theme' @String)"` } // Simplified Component with unified element model type Component struct { 	Type string `parser:"'component' @Ident"` 	Entity *string `parser:"('for' @Ident)?"` 	Attributes []ComponentAttr `parser:"@@*"` // Simplified attributes 	Elements []ComponentElement `parser:"@@*"` } // Simplified component attributes using key-value pattern type ComponentAttr struct { 	DataSource *string `parser:"('data' 'from' @String)"` 	Fields []string `parser:"| ('fields' '[' @Ident (',' @Ident)* ']')"` 	Style *string `parser:"| ('style' @String)"` 	Classes *string `parser:"| ('classes' @String)"` 	PageSize *int `parser:"| ('pagination' 'size' @Int)"` 	Validate bool `parser:"| @'validate'"` } // Enhanced ComponentElement with recursive section support type ComponentElement struct { 	Field *ComponentField `parser:"@@"` 	Section *Section `parser:"| @@"` // Sections can be nested in components 	Button *ComponentButton `parser:"| @@"` 	When *WhenCondition `parser:"| @@"` } // Enhanced WhenCondition with recursive support for both sections and components type WhenCondition struct { 	Field string `parser:"'when' @Ident"` 	Operator string `parser:"@('equals' | 'not_equals' | 'contains')"` 	Value string `parser:"@String"` 	Fields []ComponentField `parser:"@@*"` 	Sections []Section `parser:"@@*"` // Can contain sections 	Components []Component `parser:"@@*"` // Can contain components 	Buttons []ComponentButton `parser:"@@*"` } // Simplified button (renamed from ComponentButtonAttr for clarity) type ComponentButton struct { 	Name string `parser:"'button' @Ident"` 	Label string `parser:"'label' @String"` 	Style *string `parser:"('style' @String)?"` 	Icon *string `parser:"('icon' @String)?"` 	Loading *string `parser:"('loading' @String)?"` 	Disabled *string `parser:"('disabled' 'when' @Ident)?"` 	Confirm *string `parser:"('confirm' @String)?"` 	Target *string `parser:"('target' @Ident)?"` 	Position *string `parser:"('position' @String)?"` 	Via *string `parser:"('via' @String)?"` } // ComponentField remains the same as it's already well-designed type ComponentField struct { 	Name string `parser:"'field' @Ident"` 	Type string `parser:"'type' @Ident"` 	Attributes []ComponentFieldAttribute `parser:"@@*"` } // Example usage with the simplified structure: // // page UserManagement at "/admin/users" layout AdminLayout // section main type container class "grid grid-cols-3 gap-4" // section sidebar class "col-span-1" // component UserStats for User // data from "/users/stats" // // section content class "col-span-2" // component UserTable for User // fields [email, name, role] // data from "/users" // // section editPanel type panel trigger "edit" position "slide-right" for User // component UserForm for User // field email type text required // field name type text required // // page PostManagement at "/posts" layout AdminLayout // section master type master // component PostList for Post // field title type text sortable // data from "/posts" // // section detail type detail trigger "edit" // component PostForm for Post // field title type text required // field content type richtext required // // when status equals "published" // section publishedOptions // field featured type toggle // field priority type number" />
|
||
</PendingDiffInfo>
|
||
</value>
|
||
</entry>
|
||
</map>
|
||
</option>
|
||
</component>
|
||
</project> |