Merge pull request #252 from GoWebProd/master

Add test for NoEscapeHTML
This commit is contained in:
Vasily Romanov
2019-10-09 12:02:05 +03:00
committed by GitHub
3 changed files with 40 additions and 0 deletions
+2
View File
@@ -18,10 +18,12 @@ generate: build
./tests/custom_map_key_type.go \
./tests/embedded_type.go \
./tests/reference_to_pointer.go \
./tests/html.go \
bin/easyjson -all ./tests/data.go
bin/easyjson -all ./tests/nothing.go
bin/easyjson -all ./tests/errors.go
bin/easyjson -all ./tests/html.go
bin/easyjson -snake_case ./tests/snake.go
bin/easyjson -omit_empty ./tests/omitempty.go
bin/easyjson -build_tags=use_easyjson ./benchmark/data.go
+5
View File
@@ -0,0 +1,5 @@
package tests
type Struct struct {
Test string
}
+33
View File
@@ -0,0 +1,33 @@
package tests
import (
"testing"
"github.com/mailru/easyjson/jwriter"
)
func TestHTML(t *testing.T) {
s := Struct{
Test: "<b>test</b>",
}
j := jwriter.Writer{
NoEscapeHTML: false,
}
s.MarshalEasyJSON(&j)
data, _ := j.BuildBytes()
if string(data) != `{"Test":"\u003cb\u003etest\u003c/b\u003e"}` {
t.Fatal("EscapeHTML error:", string(data))
}
j.NoEscapeHTML = true
s.MarshalEasyJSON(&j)
data, _ = j.BuildBytes()
if string(data) != `{"Test":"<b>test</b>"}` {
t.Fatal("NoEscapeHTML error:", string(data))
}
}