MCPcopy Create free account
hub / github.com/francoispqt/gojay / TestEncoderNumberEncodeAPI

Function TestEncoderNumberEncodeAPI

encode_number_test.go:13–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestEncoderNumberEncodeAPI(t *testing.T) {
14 t.Run("encoder-int", func(t *testing.T) {
15 builder := &strings.Builder{}
16 enc := NewEncoder(builder)
17 err := enc.EncodeInt(1)
18 assert.Nil(t, err, "Error should be nil")
19 assert.Equal(
20 t,
21 `1`,
22 builder.String(),
23 "Result of marshalling is different as the one expected")
24 })
25 t.Run("encode-int64", func(t *testing.T) {
26 builder := &strings.Builder{}
27 enc := NewEncoder(builder)
28 err := enc.EncodeInt64(math.MaxInt64)
29 assert.Nil(t, err, "Error should be nil")
30 assert.Equal(
31 t,
32 fmt.Sprintf("%d", math.MaxInt64),
33 builder.String(),
34 "Result of marshalling is different as the one expected")
35 })
36 t.Run("encode-uint64", func(t *testing.T) {
37 builder := &strings.Builder{}
38 enc := NewEncoder(builder)
39 err := enc.EncodeUint64(uint64(math.MaxUint64))
40 assert.Nil(t, err, "Error should be nil")
41 assert.Equal(
42 t,
43 fmt.Sprintf("%d", uint64(math.MaxUint64)),
44 builder.String(),
45 "Result of marshalling is different as the one expected")
46 })
47 t.Run("encode-float64", func(t *testing.T) {
48 builder := &strings.Builder{}
49 enc := NewEncoder(builder)
50 err := enc.EncodeFloat(float64(1.1))
51 assert.Nil(t, err, "Error should be nil")
52 assert.Equal(
53 t,
54 `1.1`,
55 builder.String(),
56 "Result of marshalling is different as the one expected")
57 })
58 t.Run("encode-float32", func(t *testing.T) {
59 builder := &strings.Builder{}
60 enc := NewEncoder(builder)
61 err := enc.EncodeFloat32(float32(1.12))
62 assert.Nil(t, err, "Error should be nil")
63 assert.Equal(
64 t,
65 `1.12`,
66 builder.String(),
67 "Result of marshalling is different as the one expected")
68
69 })
70}

Callers

nothing calls this directly

Calls 7

EncodeIntMethod · 0.95
EncodeInt64Method · 0.95
EncodeUint64Method · 0.95
EncodeFloatMethod · 0.95
EncodeFloat32Method · 0.95
NewEncoderFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…