Skip to content
Myr

Fix AWK tokenizer not treating a new line character as whitespace

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent f9830c5 · Browse files · 2 files+6 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+6 added−6 removed

  • other:+6 added−6 removed

2 files+6 added−6 removed

modified:src/tokenizer_test.go+5 added-5 removed
54 unmodified lines
55}5657func TestTokenize(t *testing.T) {58 // AWK-style59 input := " abc: def: ghi "59 input := " abc: \n\t def: ghi "60 tokens := Tokenize(input, Delimiter{})61 if tokens[0].text.ToString() != "abc: " || tokens[0].prefixLength != 2 {61 if tokens[0].text.ToString() != "abc: \n\t " || tokens[0].prefixLength != 2 {62 t.Errorf("%s", tokens)63 }6465 // With delimiter
4 unmodified lines
7071 // With delimiter regex72 tokens = Tokenize(input, delimiterRegexp("\\s+"))73 if tokens[0].text.ToString() != " " || tokens[0].prefixLength != 0 ||74 tokens[1].text.ToString() != "abc: " || tokens[1].prefixLength != 2 ||75 tokens[2].text.ToString() != "def: " || tokens[2].prefixLength != 8 ||76 tokens[3].text.ToString() != "ghi " || tokens[3].prefixLength != 14 {74 tokens[1].text.ToString() != "abc: \n\t " || tokens[1].prefixLength != 2 ||75 tokens[2].text.ToString() != "def: " || tokens[2].prefixLength != 10 ||76 tokens[3].text.ToString() != "ghi " || tokens[3].prefixLength != 16 {77 t.Errorf("%s", tokens)78 }79}80
45 unmodified lines
modified:src/tokenizer.go+1 added-1 removed
159 unmodified lines
160 begin := 0161 end := 0162 for idx := 0; idx < len(input); idx++ {163 r := input[idx]164 white := r == 9 || r == 32164 white := r == 9 || r == 32 || r == 10165 switch state {166 case awkNil:167 if white {168 prefixLength++
168 unmodified lines