From 4e107e3ce58452278c3b6b90585e77a160ce45eb Mon Sep 17 00:00:00 2001 From: "Daniel J. Rollins" Date: Thu, 25 Apr 2024 22:09:41 +0100 Subject: [PATCH] test(parser): add failing test for greedy raw element parser --- parser/v2/raw_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/parser/v2/raw_test.go b/parser/v2/raw_test.go index 7888e37c3..26de32849 100644 --- a/parser/v2/raw_test.go +++ b/parser/v2/raw_test.go @@ -90,3 +90,36 @@ func TestRawElementParser(t *testing.T) { }) } } + +func TestRawElementParserIsNotGreedy(t *testing.T) { + var tests = []struct { + name string + input string + expected RawElement + }{ + { + name: "styles tag", + input: ``, + }, + { + name: "scripts tag", + input: ``, + }, + } + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + input := parse.NewInput(tt.input) + actual, ok, err := rawElements.Parse(input) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if ok { + t.Fatalf("unexpected success for input %q", tt.input) + } + if actual != nil { + t.Fatalf("expected nil Node got %v", actual) + } + }) + } +}