2016-10-17 07:14:01 +03:00
|
|
|
package ast
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-08-06 20:58:47 +03:00
|
|
|
"github.com/neilotoole/lg/testlg"
|
2016-10-17 07:14:01 +03:00
|
|
|
"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) {
|
2020-08-06 20:58:47 +03:00
|
|
|
log := testlg.New(t).Strict(true)
|
2016-10-17 07:14:01 +03:00
|
|
|
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange1)
|
2023-03-22 09:17:34 +03:00
|
|
|
assert.Equal(t, 0, NewInspector(log, ast).CountNodes(typeRowRangeNode))
|
2016-10-17 07:14:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRowRange2(t *testing.T) {
|
2020-08-06 20:58:47 +03:00
|
|
|
log := testlg.New(t).Strict(true)
|
2016-10-17 07:14:01 +03:00
|
|
|
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange2)
|
|
|
|
insp := NewInspector(log, 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) {
|
2020-08-06 20:58:47 +03:00
|
|
|
log := testlg.New(t).Strict(true)
|
2016-10-17 07:14:01 +03:00
|
|
|
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange3)
|
|
|
|
insp := NewInspector(log, 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) {
|
2020-08-06 20:58:47 +03:00
|
|
|
log := testlg.New(t).Strict(true)
|
2016-10-17 07:14:01 +03:00
|
|
|
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange4)
|
|
|
|
insp := NewInspector(log, 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) {
|
2020-08-06 20:58:47 +03:00
|
|
|
log := testlg.New(t).Strict(true)
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange5)
|
|
|
|
insp := NewInspector(log, 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) {
|
|
|
|
log := testlg.New(t).Strict(true)
|
2023-03-19 07:58:00 +03:00
|
|
|
ast := mustParse(t, fixtRowRange6)
|
|
|
|
insp := NewInspector(log, 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)
|
|
|
|
}
|