mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-19 22:21:56 +03:00
b06b631e76
* BaseFragmentBuilder now quotes table and col names for joins * Refactored libsq.engine so that the SQL generated from SLQ input can be tested * Deleted dead code; additional comments
39 lines
735 B
Go
39 lines
735 B
Go
package sqlbuilder
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestQuoteTableOrColSelector(t *testing.T) {
|
|
testCases := []struct {
|
|
in string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{in: "", wantErr: true},
|
|
{in: " ", wantErr: true},
|
|
{in: "not_start_with_period", wantErr: true},
|
|
{in: ".table", want: `"table"`},
|
|
{in: ".table.col", want: `"table"."col"`},
|
|
{in: ".table.col.other", wantErr: true},
|
|
}
|
|
|
|
const quote = `"`
|
|
|
|
for _, tc := range testCases {
|
|
tc := tc
|
|
t.Run(tc.in, func(t *testing.T) {
|
|
got, gotErr := quoteTableOrColSelector(quote, tc.in)
|
|
if tc.wantErr {
|
|
require.Error(t, gotErr)
|
|
return
|
|
}
|
|
|
|
require.NoError(t, gotErr)
|
|
require.Equal(t, tc.want, got)
|
|
})
|
|
}
|
|
}
|