diff --git a/go.mod b/go.mod index 3aca6ae2..7c0f7b0a 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.23.3 require ( github.com/PuerkitoBio/goquery v1.10.1 github.com/a-h/htmlformat v0.0.0-20231108124658-5bd994fe268e - github.com/a-h/parse v0.0.0-20240121214402-3caf7543159a + github.com/a-h/parse v0.0.0-20250122154542-74294addb73e github.com/a-h/protocol v0.0.0-20240704131721-1e461c188041 github.com/andybalholm/brotli v1.1.0 github.com/cenkalti/backoff/v4 v4.3.0 diff --git a/go.sum b/go.sum index 39b4fb2a..7778ef2a 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/a-h/htmlformat v0.0.0-20231108124658-5bd994fe268e h1:Eog54DQpku7NpPNf github.com/a-h/htmlformat v0.0.0-20231108124658-5bd994fe268e/go.mod h1:FMIm5afKmEfarNbIXOaPHFY8X7fo+fRQB6I9MPG2nB0= github.com/a-h/parse v0.0.0-20240121214402-3caf7543159a h1:vlmAfVwFK9sRpDlJyuHY8htP+KfGHB2VH02u0SoIufk= github.com/a-h/parse v0.0.0-20240121214402-3caf7543159a/go.mod h1:3mnrkvGpurZ4ZrTDbYU84xhwXW2TjTKShSwjRi2ihfQ= +github.com/a-h/parse v0.0.0-20250122154542-74294addb73e h1:HjVbSQHy+dnlS6C3XajZ69NYAb5jbGNfHanvm1+iYlo= +github.com/a-h/parse v0.0.0-20250122154542-74294addb73e/go.mod h1:3mnrkvGpurZ4ZrTDbYU84xhwXW2TjTKShSwjRi2ihfQ= github.com/a-h/protocol v0.0.0-20240704131721-1e461c188041 h1:2enlC41iOwWklx9ZUqpQygsNAG6KIm3uMMUXzBJw5jA= github.com/a-h/protocol v0.0.0-20240704131721-1e461c188041/go.mod h1:Gm0KywveHnkiIhqFSMZglXwWZRQICg3KDWLYdglv/d8= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= diff --git a/parser/v2/ifexpressionparser_test.go b/parser/v2/ifexpressionparser_test.go index d80300e4..a7ecd6e8 100644 --- a/parser/v2/ifexpressionparser_test.go +++ b/parser/v2/ifexpressionparser_test.go @@ -622,9 +622,19 @@ func TestIncompleteIf(t *testing.T) { t.Run("no opening brace", func(t *testing.T) { input := parse.NewInput(`if a tree falls in the woods`) _, _, err := ifExpression.Parse(input) - if err.Error() != "if: unterminated (missing closing '{\\n') - https://templ.guide/syntax-and-usage/statements#incomplete-statements: line 0, col 0" { + if err == nil { + t.Fatal("expected an error, got nil") + } + pe, isParseError := err.(parse.ParseError) + if !isParseError { + t.Fatalf("expected a parse error, got %T", err) + } + if pe.Msg != "if: unterminated (missing closing '{\\n') - https://templ.guide/syntax-and-usage/statements#incomplete-statements" { t.Fatalf("unexpected error: %v", err) } + if pe.Pos.Line != 0 { + t.Fatalf("unexpected line: %d", pe.Pos.Line) + } }) t.Run("capitalised If", func(t *testing.T) { input := parse.NewInput(`If a tree falls in the woods`) diff --git a/parser/v2/switchexpressionparser_test.go b/parser/v2/switchexpressionparser_test.go index e17cae71..376d7bab 100644 --- a/parser/v2/switchexpressionparser_test.go +++ b/parser/v2/switchexpressionparser_test.go @@ -322,8 +322,18 @@ func TestIncompleteSwitch(t *testing.T) { t.Run("no opening brace", func(t *testing.T) { input := parse.NewInput(`switch with no brace`) _, _, err := switchExpression.Parse(input) - if err.Error() != "switch: unterminated (missing closing '{\\n') - https://templ.guide/syntax-and-usage/statements#incomplete-statements: line 0, col 0" { - t.Fatalf("unexpected error: %v", err) + if err == nil { + t.Fatal("expected an error, got nil") + } + pe, isParseError := err.(parse.ParseError) + if !isParseError { + t.Fatalf("expected a parse error, got %T", err) + } + if pe.Msg != "switch: unterminated (missing closing '{\\n') - https://templ.guide/syntax-and-usage/statements#incomplete-statements" { + t.Errorf("unexpected error: %v", err) + } + if pe.Pos.Line != 0 { + t.Errorf("unexpected line: %d", pe.Pos.Line) } }) t.Run("capitalised Switch", func(t *testing.T) { diff --git a/parser/v2/templateparser_test.go b/parser/v2/templateparser_test.go index 5cf1ee7f..c9793152 100644 --- a/parser/v2/templateparser_test.go +++ b/parser/v2/templateparser_test.go @@ -876,7 +876,7 @@ func TestTemplateParserErrors(t *testing.T) { input: `templ Name(p Parameter) { : malformed open element: line 2, col 0", + expected: ": malformed open element: line 3, col 0", }, } for _, tt := range tests {