MCPcopy
hub / github.com/tinylib/msgp / TestNumber

Function TestNumber

msgp/number_test.go:9–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestNumber(t *testing.T) {
10 n := Number{}
11
12 if n.Type() != IntType {
13 t.Errorf("expected zero-value type to be %s; got %s", IntType, n.Type())
14 }
15
16 if n.String() != "0" {
17 t.Errorf("expected Number{}.String() to be \"0\" but got %q", n.String())
18 }
19
20 n.AsInt(248)
21 i, ok := n.Int()
22 if !ok || i != 248 || n.Type() != IntType || n.String() != "248" {
23 t.Errorf("%d in; %d out!", 248, i)
24 }
25
26 n.AsFloat64(3.141)
27 f, ok := n.Float()
28 if !ok || f != 3.141 || n.Type() != Float64Type || n.String() != "3.141" {
29 t.Errorf("%f in; %f out!", 3.141, f)
30 }
31
32 n.AsUint(40000)
33 u, ok := n.Uint()
34 if !ok || u != 40000 || n.Type() != UintType || n.String() != "40000" {
35 t.Errorf("%d in; %d out!", 40000, u)
36 }
37
38 nums := []any{
39 float64(3.14159),
40 int64(-29081),
41 uint64(90821983),
42 float32(3.141),
43 }
44
45 var dat []byte
46 var buf bytes.Buffer
47 wr := NewWriter(&buf)
48 for _, n := range nums {
49 dat, _ = AppendIntf(dat, n)
50 wr.WriteIntf(n)
51 }
52 wr.Flush()
53
54 mout := make([]Number, len(nums))
55 dout := make([]Number, len(nums))
56
57 rd := NewReader(&buf)
58 unm := dat
59 for i := range nums {
60 var err error
61 unm, err = mout[i].UnmarshalMsg(unm)
62 if err != nil {
63 t.Fatal("unmarshal error:", err)
64 }
65 err = dout[i].DecodeMsg(rd)
66 if err != nil {

Callers

nothing calls this directly

Calls 15

TypeMethod · 0.95
StringMethod · 0.95
AsIntMethod · 0.95
IntMethod · 0.95
AsFloat64Method · 0.95
FloatMethod · 0.95
AsUintMethod · 0.95
UintMethod · 0.95
WriteIntfMethod · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
AppendIntfFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…