package parser_test import ( "testing" "git.sharkk.net/Sharkk/Mako/parser" ) func TestMultilineStringLiterals(t *testing.T) { tests := []struct { input string expected string desc string }{ {`[[hello world]]`, "hello world", "basic multiline string"}, {`[[]]`, "", "empty multiline string"}, {`[[hello world]]`, "hello\nworld", "multiline with newline"}, {`[[hello [brackets] world]]`, "hello [brackets] world", "nested single brackets"}, {`[[line1 line2 line3]]`, "line1\nline2\nline3", "multiple lines"}, {`[[ tab and spaces ]]`, "\ttab and spaces\t", "tabs and spaces"}, {`[[special chars: @#$%^&*()]]`, "special chars: @#$%^&*()", "special characters"}, {`[["quotes" and 'apostrophes']]`, `"quotes" and 'apostrophes'`, "quotes inside multiline"}, } for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { l := parser.NewLexer(tt.input) p := parser.NewParser(l) expr := p.ParseExpression(parser.LOWEST) checkParserErrors(t, p) testStringLiteral(t, expr, tt.expected) }) } } func TestMultilineStringInTables(t *testing.T) { tests := []struct { input string expected string desc string }{ {`{[[hello]], [[world]]}`, `{"hello", "world"}`, "multiline strings in array"}, {`{msg = [[hello world]]}`, `{msg = "hello world"}`, "multiline string in hash"}, {`{[[key1]], "value1", key2 = [[value2]]}`, `{"key1", "value1", key2 = "value2"}`, "mixed strings in table"}, } for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { l := parser.NewLexer(tt.input) p := parser.NewParser(l) expr := p.ParseExpression(parser.LOWEST) checkParserErrors(t, p) if expr.String() != tt.expected { t.Errorf("expected %s, got %s", tt.expected, expr.String()) } }) } } func TestMixedStringTypes(t *testing.T) { tests := []struct { input string expected string desc string }{ {`"regular" + [[multiline]]`, `("regular" + "multiline")`, "regular + multiline"}, {`{[[key1]] = "value1", "key2" = [[value2]]}`, `{"key1" = "value1", "key2" = "value2"}`, "mixed in table"}, } for _, tt := range tests { t.Run(tt.desc, func(t *testing.T) { l := parser.NewLexer(tt.input) p := parser.NewParser(l) expr := p.ParseExpression(parser.LOWEST) checkParserErrors(t, p) if expr.String() != tt.expected { t.Errorf("expected %s, got %s", tt.expected, expr.String()) } }) } }