sq/libsq/ast/range_test.go
Neil O'Toole a1a89ee9dd
Support table and column names with spaces. (#156)
* sakila: initial test data

* sakila: more test data

* sakila: yet more test data setup

* whitespace cols: now working for sqlite

* grammar cleanup

* whitespace cols: now working inside count() func for sqlite

* whitespace cols: tests mostly passing; begining refactoring

* grammar: refactor handle

* grammar: more refactoring

* grammar: rename selElement to selector

* wip

* all tests passing

* all tests passing

* linting

* driver: implement CurrentSchema for all driver.SQLDriver impls

* driver: tests for AlterTableRename and AlterTableRenameColumn

* undo reformat of SQL

* undo reformat of SQL

* undo reformat of SQL

* undo reformat of SQL
2023-03-22 00:17:34 -06:00

74 lines
1.9 KiB
Go

package ast
import (
"testing"
"github.com/neilotoole/lg/testlg"
"github.com/stretchr/testify/assert"
)
// [] select all rows (no range)
// [1] select row[1]
// [10:15] select rows 10 thru 15
// [0:15] select rows 0 thru 15
// [:15] same as above (0 thru 15)
// [10:] select all rows from 10 onwards
func TestRowRange1(t *testing.T) {
log := testlg.New(t).Strict(true)
ast := mustParse(t, fixtRowRange1)
assert.Equal(t, 0, NewInspector(log, ast).CountNodes(typeRowRangeNode))
}
func TestRowRange2(t *testing.T) {
log := testlg.New(t).Strict(true)
ast := mustParse(t, fixtRowRange2)
insp := NewInspector(log, ast)
assert.Equal(t, 1, insp.CountNodes(typeRowRangeNode))
nodes := insp.FindNodes(typeRowRangeNode)
assert.Equal(t, 1, len(nodes))
rr, _ := nodes[0].(*RowRange)
assert.Equal(t, 2, rr.Offset)
assert.Equal(t, 1, rr.Limit)
}
func TestRowRange3(t *testing.T) {
log := testlg.New(t).Strict(true)
ast := mustParse(t, fixtRowRange3)
insp := NewInspector(log, ast)
rr, _ := insp.FindNodes(typeRowRangeNode)[0].(*RowRange)
assert.Equal(t, 1, rr.Offset)
assert.Equal(t, 2, rr.Limit)
}
func TestRowRange4(t *testing.T) {
log := testlg.New(t).Strict(true)
ast := mustParse(t, fixtRowRange4)
insp := NewInspector(log, ast)
rr, _ := insp.FindNodes(typeRowRangeNode)[0].(*RowRange)
assert.Equal(t, 0, rr.Offset)
assert.Equal(t, 3, rr.Limit)
}
func TestRowRange5(t *testing.T) {
log := testlg.New(t).Strict(true)
ast := mustParse(t, fixtRowRange5)
insp := NewInspector(log, ast)
rr, _ := insp.FindNodes(typeRowRangeNode)[0].(*RowRange)
assert.Equal(t, 0, rr.Offset)
assert.Equal(t, 3, rr.Limit)
}
func TestRowRange6(t *testing.T) {
log := testlg.New(t).Strict(true)
ast := mustParse(t, fixtRowRange6)
insp := NewInspector(log, ast)
rr, _ := insp.FindNodes(typeRowRangeNode)[0].(*RowRange)
assert.Equal(t, 2, rr.Offset)
assert.Equal(t, -1, rr.Limit)
}