mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-24 08:36:43 +03:00
7396aadb9e
* The query language now supports multiple joins.
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package ast
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/neilotoole/sq/testh/tutil"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestRowRange tests the row range mechanism.
|
|
//
|
|
// [] 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 TestRowRange(t *testing.T) {
|
|
testCases := []struct {
|
|
in string
|
|
wantRowRange bool
|
|
wantOffset int
|
|
wantLimit int
|
|
}{
|
|
{".actor | .[]", false, 0, 0},
|
|
{".actor | .[2]", true, 2, 1},
|
|
{".actor | .[1:3]", true, 1, 2},
|
|
{".actor | .[0:3]", true, 0, 3},
|
|
{".actor | .[:3]", true, 0, 3},
|
|
{".actor | .[2:]", true, 2, -1},
|
|
}
|
|
|
|
for i, tc := range testCases {
|
|
tc := tc
|
|
t.Run(tutil.Name(i, tc.in), func(t *testing.T) {
|
|
ast := mustParse(t, tc.in)
|
|
insp := NewInspector(ast)
|
|
nodes := insp.FindNodes(typeRowRangeNode)
|
|
|
|
if !tc.wantRowRange {
|
|
require.Empty(t, nodes)
|
|
return
|
|
}
|
|
|
|
require.Len(t, nodes, 1)
|
|
rr, ok := nodes[0].(*RowRangeNode)
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, tc.wantOffset, rr.Offset)
|
|
require.Equal(t, tc.wantLimit, rr.Limit)
|
|
})
|
|
}
|
|
}
|