From 5397eef234d5d006bb1a618d198b05339951c269 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 21 May 2015 15:42:49 -0600 Subject: [PATCH] Added tests for allTokens --- config/parse/parse.go | 2 ++ config/parse/parse_test.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 config/parse/parse_test.go diff --git a/config/parse/parse.go b/config/parse/parse.go index 6695abdf..b44041d4 100644 --- a/config/parse/parse.go +++ b/config/parse/parse.go @@ -24,4 +24,6 @@ func allTokens(input io.Reader) (tokens []token) { return } +// Set of directives that are valid (unordered). Populated +// by config package's init function. var ValidDirectives = make(map[string]struct{}) diff --git a/config/parse/parse_test.go b/config/parse/parse_test.go new file mode 100644 index 00000000..48746300 --- /dev/null +++ b/config/parse/parse_test.go @@ -0,0 +1,22 @@ +package parse + +import ( + "strings" + "testing" +) + +func TestAllTokens(t *testing.T) { + input := strings.NewReader("a b c\nd e") + expected := []string{"a", "b", "c", "d", "e"} + tokens := allTokens(input) + + if len(tokens) != len(expected) { + t.Fatalf("Expected %d tokens, got %d", len(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) + } + } +}