| 270 | } |
| 271 | |
| 272 | func TestBoolArrayScanError(t *testing.T) { |
| 273 | for _, tt := range []struct { |
| 274 | input, err string |
| 275 | }{ |
| 276 | {``, "unable to parse array"}, |
| 277 | {`{`, "unable to parse array"}, |
| 278 | {`{{t},{f}}`, "cannot convert ARRAY[2][1] to BoolArray"}, |
| 279 | {`{NULL}`, `could not parse boolean array index 0: invalid boolean ""`}, |
| 280 | {`{a}`, `could not parse boolean array index 0: invalid boolean "a"`}, |
| 281 | {`{t,b}`, `could not parse boolean array index 1: invalid boolean "b"`}, |
| 282 | {`{t,f,cd}`, `could not parse boolean array index 2: invalid boolean "cd"`}, |
| 283 | } { |
| 284 | arr := BoolArray{true, true, true} |
| 285 | err := arr.Scan(tt.input) |
| 286 | |
| 287 | if err == nil { |
| 288 | t.Fatalf("Expected error for %q, got none", tt.input) |
| 289 | } |
| 290 | if !strings.Contains(err.Error(), tt.err) { |
| 291 | t.Errorf("Expected error to contain %q for %q, got %q", tt.err, tt.input, err) |
| 292 | } |
| 293 | if !reflect.DeepEqual(arr, BoolArray{true, true, true}) { |
| 294 | t.Errorf("Expected destination not to change for %q, got %+v", tt.input, arr) |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | func TestBoolArrayValue(t *testing.T) { |
| 300 | result, err := BoolArray(nil).Value() |