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",
67 // Handle single ampersand.
69 "copySingleAmpersand",
73 // Handle ampersand followed by non-entity.
75 "copyAmpersandNonEntity",
87 func TestUnescape(t
*testing
.T
) {
88 for _
, tt
:= range unescapeTests
{
89 unescaped
:= UnescapeString(tt
.html
)
90 if unescaped
!= tt
.unescaped
{
91 t
.Errorf("TestUnescape %s: want %q, got %q", tt
.desc
, tt
.unescaped
, unescaped
)
96 func TestUnescapeEscape(t
*testing
.T
) {
106 `"<&>"`,
107 `3&5==1 && 0<1, "0<1", a+acute=á`,
108 `The special characters are: <, >, &, ' and "`,
110 for _
, s
:= range ss
{
111 if got
:= UnescapeString(EscapeString(s
)); got
!= s
{
112 t
.Errorf("got %q want %q", got
, s
)