You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.9 KiB

  1. package query_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/tendermint/tendermint/libs/pubsub/query"
  6. )
  7. // TODO: fuzzy testing?
  8. func TestParser(t *testing.T) {
  9. cases := []struct {
  10. query string
  11. valid bool
  12. }{
  13. {"tm.events.type='NewBlock'", true},
  14. {"tm.events.type = 'NewBlock'", true},
  15. {"tm.events.name = ''", true},
  16. {"tm.events.type='TIME'", true},
  17. {"tm.events.type='DATE'", true},
  18. {"tm.events.type='='", true},
  19. {"tm.events.type='TIME", false},
  20. {"tm.events.type=TIME'", false},
  21. {"tm.events.type==", false},
  22. {"tm.events.type=NewBlock", false},
  23. {">==", false},
  24. {"tm.events.type 'NewBlock' =", false},
  25. {"tm.events.type>'NewBlock'", false},
  26. {"", false},
  27. {"=", false},
  28. {"='NewBlock'", false},
  29. {"tm.events.type=", false},
  30. {"tm.events.typeNewBlock", false},
  31. {"tm.events.type'NewBlock'", false},
  32. {"'NewBlock'", false},
  33. {"NewBlock", false},
  34. {"", false},
  35. {"tm.events.type='NewBlock' AND abci.account.name='Igor'", true},
  36. {"tm.events.type='NewBlock' AND", false},
  37. {"tm.events.type='NewBlock' AN", false},
  38. {"tm.events.type='NewBlock' AN tm.events.type='NewBlockHeader'", false},
  39. {"AND tm.events.type='NewBlock' ", false},
  40. {"abci.account.name CONTAINS 'Igor'", true},
  41. {"tx.date > DATE 2013-05-03", true},
  42. {"tx.date < DATE 2013-05-03", true},
  43. {"tx.date <= DATE 2013-05-03", true},
  44. {"tx.date >= DATE 2013-05-03", true},
  45. {"tx.date >= DAT 2013-05-03", false},
  46. {"tx.date <= DATE2013-05-03", false},
  47. {"tx.date <= DATE -05-03", false},
  48. {"tx.date >= DATE 20130503", false},
  49. {"tx.date >= DATE 2013+01-03", false},
  50. // incorrect year, month, day
  51. {"tx.date >= DATE 0013-01-03", false},
  52. {"tx.date >= DATE 2013-31-03", false},
  53. {"tx.date >= DATE 2013-01-83", false},
  54. {"tx.date > TIME 2013-05-03T14:45:00+07:00", true},
  55. {"tx.date < TIME 2013-05-03T14:45:00-02:00", true},
  56. {"tx.date <= TIME 2013-05-03T14:45:00Z", true},
  57. {"tx.date >= TIME 2013-05-03T14:45:00Z", true},
  58. {"tx.date >= TIME2013-05-03T14:45:00Z", false},
  59. {"tx.date = IME 2013-05-03T14:45:00Z", false},
  60. {"tx.date = TIME 2013-05-:45:00Z", false},
  61. {"tx.date >= TIME 2013-05-03T14:45:00", false},
  62. {"tx.date >= TIME 0013-00-00T14:45:00Z", false},
  63. {"tx.date >= TIME 2013+05=03T14:45:00Z", false},
  64. {"account.balance=100", true},
  65. {"account.balance >= 200", true},
  66. {"account.balance >= -300", false},
  67. {"account.balance >>= 400", false},
  68. {"account.balance=33.22.1", false},
  69. {"slashing.amount EXISTS", true},
  70. {"slashing.amount EXISTS AND account.balance=100", true},
  71. {"account.balance=100 AND slashing.amount EXISTS", true},
  72. {"slashing EXISTS", true},
  73. {"hash='136E18F7E4C348B780CF873A0BF43922E5BAFA63'", true},
  74. {"hash=136E18F7E4C348B780CF873A0BF43922E5BAFA63", false},
  75. }
  76. for _, c := range cases {
  77. _, err := query.New(c.query)
  78. if c.valid {
  79. assert.NoErrorf(t, err, "Query was '%s'", c.query)
  80. } else {
  81. assert.Errorf(t, err, "Query was '%s'", c.query)
  82. }
  83. }
  84. }