...

Source file src/github.com/mailru/easyjson/tests/html_test.go

Documentation: github.com/mailru/easyjson/tests

     1  package tests
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mailru/easyjson/jwriter"
     7  )
     8  
     9  func TestHTML(t *testing.T) {
    10  	s := Struct{
    11  		Test: "<b>test</b>",
    12  	}
    13  
    14  	j := jwriter.Writer{
    15  		NoEscapeHTML: false,
    16  	}
    17  	s.MarshalEasyJSON(&j)
    18  
    19  	data, _ := j.BuildBytes()
    20  
    21  	if string(data) != `{"Test":"\u003cb\u003etest\u003c/b\u003e"}` {
    22  		t.Fatal("EscapeHTML error:", string(data))
    23  	}
    24  
    25  	j.NoEscapeHTML = true
    26  	s.MarshalEasyJSON(&j)
    27  
    28  	data, _ = j.BuildBytes()
    29  
    30  	if string(data) != `{"Test":"<b>test</b>"}` {
    31  		t.Fatal("NoEscapeHTML error:", string(data))
    32  	}
    33  }
    34  

View as plain text