Fix bug parsing empty arrays, make golint and go vet happy.
Add comments to make golint happy. Also, because comments are a good thing to
have.
Turn += 1 and -= 1 into ++ and --, respectively, so golint will be happy.
Fix an improperly formated errorf, where a rune was being treated as a string.
Thanks, go vet!
Fix whitespace parsing, returning the parse functions again instead of just
skipping the one character. Now if we have more than one whitespace character in
a row, they'll all be skipped.
Add a parseStringOrNullOrEnd parse function that will be called after the
tokenArrayStart character, to fix a bug where empty arrays were expecting a
string or null and getting the array end character. This is only valid after
tokenArrayStart, however; in other places where parseSeparatorOrDelim is used,
it wouldn't be appropriate.
Add a parser test for an empty array.
7 func strPtr(in string) *string {
11 var parseTestInputs = map[string][]*string{
13 `{lions}`: []*string{strPtr("lions")},
14 `{lions,tigers}`: []*string{strPtr("lions"), strPtr("tigers")},
15 `{lions,tigers,NULL}`: []*string{strPtr("lions"), strPtr("tigers"), nil},
16 `{lions,tigers,bears}`: []*string{strPtr("lions"), strPtr("tigers"), strPtr("bears")},
17 `{lions,tigers,bears,"oh my!"}`: []*string{strPtr("lions"), strPtr("tigers"), strPtr("bears"), strPtr("oh my!")},
20 func TestParseInputsTable(t *testing.T) {
21 for input, expected := range parseTestInputs {
23 output, err := parse(l)
27 t.Logf("`%s`: %#+v\n", input, output)
28 if len(output) != len(expected) {
29 t.Fatalf("Expected %d items in array, got %d\n", len(expected), len(output))
31 for pos, item := range output {
32 if item == nil && expected[pos] != nil {
33 t.Errorf("Expected %d to be %s, got nil instead.", pos, *expected[pos])
34 } else if item != nil && expected[pos] == nil {
35 t.Errorf("Expected %d to be nil, got %s instead.", pos, *item)
36 } else if item != nil && expected[pos] != nil {
38 } else if item == nil && expected[pos] == nil {
40 } else if *item != *expected[pos] {
41 t.Errorf("Expected %d to be %s, got %s instead.", pos, *expected[pos], *item)