6 "github.com/stretchr/testify/assert"
7 "github.com/tendermint/tmlibs/pubsub/query"
10 // TODO: fuzzy testing?
11 func TestParser(t *testing.T) {
16 {"tm.events.type='NewBlock'", true},
17 {"tm.events.type = 'NewBlock'", true},
18 {"tm.events.name = ''", true},
19 {"tm.events.type='TIME'", true},
20 {"tm.events.type='DATE'", true},
21 {"tm.events.type='='", true},
22 {"tm.events.type='TIME", false},
23 {"tm.events.type=TIME'", false},
24 {"tm.events.type==", false},
25 {"tm.events.type=NewBlock", false},
27 {"tm.events.type 'NewBlock' =", false},
28 {"tm.events.type>'NewBlock'", false},
31 {"='NewBlock'", false},
32 {"tm.events.type=", false},
34 {"tm.events.typeNewBlock", false},
35 {"tm.events.type'NewBlock'", false},
36 {"'NewBlock'", false},
40 {"tm.events.type='NewBlock' AND abci.account.name='Igor'", true},
41 {"tm.events.type='NewBlock' AND", false},
42 {"tm.events.type='NewBlock' AN", false},
43 {"tm.events.type='NewBlock' AN tm.events.type='NewBlockHeader'", false},
44 {"AND tm.events.type='NewBlock' ", false},
46 {"abci.account.name CONTAINS 'Igor'", true},
48 {"tx.date > DATE 2013-05-03", true},
49 {"tx.date < DATE 2013-05-03", true},
50 {"tx.date <= DATE 2013-05-03", true},
51 {"tx.date >= DATE 2013-05-03", true},
52 {"tx.date >= DAT 2013-05-03", false},
53 {"tx.date <= DATE2013-05-03", false},
54 {"tx.date <= DATE -05-03", false},
55 {"tx.date >= DATE 20130503", false},
56 {"tx.date >= DATE 2013+01-03", false},
57 // incorrect year, month, day
58 {"tx.date >= DATE 0013-01-03", false},
59 {"tx.date >= DATE 2013-31-03", false},
60 {"tx.date >= DATE 2013-01-83", false},
62 {"tx.date > TIME 2013-05-03T14:45:00+07:00", true},
63 {"tx.date < TIME 2013-05-03T14:45:00-02:00", true},
64 {"tx.date <= TIME 2013-05-03T14:45:00Z", true},
65 {"tx.date >= TIME 2013-05-03T14:45:00Z", true},
66 {"tx.date >= TIME2013-05-03T14:45:00Z", false},
67 {"tx.date = IME 2013-05-03T14:45:00Z", false},
68 {"tx.date = TIME 2013-05-:45:00Z", false},
69 {"tx.date >= TIME 2013-05-03T14:45:00", false},
70 {"tx.date >= TIME 0013-00-00T14:45:00Z", false},
71 {"tx.date >= TIME 2013+05=03T14:45:00Z", false},
73 {"account.balance=100", true},
74 {"account.balance >= 200", true},
75 {"account.balance >= -300", false},
76 {"account.balance >>= 400", false},
77 {"account.balance=33.22.1", false},
79 {"hash='136E18F7E4C348B780CF873A0BF43922E5BAFA63'", true},
80 {"hash=136E18F7E4C348B780CF873A0BF43922E5BAFA63", false},
83 for _, c := range cases {
84 _, err := query.New(c.query)
86 assert.NoError(t, err, "Query was '%s'", c.query)
88 assert.Error(t, err, "Query was '%s'", c.query)