-
Notifications
You must be signed in to change notification settings - Fork 2
/
stream_test.go
47 lines (40 loc) · 1.14 KB
/
stream_test.go
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
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package json
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/wal-g/json/mocks"
)
func TestRawMessage(t *testing.T) {
var data struct {
X float64
Id RawMessage
Y float32
}
const raw = `["\u0056",null]`
const msg = `{"X":0.1,"Id":["\u0056",null],"Y":0.2}`
require.NoError(t, Unmarshal(strings.NewReader(msg), &data))
require.Equal(t, raw, string(data.Id))
buf := mocks.NewBuildCloser()
require.NoError(t, Marshal(&data, buf))
assert.Equal(t, msg, buf.String())
}
func TestNullRawMessage(t *testing.T) {
var data struct {
X float64
Id RawMessage
IdPtr *RawMessage
Y float32
}
const msg = `{"X":0.1,"Id":null,"IdPtr":null,"Y":0.2}`
require.NoError(t, Unmarshal(strings.NewReader(msg), &data))
require.Equal(t, "null", string(data.Id))
require.Equal(t, (*RawMessage)(nil), data.IdPtr)
buf := mocks.NewBuildCloser()
require.NoError(t, Marshal(&data, buf))
assert.Equal(t, msg, buf.String())
}