diff options
Diffstat (limited to 'caddyfile/parse_test.go')
-rw-r--r-- | caddyfile/parse_test.go | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/caddyfile/parse_test.go b/caddyfile/parse_test.go index 10beb5b56..2b1409192 100644 --- a/caddyfile/parse_test.go +++ b/caddyfile/parse_test.go @@ -23,21 +23,47 @@ import ( ) func TestAllTokens(t *testing.T) { - input := strings.NewReader("a b c\nd e") - expected := []string{"a", "b", "c", "d", "e"} - tokens, err := allTokens(input) - - if err != nil { - t.Fatalf("Expected no error, got %v", err) - } - if len(tokens) != len(expected) { - t.Fatalf("Expected %d tokens, got %d", len(expected), len(tokens)) - } + tests := []struct { + name string + input string + expected []string + }{ + { + name: "not-empty", + input: "a b c\nd e", + expected: []string{"a", "b", "c", "d", "e"}, + }, { + name: "empty", + input: "", + }, { + name: "newline", + input: "\n", + }, { + name: "space", + input: " ", + }, { + name: "tab and newline", + input: "\t\n", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tokens, err := allTokens(strings.NewReader(tt.input)) + + if err != nil { + t.Fatalf("Expected no error, got %v", err) + } + if len(tokens) != len(tt.expected) { + t.Fatalf("Expected %d tokens, got %d", len(tt.expected), len(tokens)) + } - for i, val := range expected { - if tokens[i].Text != val { - t.Errorf("Token %d should be '%s' but was '%s'", i, val, tokens[i].Text) - } + for i, val := range tt.expected { + if tokens[i].Text != val { + t.Errorf("Token %d should be '%s' but was '%s'", i, val, tokens[i].Text) + } + } + }) } } |