mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-18 13:41:49 +03:00
2ba633fc2a
* Fixed space issues with expressions * Alias can now be an arbitrary string * Alias can now be an arbitrary string (fixed) * Alias now automatically applied to expressions * Ignore .run * Fixed issue with TestRun not logging correctly to testing.T * Fiddling with sqlite3 temp file closing * Re-enable tests
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package libsq_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/neilotoole/sq/libsq"
|
|
"github.com/neilotoole/sq/testh/tutil"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/neilotoole/sq/testh"
|
|
)
|
|
|
|
func TestQuery_no_source(t *testing.T) {
|
|
testCases := []struct {
|
|
in string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{"1+2", `SELECT 1+2 AS "1+2"`, false},
|
|
{"(1+ 2) * 3", `SELECT (1+2)*3 AS "(1+2)*3"`, false},
|
|
{"(1+ 2) * 3", `SELECT (1+2)*3 AS "(1+2)*3"`, false},
|
|
{`1:"the number"`, `SELECT 1 AS "the number"`, false},
|
|
{`1:thenumber`, `SELECT 1 AS "thenumber"`, false},
|
|
}
|
|
|
|
for i, tc := range testCases {
|
|
tc := tc
|
|
t.Run(tutil.Name(i, tc.in), func(t *testing.T) {
|
|
t.Logf("\nquery: %s\n want: %s", tc.in, tc.want)
|
|
th := testh.New(t)
|
|
coll := th.NewCollection()
|
|
dbases := th.Databases()
|
|
|
|
qc := &libsq.QueryContext{
|
|
Collection: coll,
|
|
DBOpener: dbases,
|
|
JoinDBOpener: dbases,
|
|
ScratchDBOpener: dbases,
|
|
}
|
|
|
|
gotSQL, gotErr := libsq.SLQ2SQL(th.Context, qc, tc.in)
|
|
if tc.wantErr {
|
|
require.Error(t, gotErr)
|
|
return
|
|
}
|
|
|
|
require.NoError(t, gotErr)
|
|
t.Log(gotSQL)
|
|
assert.Equal(t, tc.want, gotSQL)
|
|
})
|
|
}
|
|
}
|