(t *testing.T)
| 19 | } |
| 20 | |
| 21 | func TestReadIntf(t *testing.T) { |
| 22 | // NOTE: if you include cases |
| 23 | // with, say, int32s, the test |
| 24 | // will fail, b/c integers are |
| 25 | // always read out as int64, and |
| 26 | // unsigned integers as uint64 |
| 27 | |
| 28 | testCases := []any{ |
| 29 | float64(128.032), |
| 30 | float32(9082.092), |
| 31 | int64(-40), |
| 32 | uint64(9082981), |
| 33 | time.Now(), |
| 34 | 48*time.Hour + 3*time.Minute + 2*time.Second + 3*time.Nanosecond, |
| 35 | "hello!", |
| 36 | []byte("hello!"), |
| 37 | map[string]any{ |
| 38 | "thing-1": "thing-1-value", |
| 39 | "thing-2": int64(800), |
| 40 | "thing-3": []byte("some inner bytes..."), |
| 41 | "thing-4": false, |
| 42 | }, |
| 43 | } |
| 44 | |
| 45 | var buf bytes.Buffer |
| 46 | var v any |
| 47 | dec := NewReader(&buf) |
| 48 | enc := NewWriter(&buf) |
| 49 | |
| 50 | for i, ts := range testCases { |
| 51 | buf.Reset() |
| 52 | err := enc.WriteIntf(ts) |
| 53 | if err != nil { |
| 54 | t.Errorf("Test case %d: %s", i, err) |
| 55 | continue |
| 56 | } |
| 57 | err = enc.Flush() |
| 58 | if err != nil { |
| 59 | t.Fatal(err) |
| 60 | } |
| 61 | v, err = dec.ReadIntf() |
| 62 | if err != nil { |
| 63 | t.Errorf("Test case: %d: %s", i, err) |
| 64 | } |
| 65 | |
| 66 | /* for time, use time.Equal instead of reflect.DeepEqual */ |
| 67 | if tm, ok := v.(time.Time); ok { |
| 68 | if !tm.Equal(v.(time.Time)) { |
| 69 | t.Errorf("%v != %v", ts, v) |
| 70 | } |
| 71 | } else if intd, ok := ts.(time.Duration); ok { |
| 72 | /* for time.Duration, cast before comparing */ |
| 73 | outtd := time.Duration(v.(int64)) |
| 74 | if intd != outtd { |
| 75 | t.Errorf("%v in; %v out", intd, outtd) |
| 76 | } |
| 77 | } else if !reflect.DeepEqual(v, ts) { |
| 78 | t.Errorf("%v in; %v out", ts, v) |
nothing calls this directly
no test coverage detected
searching dependent graphs…