| 1 |
package common |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/pkg/errors" |
| 7 |
) |
| 8 |
|
| 9 |
func TestNewLogicalValue(t *testing.T) { |
| 10 |
vectors := []struct { |
| 11 |
s string |
| 12 |
expected LogicalValue |
| 13 |
wantErr error |
| 14 |
}{{ |
| 15 |
s: `ANY`, |
| 16 |
expected: LogicalValue{Any: true}, |
| 17 |
}, { |
| 18 |
s: `NA`, |
| 19 |
expected: LogicalValue{Na: true}, |
| 20 |
}, { |
| 21 |
s: `any`, |
| 22 |
expected: LogicalValue{Any: true}, |
| 23 |
}, { |
| 24 |
s: `na`, |
| 25 |
expected: LogicalValue{Na: true}, |
| 26 |
}, { |
| 27 |
s: `invalid`, |
| 28 |
wantErr: ErrIllegalArgument, |
| 29 |
}, |
| 30 |
} |
| 31 |
|
| 32 |
for i, v := range vectors { |
| 33 |
actual, err := NewLogicalValue(v.s) |
| 34 |
if errors.Cause(err) != v.wantErr { |
| 35 |
t.Errorf("test %d, Error: got %v, want %v", i, errors.Cause(err), v.wantErr) |
| 36 |
} |
| 37 |
if err != nil { |
| 38 |
continue |
| 39 |
} |
| 40 |
if actual != v.expected { |
| 41 |
t.Errorf("test %d, Result: got %v, want %v", i, actual, v.expected) |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
func TestIsANY(t *testing.T) { |
| 47 |
vectors := []struct { |
| 48 |
lv LogicalValue |
| 49 |
expected bool |
| 50 |
}{{ |
| 51 |
lv: LogicalValue{Any: true, Na: false}, |
| 52 |
expected: true, |
| 53 |
}, { |
| 54 |
lv: LogicalValue{Any: false, Na: true}, |
| 55 |
expected: false, |
| 56 |
}, |
| 57 |
} |
| 58 |
|
| 59 |
for i, v := range vectors { |
| 60 |
actual := v.lv.IsANY() |
| 61 |
if actual != v.expected { |
| 62 |
t.Errorf("test %d, Result: got %v, want %v", i, actual, v.expected) |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
func TestIsNA(t *testing.T) { |
| 68 |
vectors := []struct { |
| 69 |
lv LogicalValue |
| 70 |
expected bool |
| 71 |
}{{ |
| 72 |
lv: LogicalValue{Any: true, Na: false}, |
| 73 |
expected: false, |
| 74 |
}, { |
| 75 |
lv: LogicalValue{Any: false, Na: true}, |
| 76 |
expected: true, |
| 77 |
}, |
| 78 |
} |
| 79 |
|
| 80 |
for i, v := range vectors { |
| 81 |
actual := v.lv.IsNA() |
| 82 |
if actual != v.expected { |
| 83 |
t.Errorf("test %d, Result: got %v, want %v", i, actual, v.expected) |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
func TestLogicalValueString(t *testing.T) { |
| 89 |
vectors := []struct { |
| 90 |
lv LogicalValue |
| 91 |
expected string |
| 92 |
}{{ |
| 93 |
lv: LogicalValue{Any: true, Na: false}, |
| 94 |
expected: "ANY", |
| 95 |
}, { |
| 96 |
lv: LogicalValue{Any: false, Na: true}, |
| 97 |
expected: "NA", |
| 98 |
}, |
| 99 |
} |
| 100 |
|
| 101 |
for i, v := range vectors { |
| 102 |
actual := v.lv.String() |
| 103 |
if actual != v.expected { |
| 104 |
t.Errorf("test %d, Result: got %v, want %v", i, actual, v.expected) |
| 105 |
} |
| 106 |
} |
| 107 |
} |