This commit is contained in:
Aliaksandr Valialkin 2024-05-20 16:49:51 +02:00
parent ae0a11d7c1
commit f4ac7c50b6
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 31 additions and 1 deletions

View file

@ -246,7 +246,7 @@ func expectParsePipeFailure(t *testing.T, pipeStr string) {
lex := newLexer(pipeStr) lex := newLexer(pipeStr)
p, err := parsePipe(lex) p, err := parsePipe(lex)
if err == nil { if err == nil && lex.isEnd() {
t.Fatalf("expecting error when parsing [%s]; parsed result: [%s]", pipeStr, p) t.Fatalf("expecting error when parsing [%s]; parsed result: [%s]", pipeStr, p)
} }
} }
@ -259,6 +259,9 @@ func expectParsePipeSuccess(t *testing.T, pipeStr string) {
if err != nil { if err != nil {
t.Fatalf("cannot parse [%s]: %s", pipeStr, err) t.Fatalf("cannot parse [%s]: %s", pipeStr, err)
} }
if !lex.isEnd() {
t.Fatalf("unexpected tail after parsing [%s]: [%s]", pipeStr, lex.s)
}
pipeStrResult := p.String() pipeStrResult := p.String()
if pipeStrResult != pipeStr { if pipeStrResult != pipeStr {

View file

@ -8,6 +8,33 @@ import (
"testing" "testing"
) )
func TestParsePipeUnpackJSONSuccess(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeSuccess(t, pipeStr)
}
f(`unpack_json`)
f(`unpack_json from x`)
f(`unpack_json from x result_prefix abc`)
f(`unpack_json result_prefix abc`)
}
func TestParsePipeUnpackJSONFailure(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeFailure(t, pipeStr)
}
f(`unpack_json foo`)
f(`unpack_json from`)
f(`unpack_json from x y`)
f(`unpack_json from x result_prefix`)
f(`unpack_json from x result_prefix a b`)
f(`unpack_json result_prefix`)
f(`unpack_json result_prefix a b`)
}
func TestPipeUnpackJSON(t *testing.T) { func TestPipeUnpackJSON(t *testing.T) {
f := func(pipeStr string, rows, rowsExpected [][]Field) { f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper() t.Helper()