Skip to content

Commit

Permalink
使用sonic包
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Nov 20, 2024
1 parent 1901938 commit 9fd9d59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions test/collection_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package test

import (
"encoding/json"
"testing"

"github.com/bytedance/sonic"
"github.com/farseer-go/collections"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -78,7 +78,7 @@ func Test_collection_RemoveAll(t *testing.T) {
func TestCollection_MarshalJSON(t *testing.T) {
lst := collections.NewList[int](1, 2, 3, 6)
strjson, _ := lst.MarshalJSON()
retjson, _ := json.Marshal(lst)
retjson, _ := sonic.Marshal(lst)
assert.Equal(t, retjson, strjson)
}

Expand Down
9 changes: 5 additions & 4 deletions test/dictionary_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package test

import (
"encoding/json"
"errors"
"fmt"
"testing"

"github.com/bytedance/sonic"
"github.com/farseer-go/collections"
"github.com/stretchr/testify/assert"
"testing"
)

func Test_dictionary_Values(t *testing.T) {
Expand Down Expand Up @@ -211,10 +212,10 @@ func TestDictionary_IsNil(t *testing.T) {
func TestDictionaryJson(t *testing.T) {
var dic collections.Dictionary[int, int]
assert.True(t, dic.IsNil())
marshal, _ := json.Marshal(dic)
marshal, _ := sonic.Marshal(dic)
assert.Equal(t, "{}", string(marshal))

_ = json.Unmarshal([]byte("{}"), &dic)
_ = sonic.Unmarshal([]byte("{}"), &dic)
assert.False(t, dic.IsNil())
}

Expand Down
11 changes: 6 additions & 5 deletions test/list_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package test

import (
"encoding/json"
"reflect"
"testing"

"github.com/bytedance/sonic"
"github.com/farseer-go/collections"
"github.com/farseer-go/fs/types"
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)

func TestList_AsEnumerable(t *testing.T) {
Expand Down Expand Up @@ -100,10 +101,10 @@ func TestNil(t *testing.T) {

func TestListJson(t *testing.T) {
var lst collections.List[int]
marshal, _ := json.Marshal(lst)
marshal, _ := sonic.Marshal(lst)
assert.Equal(t, "[]", string(marshal))

_ = json.Unmarshal([]byte("[]"), &lst)
_ = sonic.Unmarshal([]byte("[]"), &lst)
assert.False(t, lst.IsNil())
}

Expand Down

0 comments on commit 9fd9d59

Please sign in to comment.