1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
9 type unescapeTest struct {
10 // A short description of the test case.
14 // The unescaped text.
18 var unescapeTests = []unescapeTest{
19 // Handle no entities.
25 // Handle simple named entities.
31 // Handle hitting the end of the string.
37 // Handle entities with two codepoints.
41 "text \u22db\ufe00 blah",
43 // Handle decimal numeric entities.
49 // Handle hexadecimal numeric entities.
52 "Lambda = λ = λ ",
55 // Handle numeric early termination.
58 "&# &#x €43 © = ©f = ©",
59 "&# &#x €43 © = ©f = ©",
61 // Handle numeric ISO-8859-1 entity replacements.
63 "numericReplacements",
69 func TestUnescape(t *testing.T) {
70 for _, tt := range unescapeTests {
71 unescaped := UnescapeString(tt.html)
72 if unescaped != tt.unescaped {
73 t.Errorf("TestUnescape %s: want %q, got %q", tt.desc, tt.unescaped, unescaped)
78 func TestUnescapeEscape(t *testing.T) {
88 `"<&>"`,
89 `3&5==1 && 0<1, "0<1", a+acute=á`,
90 `The special characters are: <, >, &, ' and "`,
92 for _, s := range ss {
93 if got := UnescapeString(EscapeString(s)); got != s {
94 t.Errorf("got %q want %q", got, s)