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

View File

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