MCPcopy Create free account
hub / github.com/segmentio/encoding / TestAppendEscape

Function TestAppendEscape

json/json_test.go:1855–1896  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1853}
1854
1855func TestAppendEscape(t *testing.T) {
1856 t.Run("basic", func(t *testing.T) {
1857 b := AppendEscape([]byte{}, `value`, AppendFlags(0))
1858 exp := []byte(`"value"`)
1859 if !bytes.Equal(exp, b) {
1860 t.Error(
1861 "unexpected encoding:",
1862 "expected", exp,
1863 "got", b,
1864 )
1865 }
1866 })
1867
1868 t.Run("escaped", func(t *testing.T) {
1869 b := AppendEscape([]byte{}, `"escaped" <value>`, EscapeHTML)
1870 exp := []byte(`"\"escaped\"\t\u003cvalue\u003e"`)
1871 if !bytes.Equal(exp, b) {
1872 t.Error(
1873 "unexpected encoding:",
1874 "expected", exp,
1875 "got", b,
1876 )
1877 }
1878 })
1879
1880 t.Run("build", func(t *testing.T) {
1881 b := []byte{}
1882 b = append(b, '{')
1883 b = AppendEscape(b, `key`, EscapeHTML)
1884 b = append(b, ':')
1885 b = AppendEscape(b, `"escaped" <value>`, EscapeHTML)
1886 b = append(b, '}')
1887 exp := []byte(`{"key":"\"escaped\"\t\u003cvalue\u003e"}`)
1888 if !bytes.Equal(exp, b) {
1889 t.Error(
1890 "unexpected encoding:",
1891 "expected", exp,
1892 "got", b,
1893 )
1894 }
1895 })
1896}
1897
1898func TestUnescapeString(t *testing.T) {
1899 b := Unescape([]byte(`"value"`))

Callers

nothing calls this directly

Calls 3

AppendEscapeFunction · 0.85
AppendFlagsTypeAlias · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…