Move ne comparator below eq comparator (#119)

qb: Move ne comparator below eq comparator

Signed-off-by: pierdipi <pierangelodipilato@gmail.com>
This commit is contained in:
pierDipi
2019-11-07 15:29:22 +01:00
committed by Michal Matczuk
parent 8a02fca018
commit 180d58ce46
2 changed files with 27 additions and 27 deletions

View File

@@ -13,6 +13,7 @@ type op byte
const (
eq op = iota
ne
lt
leq
gt
@@ -21,7 +22,6 @@ const (
cnt
cntKey
like
ne
)
// Cmp if a filtering comparator that is used in WHERE and IF clauses.
@@ -36,6 +36,8 @@ func (c Cmp) writeCql(cql *bytes.Buffer) (names []string) {
switch c.op {
case eq:
cql.WriteByte('=')
case ne:
cql.WriteString("!=")
case lt:
cql.WriteByte('<')
case leq:
@@ -54,8 +56,6 @@ func (c Cmp) writeCql(cql *bytes.Buffer) (names []string) {
cql.WriteString(" CONTAINS KEY ")
case like:
cql.WriteString(" LIKE ")
case ne:
cql.WriteString("!=")
}
return c.value.writeCql(cql)
}

View File

@@ -23,6 +23,16 @@ func TestCmp(t *testing.T) {
S: "eq=?",
N: []string{"eq"},
},
{
C: Ne("ne"),
S: "ne!=?",
N: []string{"ne"},
},
{
C: NeTuple("ne", 3),
S: "ne!=(?,?,?)",
N: []string{"ne_0", "ne_1", "ne_2"},
},
{
C: Lt("lt"),
S: "lt<?",
@@ -103,16 +113,6 @@ func TestCmp(t *testing.T) {
S: "like LIKE (?,?)",
N: []string{"like_0", "like_1"},
},
{
C: Ne("ne"),
S: "ne!=?",
N: []string{"ne"},
},
{
C: NeTuple("ne", 3),
S: "ne!=(?,?,?)",
N: []string{"ne_0", "ne_1", "ne_2"},
},
// Custom bind names
{
@@ -120,6 +120,11 @@ func TestCmp(t *testing.T) {
S: "eq=?",
N: []string{"name"},
},
{
C: NeNamed("ne", "name"),
S: "ne!=?",
N: []string{"name"},
},
{
C: LtNamed("lt", "name"),
S: "lt<?",
@@ -155,17 +160,16 @@ func TestCmp(t *testing.T) {
S: "cntKey CONTAINS KEY ?",
N: []string{"name"},
},
{
C: NeNamed("ne", "name"),
S: "ne!=?",
N: []string{"name"},
},
// Literals
{
C: EqLit("eq", "litval"),
S: "eq=litval",
},
{
C: NeLit("ne", "litval"),
S: "ne!=litval",
},
{
C: LtLit("lt", "litval"),
S: "lt<litval",
@@ -190,10 +194,6 @@ func TestCmp(t *testing.T) {
C: ContainsLit("cnt", "litval"),
S: "cnt CONTAINS litval",
},
{
C: NeLit("ne", "litval"),
S: "ne!=litval",
},
// Functions
{
@@ -215,6 +215,11 @@ func TestCmp(t *testing.T) {
C: EqFunc("eq", Now()),
S: "eq=now()",
},
{
C: NeFunc("ne", Fn("fn", "arg0", "arg1", "arg2")),
S: "ne!=fn(?,?,?)",
N: []string{"arg0", "arg1", "arg2"},
},
{
C: LtFunc("eq", Now()),
S: "eq<now()",
@@ -233,11 +238,6 @@ func TestCmp(t *testing.T) {
S: "eq>=maxTimeuuid(?)",
N: []string{"arg0"},
},
{
C: NeFunc("ne", Fn("fn", "arg0", "arg1", "arg2")),
S: "ne!=fn(?,?,?)",
N: []string{"arg0", "arg1", "arg2"},
},
}
buf := bytes.Buffer{}