@@ -33,6 +33,8 @@ func TestScanner(t *testing.T) {
3333 "lines_mixed_delimiters" : {input : "a\r \n \f b" , rg : nil , want : []string {"a" , "b" }},
3434 "lines_only_delimiters" : {input : "\n \r \f " , rg : nil , want : nil },
3535
36+ "regex_empty" : {input : "" , rg : dateRegex , want : nil },
37+ "regex_not_matching_at_start" : {input : "ERROR something2024-01-15 ERROR something" , rg : dateRegex , want : []string {"ERROR something" , "2024-01-15 ERROR something" }},
3638 "regex_single_entry" : {input : "2024-01-15 ERROR something" , rg : dateRegex , want : []string {"2024-01-15 ERROR something" }},
3739 "regex_two_entries_with_newline" : {input : "2024-01-15 ERROR\n 2024-01-16 INFO" , rg : dateRegex , want : []string {"2024-01-15 ERROR\n " , "2024-01-16 INFO" }},
3840 "regex_continuation_lines" : {input : "2024-01-15 ERROR\n at com.foo\n 2024-01-16 INFO" , rg : dateRegex , want : []string {"2024-01-15 ERROR\n at com.foo\n " , "2024-01-16 INFO" }},
@@ -65,3 +67,41 @@ func TestScanner(t *testing.T) {
6567 })
6668 }
6769}
70+
71+ func TestScannerWithOversizedToken (t * testing.T ) {
72+ t .Parallel ()
73+
74+ overflow := 100
75+ oversized := strings .Repeat ("a" , maxTokenSize + overflow )
76+
77+ tests := map [string ]struct {
78+ rg * regexp.Regexp
79+ }{
80+ "lines" : {rg : nil },
81+ "regex" : {rg : regexp .MustCompile (`\d{4}-\d{2}-\d{2}` )},
82+ }
83+
84+ for name , tc := range tests {
85+ t .Run (name , func (t * testing.T ) {
86+ t .Parallel ()
87+ scanner := NewScanner (strings .NewReader (oversized ), tc .rg )
88+
89+ var got []string
90+ for scanner .Scan () {
91+ got = append (got , scanner .Text ())
92+ }
93+ if err := scanner .Err (); err != nil {
94+ t .Fatalf ("unexpected error: %v" , err )
95+ }
96+ if len (got ) != 2 {
97+ t .Fatalf ("want 2 tokens, got %d" , len (got ))
98+ }
99+ if len (got [0 ]) != maxTokenSize {
100+ t .Errorf ("first token: want %d bytes, got %d" , maxTokenSize , len (got [0 ]))
101+ }
102+ if len (got [1 ]) != overflow {
103+ t .Errorf ("second token: want %d bytes, got %d" , overflow , len (got [1 ]))
104+ }
105+ })
106+ }
107+ }
0 commit comments