Skip to content

Commit

Permalink
remove test
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Feb 7, 2024
1 parent 73e333a commit 6d134b5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark-linux-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17.1
go-version: 1.22

- uses: actions/cache@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark-linux-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17.1
go-version: 1.22

- uses: actions/cache@v2
with:
Expand Down
58 changes: 58 additions & 0 deletions ast/api_amd64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,66 @@ import (

`github.com/bytedance/sonic/encoder`
`github.com/stretchr/testify/require`
`github.com/bytedance/sonic/internal/native/types`
`github.com/stretchr/testify/assert`
)

func TestEncodeValue(t *testing.T) {
obj := new(_TwitterStruct)
if err := json.Unmarshal([]byte(_TwitterJson), obj); err != nil {
t.Fatal(err)
}
// buf, err := encoder.Encode(obj, encoder.EscapeHTML|encoder.SortMapKeys)
buf, err := json.Marshal(obj)
if err != nil {
t.Fatal(err)
}
quote, err := json.Marshal(_TwitterJson)
if err != nil {
t.Fatal(err)
}
type Case struct {
node Node
exp string
err bool
}
input := []Case{
{NewNull(), "null", false},
{NewBool(true), "true", false},
{NewBool(false), "false", false},
{NewNumber("0.0"), "0.0", false},
{NewString(""), `""`, false},
{NewString(`\"\"`), `"\\\"\\\""`, false},
{NewString(_TwitterJson), string(quote), false},
{NewArray([]Node{}), "[]", false},
{NewArray([]Node{NewString(""), NewNull()}), `["",null]`, false},
{NewArray([]Node{NewBool(true), NewString("true"), NewString("\t")}), `[true,"true","\t"]`, false},
{NewObject([]Pair{Pair{"a", NewNull()}, Pair{"b", NewNumber("0")}}), `{"a":null,"b":0}`, false},
{NewObject([]Pair{Pair{"\ta", NewString("\t")}, Pair{"\bb", NewString("\b")}, Pair{"\nb", NewString("\n")}, Pair{"\ra", NewString("\r")}}),`{"\ta":"\t","\u0008b":"\u0008","\nb":"\n","\ra":"\r"}`, false},
{NewObject([]Pair{}), `{}`, false},
{NewObject([]Pair{Pair{Key: "", Value: NewNull()}}), `{"":null}`, false},
{NewBytes([]byte("hello, world")), `"aGVsbG8sIHdvcmxk"`, false},
{NewAny(obj), string(buf), false},
{NewRaw(`[{ }]`), "[{}]", false},
{Node{}, "", true},
{Node{t: types.ValueType(1)}, "", true},
}
for i, c := range input {
t.Log(i)
buf, err := json.Marshal(&c.node)
if c.err {
if err == nil {
t.Fatal(i)
}
continue
}
if err != nil {
t.Fatal(i, err)
}
assert.Equal(t, c.exp, string(buf))
}
}

func TestSortNodeTwitter(t *testing.T) {
root, err := NewSearcher(_TwitterJson).GetByPath()
if err != nil {
Expand Down
58 changes: 0 additions & 58 deletions ast/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
`sync`
`testing`

`github.com/bytedance/sonic/internal/native/types`
`github.com/stretchr/testify/assert`
`github.com/stretchr/testify/require`
)

Expand Down Expand Up @@ -63,62 +61,6 @@ func TestGC_Encode(t *testing.T) {
wg.Wait()
}

func TestEncodeValue(t *testing.T) {
obj := new(_TwitterStruct)
if err := json.Unmarshal([]byte(_TwitterJson), obj); err != nil {
t.Fatal(err)
}
// buf, err := encoder.Encode(obj, encoder.EscapeHTML|encoder.SortMapKeys)
buf, err := json.Marshal(obj)
if err != nil {
t.Fatal(err)
}
quote, err := json.Marshal(_TwitterJson)
if err != nil {
t.Fatal(err)
}
type Case struct {
node Node
exp string
err bool
}
input := []Case{
{NewNull(), "null", false},
{NewBool(true), "true", false},
{NewBool(false), "false", false},
{NewNumber("0.0"), "0.0", false},
{NewString(""), `""`, false},
{NewString(`\"\"`), `"\\\"\\\""`, false},
{NewString(_TwitterJson), string(quote), false},
{NewArray([]Node{}), "[]", false},
{NewArray([]Node{NewString(""), NewNull()}), `["",null]`, false},
{NewArray([]Node{NewBool(true), NewString("true"), NewString("\t")}), `[true,"true","\t"]`, false},
{NewObject([]Pair{Pair{"a", NewNull()}, Pair{"b", NewNumber("0")}}), `{"a":null,"b":0}`, false},
{NewObject([]Pair{Pair{"\ta", NewString("\t")}, Pair{"\bb", NewString("\b")}, Pair{"\nb", NewString("\n")}, Pair{"\ra", NewString("\r")}}),`{"\ta":"\t","\u0008b":"\u0008","\nb":"\n","\ra":"\r"}`, false},
{NewObject([]Pair{}), `{}`, false},
{NewObject([]Pair{Pair{Key: "", Value: NewNull()}}), `{"":null}`, false},
{NewBytes([]byte("hello, world")), `"aGVsbG8sIHdvcmxk"`, false},
{NewAny(obj), string(buf), false},
{NewRaw(`[{ }]`), "[{}]", false},
{Node{}, "", true},
{Node{t: types.ValueType(1)}, "", true},
}
for i, c := range input {
t.Log(i)
buf, err := json.Marshal(&c.node)
if c.err {
if err == nil {
t.Fatal(i)
}
continue
}
if err != nil {
t.Fatal(i, err)
}
assert.Equal(t, c.exp, string(buf))
}
}

func TestEncodeNode(t *testing.T) {
data := `{"a":[{},[],-0.1,true,false,null,""],"b":0,"c":true,"d":false,"e":null,"g":""}`
root, e := NewSearcher(data).GetByPath()
Expand Down

0 comments on commit 6d134b5

Please sign in to comment.