Skip to content

Commit

Permalink
Fix EQ token scanning.
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjohnson committed Nov 20, 2014
1 parent 1c81fcf commit f94b588
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
6 changes: 1 addition & 5 deletions influxql/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ func (s *Scanner) Scan() (tok Token, pos Pos, lit string) {
case '/':
return DIV, pos, ""
case '=':
if ch1, _ := s.r.read(); ch1 == '=' {
return EQ, pos, ""
}
s.r.unread()
return ILLEGAL, pos, string(ch0)
return EQ, pos, ""
case '!':
if ch1, _ := s.r.read(); ch1 == '=' {
return NEQ, pos, ""
Expand Down
13 changes: 6 additions & 7 deletions influxql/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ func TestScanner_Scan(t *testing.T) {
{s: `OR`, tok: influxql.OR},
{s: `or`, tok: influxql.OR},

{s: `==`, tok: influxql.EQ},
{s: `= `, tok: influxql.ILLEGAL, lit: "="},
{s: `=`, tok: influxql.EQ},
{s: `!=`, tok: influxql.NEQ},
{s: `! `, tok: influxql.ILLEGAL, lit: "!"},
{s: `<`, tok: influxql.LT},
Expand Down Expand Up @@ -151,13 +150,13 @@ func TestScanner_Scan_Multi(t *testing.T) {
{tok: influxql.IDENT, pos: influxql.Pos{Line: 0, Char: 33}, lit: "a"},
{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 34}, lit: " "},
{tok: influxql.EQ, pos: influxql.Pos{Line: 0, Char: 35}, lit: ""},
{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 37}, lit: " "},
{tok: influxql.STRING, pos: influxql.Pos{Line: 0, Char: 38}, lit: "b"},
{tok: influxql.EOF, pos: influxql.Pos{Line: 0, Char: 41}, lit: ""},
{tok: influxql.WS, pos: influxql.Pos{Line: 0, Char: 36}, lit: " "},
{tok: influxql.STRING, pos: influxql.Pos{Line: 0, Char: 37}, lit: "b"},
{tok: influxql.EOF, pos: influxql.Pos{Line: 0, Char: 40}, lit: ""},
}

// Create a scanner.
v := `SELECT value from myseries WHERE a == "b"`
v := `SELECT value from myseries WHERE a = "b"`
s := influxql.NewScanner(strings.NewReader(v))

// Continually scan until we reach the end.
Expand All @@ -178,7 +177,7 @@ func TestScanner_Scan_Multi(t *testing.T) {
// Verify each token matches.
for i := range exp {
if !reflect.DeepEqual(exp[i], act[i]) {
t.Fatalf("%d. token mismatch: exp=%#v\n\ngot=%#v", exp[i], act[i])
t.Fatalf("%d. token mismatch:\n\nexp=%#v\n\ngot=%#v", i, exp[i], act[i])
}
}
}

0 comments on commit f94b588

Please sign in to comment.