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