Update SQL tests
This commit is contained in:
parent
2fb4791387
commit
9492ed7244
2 changed files with 73 additions and 23 deletions
|
@ -43,11 +43,11 @@ func (s *Scanner) Scan() (tok Token, lit string, val interface{}) {
|
||||||
ch := s.next()
|
ch := s.next()
|
||||||
|
|
||||||
// If we see whitespace then consume all contiguous whitespace.
|
// If we see whitespace then consume all contiguous whitespace.
|
||||||
if isWhitespace(ch) {
|
if isBlank(ch) {
|
||||||
return s.scanBlank(ch)
|
return s.scanBlank(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we see a letter then consume as an string.
|
// If we see a letter then consume as a string.
|
||||||
if isLetter(ch) {
|
if isLetter(ch) {
|
||||||
return s.scanIdent(ch)
|
return s.scanIdent(ch)
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ func (s *Scanner) scanBlank(chp ...rune) (tok Token, lit string, val interface{}
|
||||||
for {
|
for {
|
||||||
if ch := s.next(); ch == eof {
|
if ch := s.next(); ch == eof {
|
||||||
break
|
break
|
||||||
} else if !isWhitespace(ch) {
|
} else if !isBlank(ch) {
|
||||||
s.undo()
|
s.undo()
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
|
@ -732,8 +732,8 @@ func (s *Scanner) undo() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// isWhitespace returns true if the rune is a space, tab, or newline.
|
// isBlank returns true if the rune is a space, tab, or newline.
|
||||||
func isWhitespace(ch rune) bool {
|
func isBlank(ch rune) bool {
|
||||||
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'
|
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ func Test_Parse_Queries_Select(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM`,
|
sql: `SELECT * FROM`,
|
||||||
err: "Found `` but expected `table name`",
|
err: "Found `` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM per!son`,
|
sql: `SELECT * FROM per!son`,
|
||||||
|
@ -307,20 +307,24 @@ func Test_Parse_Queries_Select(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM @`,
|
sql: `SELECT * FROM @`,
|
||||||
err: "Found `` but expected `table name`",
|
err: "Found `@` but expected `table name or record id`",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @person`,
|
||||||
|
err: "Found `@person` but expected `table name or record id`",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @person:`,
|
||||||
|
err: "Found `@person:` but expected `table name or record id`",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @person WHERE`,
|
||||||
|
err: "Found `@person` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM person:uuid`,
|
sql: `SELECT * FROM person:uuid`,
|
||||||
err: "Found `:` but expected `EOF, ;`",
|
err: "Found `:` but expected `EOF, ;`",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
sql: `SELECT * FROM @person`,
|
|
||||||
err: "Found `` but expected `:`",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
sql: `SELECT * FROM @person:`,
|
|
||||||
err: "Found `` but expected `table id`",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM person`,
|
sql: `SELECT * FROM person`,
|
||||||
res: &Query{Statements: []Statement{&SelectStatement{
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
@ -370,6 +374,13 @@ func Test_Parse_Queries_Select(t *testing.T) {
|
||||||
What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}},
|
What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}},
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @person:{123.456.789.012}`,
|
||||||
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
Expr: []*Field{{Expr: &All{}, Alias: "*"}},
|
||||||
|
What: []Expr{&Thing{TB: "person", ID: "123.456.789.012"}},
|
||||||
|
}}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM @person:⟨A250C5A3-948F-4657-88AD-FF5F27B5B24E⟩`,
|
sql: `SELECT * FROM @person:⟨A250C5A3-948F-4657-88AD-FF5F27B5B24E⟩`,
|
||||||
res: &Query{Statements: []Statement{&SelectStatement{
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
@ -377,6 +388,13 @@ func Test_Parse_Queries_Select(t *testing.T) {
|
||||||
What: []Expr{&Thing{TB: "person", ID: "A250C5A3-948F-4657-88AD-FF5F27B5B24E"}},
|
What: []Expr{&Thing{TB: "person", ID: "A250C5A3-948F-4657-88AD-FF5F27B5B24E"}},
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @person:{A250C5A3-948F-4657-88AD-FF5F27B5B24E}`,
|
||||||
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
Expr: []*Field{{Expr: &All{}, Alias: "*"}},
|
||||||
|
What: []Expr{&Thing{TB: "person", ID: "A250C5A3-948F-4657-88AD-FF5F27B5B24E"}},
|
||||||
|
}}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM @person:⟨8250C5A3-948F-4657-88AD-FF5F27B5B24E⟩`,
|
sql: `SELECT * FROM @person:⟨8250C5A3-948F-4657-88AD-FF5F27B5B24E⟩`,
|
||||||
res: &Query{Statements: []Statement{&SelectStatement{
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
@ -384,6 +402,13 @@ func Test_Parse_Queries_Select(t *testing.T) {
|
||||||
What: []Expr{&Thing{TB: "person", ID: "8250C5A3-948F-4657-88AD-FF5F27B5B24E"}},
|
What: []Expr{&Thing{TB: "person", ID: "8250C5A3-948F-4657-88AD-FF5F27B5B24E"}},
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @person:{8250C5A3-948F-4657-88AD-FF5F27B5B24E}`,
|
||||||
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
Expr: []*Field{{Expr: &All{}, Alias: "*"}},
|
||||||
|
What: []Expr{&Thing{TB: "person", ID: "8250C5A3-948F-4657-88AD-FF5F27B5B24E"}},
|
||||||
|
}}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM @person:⟨Tobie Morgan Hitchcock⟩`,
|
sql: `SELECT * FROM @person:⟨Tobie Morgan Hitchcock⟩`,
|
||||||
res: &Query{Statements: []Statement{&SelectStatement{
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
@ -391,6 +416,13 @@ func Test_Parse_Queries_Select(t *testing.T) {
|
||||||
What: []Expr{&Thing{TB: "person", ID: "Tobie Morgan Hitchcock"}},
|
What: []Expr{&Thing{TB: "person", ID: "Tobie Morgan Hitchcock"}},
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @person:{Tobie Morgan Hitchcock}`,
|
||||||
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
Expr: []*Field{{Expr: &All{}, Alias: "*"}},
|
||||||
|
What: []Expr{&Thing{TB: "person", ID: "Tobie Morgan Hitchcock"}},
|
||||||
|
}}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM @⟨email addresses⟩:⟨tobie@abcum.com⟩`,
|
sql: `SELECT * FROM @⟨email addresses⟩:⟨tobie@abcum.com⟩`,
|
||||||
res: &Query{Statements: []Statement{&SelectStatement{
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
@ -398,6 +430,13 @@ func Test_Parse_Queries_Select(t *testing.T) {
|
||||||
What: []Expr{&Thing{TB: "email addresses", ID: "tobie@abcum.com"}},
|
What: []Expr{&Thing{TB: "email addresses", ID: "tobie@abcum.com"}},
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @{email addresses}:{tobie@abcum.com}`,
|
||||||
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
Expr: []*Field{{Expr: &All{}, Alias: "*"}},
|
||||||
|
What: []Expr{&Thing{TB: "email addresses", ID: "tobie@abcum.com"}},
|
||||||
|
}}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM @⟨email addresses⟩:⟨tobie+spam@abcum.com⟩`,
|
sql: `SELECT * FROM @⟨email addresses⟩:⟨tobie+spam@abcum.com⟩`,
|
||||||
res: &Query{Statements: []Statement{&SelectStatement{
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
@ -405,9 +444,20 @@ func Test_Parse_Queries_Select(t *testing.T) {
|
||||||
What: []Expr{&Thing{TB: "email addresses", ID: "tobie+spam@abcum.com"}},
|
What: []Expr{&Thing{TB: "email addresses", ID: "tobie+spam@abcum.com"}},
|
||||||
}}},
|
}}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @{email addresses}:{tobie+spam@abcum.com}`,
|
||||||
|
res: &Query{Statements: []Statement{&SelectStatement{
|
||||||
|
Expr: []*Field{{Expr: &All{}, Alias: "*"}},
|
||||||
|
What: []Expr{&Thing{TB: "email addresses", ID: "tobie+spam@abcum.com"}},
|
||||||
|
}}},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT * FROM @⟨email addresses⟩:⟨this\qis\nodd⟩`,
|
sql: `SELECT * FROM @⟨email addresses⟩:⟨this\qis\nodd⟩`,
|
||||||
err: "Found `thisqis\nodd` but expected `table id`",
|
err: "Found `@email addresses:thisqis\nodd` but expected `table name or record id`",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
sql: `SELECT * FROM @{email addresses}:{this\qis\nodd}`,
|
||||||
|
err: "Found `@email addresses:thisqis\nodd` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `SELECT *, temp AS test FROM person`,
|
sql: `SELECT *, temp AS test FROM person`,
|
||||||
|
@ -679,11 +729,11 @@ func Test_Parse_Queries_Create(t *testing.T) {
|
||||||
var tests = []tester{
|
var tests = []tester{
|
||||||
{
|
{
|
||||||
sql: `CREATE`,
|
sql: `CREATE`,
|
||||||
err: "Found `` but expected `table name`",
|
err: "Found `` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `INSERT INTO`,
|
sql: `INSERT INTO`,
|
||||||
err: "Found `` but expected `table name`",
|
err: "Found `` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `CREATE person`,
|
sql: `CREATE person`,
|
||||||
|
@ -827,11 +877,11 @@ func Test_Parse_Queries_Update(t *testing.T) {
|
||||||
var tests = []tester{
|
var tests = []tester{
|
||||||
{
|
{
|
||||||
sql: `UPDATE`,
|
sql: `UPDATE`,
|
||||||
err: "Found `` but expected `table name`",
|
err: "Found `` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `UPSERT INTO`,
|
sql: `UPSERT INTO`,
|
||||||
err: "Found `` but expected `table name`",
|
err: "Found `` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `UPDATE person`,
|
sql: `UPDATE person`,
|
||||||
|
@ -975,7 +1025,7 @@ func Test_Parse_Queries_Modify(t *testing.T) {
|
||||||
var tests = []tester{
|
var tests = []tester{
|
||||||
{
|
{
|
||||||
sql: `MODIFY`,
|
sql: `MODIFY`,
|
||||||
err: "Found `` but expected `@`",
|
err: "Found `` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `MODIFY @person:test`,
|
sql: `MODIFY @person:test`,
|
||||||
|
@ -1073,11 +1123,11 @@ func Test_Parse_Queries_Delete(t *testing.T) {
|
||||||
var tests = []tester{
|
var tests = []tester{
|
||||||
{
|
{
|
||||||
sql: `DELETE`,
|
sql: `DELETE`,
|
||||||
err: "Found `` but expected `table name`",
|
err: "Found `` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `DELETE FROM`,
|
sql: `DELETE FROM`,
|
||||||
err: "Found `` but expected `table name`",
|
err: "Found `` but expected `table name or record id`",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sql: `DELETE person`,
|
sql: `DELETE person`,
|
||||||
|
|
Loading…
Reference in a new issue