| 1 |
package gox |
| 2 |
|
| 3 |
import ( |
| 4 |
"errors" |
| 5 |
"fmt" |
| 6 |
"reflect" |
| 7 |
"testing" |
| 8 |
"time" |
| 9 |
) |
| 10 |
|
| 11 |
func TestPie(t *testing.T) { |
| 12 |
Pie(nil) |
| 13 |
|
| 14 |
var wasPanic bool |
| 15 |
func() { |
| 16 |
defer func() { |
| 17 |
if x := recover(); x != nil { |
| 18 |
wasPanic = true |
| 19 |
} |
| 20 |
}() |
| 21 |
Pie(errors.New("test error")) |
| 22 |
}() |
| 23 |
if !wasPanic { |
| 24 |
t.Errorf("Expected panic!") |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
func ExampleWrap() { |
| 30 |
now := time.Date(2020, 3, 4, 0, 0, 0, 0, time.UTC) |
| 31 |
|
| 32 |
fmt.Printf("Year: %d, month: %d, day: %d\n", |
| 33 |
Wrap(now.Date())...) |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
func TestWrap(t *testing.T) { |
| 40 |
cases := []struct { |
| 41 |
name string |
| 42 |
in []interface{} |
| 43 |
out []interface{} |
| 44 |
}{ |
| 45 |
{"nil", nil, nil}, |
| 46 |
{"empty", []interface{}{}, []interface{}{}}, |
| 47 |
{"one", []interface{}{1}, []interface{}{1}}, |
| 48 |
{"two", []interface{}{byte(1), "two"}, []interface{}{byte(1), "two"}}, |
| 49 |
} |
| 50 |
|
| 51 |
for _, c := range cases { |
| 52 |
if got := Wrap(c.in...); !reflect.DeepEqual(got, c.out) { |
| 53 |
t.Errorf("[%s] Expected: %#v, got: %#v", |
| 54 |
c.name, c.out, got) |
| 55 |
} |
| 56 |
} |
| 57 |
} |