2016-10-17 07:14:01 +03:00
|
|
|
package ast
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"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
|
|
|
|
|
2023-04-07 11:00:49 +03:00
|
|
|
// TODO: Move this to libsq/query_range_test.go
|
2016-10-17 07:14:01 +03:00
|
|
|
|
2023-04-07 11:00:49 +03:00
|
|
|
func TestRowRange1(t *testing.T) {
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange1)
|
2023-04-07 11:00:49 +03:00
|
|
|
assert.Equal(t, 0, NewInspector(ast).CountNodes(typeRowRangeNode))
|
2016-10-17 07:14:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRowRange2(t *testing.T) {
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange2)
|
2023-04-07 11:00:49 +03:00
|
|
|
insp := NewInspector(ast)
|
2023-03-22 09:17:34 +03:00
|
|
|
assert.Equal(t, 1, insp.CountNodes(typeRowRangeNode))
|
|
|
|
nodes := insp.FindNodes(typeRowRangeNode)
|
2016-10-17 07:14:01 +03:00
|
|
|
assert.Equal(t, 1, len(nodes))
|
2023-03-26 04:20:53 +03:00
|
|
|
rr, _ := nodes[0].(*RowRangeNode)
|
2016-10-17 07:14:01 +03:00
|
|
|
assert.Equal(t, 2, rr.Offset)
|
|
|
|
assert.Equal(t, 1, rr.Limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRowRange3(t *testing.T) {
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange3)
|
2023-04-07 11:00:49 +03:00
|
|
|
insp := NewInspector(ast)
|
2023-03-26 04:20:53 +03:00
|
|
|
rr, _ := insp.FindNodes(typeRowRangeNode)[0].(*RowRangeNode)
|
2016-10-17 07:14:01 +03:00
|
|
|
assert.Equal(t, 1, rr.Offset)
|
|
|
|
assert.Equal(t, 2, rr.Limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRowRange4(t *testing.T) {
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange4)
|
2023-04-07 11:00:49 +03:00
|
|
|
insp := NewInspector(ast)
|
2023-03-26 04:20:53 +03:00
|
|
|
rr, _ := insp.FindNodes(typeRowRangeNode)[0].(*RowRangeNode)
|
2016-10-17 07:14:01 +03:00
|
|
|
assert.Equal(t, 0, rr.Offset)
|
|
|
|
assert.Equal(t, 3, rr.Limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRowRange5(t *testing.T) {
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange5)
|
2023-04-07 11:00:49 +03:00
|
|
|
insp := NewInspector(ast)
|
2023-03-26 04:20:53 +03:00
|
|
|
rr, _ := insp.FindNodes(typeRowRangeNode)[0].(*RowRangeNode)
|
2016-10-17 07:14:01 +03:00
|
|
|
assert.Equal(t, 0, rr.Offset)
|
|
|
|
assert.Equal(t, 3, rr.Limit)
|
|
|
|
}
|
|
|
|
|
2020-08-06 20:58:47 +03:00
|
|
|
func TestRowRange6(t *testing.T) {
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange6)
|
2023-04-07 11:00:49 +03:00
|
|
|
insp := NewInspector(ast)
|
2023-03-26 04:20:53 +03:00
|
|
|
rr, _ := insp.FindNodes(typeRowRangeNode)[0].(*RowRangeNode)
|
2016-10-17 07:14:01 +03:00
|
|
|
assert.Equal(t, 2, rr.Offset)
|
|
|
|
assert.Equal(t, -1, rr.Limit)
|
|
|
|
}
|