mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-18 21:52:28 +03:00
db55986980
- Support for ingest cache, download cache, and progress bars.
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package sqlz_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/neilotoole/sq/libsq/core/sqlz"
|
|
)
|
|
|
|
func TestNullBool_Scan(t *testing.T) {
|
|
tests := []struct {
|
|
input any
|
|
expectValid bool
|
|
expectBool bool
|
|
}{
|
|
{"yes", true, true},
|
|
{"Yes", true, true},
|
|
{"YES", true, true},
|
|
{"Y", true, true},
|
|
{" Yes ", true, true},
|
|
|
|
{"no", true, false},
|
|
{"No", true, false},
|
|
{"NO", true, false},
|
|
{"N", true, false},
|
|
{" No ", true, false},
|
|
|
|
// check that the pre-existing sql.NullBool stuff works
|
|
{"true", true, true},
|
|
{true, true, true},
|
|
{1, true, true},
|
|
{"1", true, true},
|
|
{"false", true, false},
|
|
{false, true, false},
|
|
{0, true, false},
|
|
{"0", true, false},
|
|
{"garbage", false, false},
|
|
}
|
|
|
|
for i, tt := range tests {
|
|
var nb sqlz.NullBool
|
|
|
|
err := nb.Scan(tt.input)
|
|
if err != nil {
|
|
if !tt.expectValid {
|
|
continue
|
|
}
|
|
t.Errorf("[%d] {%s}: did not expect error: %v", i, tt.input, err)
|
|
continue
|
|
}
|
|
|
|
require.Nil(t, err, "[%d] {%s}: did not expect error: %v", i, tt.input, err)
|
|
require.Equal(t, tt.expectValid, nb.Valid, "[%d] {%s}: expected Valid to be %v but got %v", i, tt.input,
|
|
tt.expectValid, nb.Valid)
|
|
require.Equal(t, tt.expectBool, nb.Bool, "[%d] {%s}: expected Bool to be %v but got %v", i, tt.input,
|
|
tt.expectBool, nb.Bool)
|
|
}
|
|
}
|