Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test and benchmark for unicode #11

Merged
merged 3 commits into from
May 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion jingo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,47 @@ func Test_NilStruct(t *testing.T) {
}
}

//
type UnicodeObject struct {
Chinese string `json:"chinese"`
Emoji string `json:"emoji"`
Russian string `json:"russian"`
}

func Test_Unicode(t *testing.T) {
ub := UnicodeObject{
Chinese: "你好,世界",
Emoji: "👋🌍😄😂👋💊🐂🍺",
Russian: "ру́сский язы́к",
}

wantJSON := "{\"chinese\":\"你好,世界\",\"emoji\":\"👋🌍😄😂👋💊🐂🍺\",\"russian\":\"ру́сский язы́к\"}"

var enc = NewStructEncoder(UnicodeObject{})
buf := NewBufferFromPool()
enc.Marshal(&ub, buf)
resultJSON := buf.String()
if resultJSON != wantJSON {
t.Errorf("Test_UnicodeEncode Failed: want JSON:" + wantJSON + " got JSON:" + resultJSON)
}

}

func BenchmarkUnicode(b *testing.B) {
ub := UnicodeObject{
Chinese: "你好,世界",
Emoji: "👋🌍😄😂💊🐂🍺",
Russian: "ру́сский язы́к",
}

var enc = NewStructEncoder(UnicodeObject{})

b.StartTimer()
for i := 0; i < b.N; i++ {
buf := NewBufferFromPool()
enc.Marshal(&ub, buf)
buf.ReturnToPool()
}
}

// var fakeType = SmallPayload{}
// var fake = NewSmallPayload()
Expand Down