diff options
author | Michael Muré <batolettre@gmail.com> | 2020-03-28 17:17:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-28 17:17:13 +0100 |
commit | 390e66eb2b3a7088cdb8a44eeaf384fe691daf4a (patch) | |
tree | 05386ddf08d7e1c2947a6fc6cf2fbd44efa19eaf /query/lexer_test.go | |
parent | 58abc6b0a35b679ac0c34579ff1cb53c8fa71af4 (diff) | |
parent | 314fcbb2293d869c33d6a76aedd148aedff6561d (diff) | |
download | git-bug-390e66eb2b3a7088cdb8a44eeaf384fe691daf4a.tar.gz |
Merge pull request #355 from MichaelMure/query-parser-ast
replace the all-in-one query parser by a complete one with AST/lexer/parser
Diffstat (limited to 'query/lexer_test.go')
-rw-r--r-- | query/lexer_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/query/lexer_test.go b/query/lexer_test.go new file mode 100644 index 00000000..922e3fc9 --- /dev/null +++ b/query/lexer_test.go @@ -0,0 +1,45 @@ +package query + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestTokenize(t *testing.T) { + var tests = []struct { + input string + tokens []token + }{ + {"gibberish", nil}, + {"status:", nil}, + {":value", nil}, + + {"status:open", []token{{"status", "open"}}}, + {"status:closed", []token{{"status", "closed"}}}, + + {"author:rene", []token{{"author", "rene"}}}, + {`author:"René Descartes"`, []token{{"author", "René Descartes"}}}, + + { + `status:open status:closed author:rene author:"René Descartes"`, + []token{ + {"status", "open"}, + {"status", "closed"}, + {"author", "rene"}, + {"author", "René Descartes"}, + }, + }, + } + + for _, tc := range tests { + tokens, err := tokenize(tc.input) + if tc.tokens == nil { + assert.Error(t, err) + assert.Nil(t, tokens) + } else { + assert.NoError(t, err) + assert.Equal(t, tc.tokens, tokens) + } + } +} |