93 lines
2.0 KiB
Go
93 lines
2.0 KiB
Go
|
package helper
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func Test_htmlSpecialChars(t *testing.T) {
|
||
|
type args struct {
|
||
|
text string
|
||
|
flags int
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want string
|
||
|
}{
|
||
|
{
|
||
|
name: "t1",
|
||
|
args: args{text: "<a href='test'>Test</a>", flags: EntQuotes},
|
||
|
want: "<a href='test'>Test</a>",
|
||
|
}, {
|
||
|
name: "t2",
|
||
|
args: args{text: "<a href='test'>Test</a>", flags: EntCompat},
|
||
|
want: "<a href='test'>Test</a>",
|
||
|
}, {
|
||
|
name: "t3",
|
||
|
args: args{text: "<a href='test'>T est</a>", flags: EntCompat | EntSpace},
|
||
|
want: "<a href='test'>T est</a>",
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := htmlSpecialChars(tt.args.text, tt.args.flags); got != tt.want {
|
||
|
t.Errorf("htmlSpecialChars() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Test_htmlSpecialCharsDecode(t *testing.T) {
|
||
|
type args struct {
|
||
|
text string
|
||
|
flags int
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
want string
|
||
|
}{
|
||
|
{
|
||
|
name: "t1",
|
||
|
args: args{
|
||
|
text: "<a href='test'>Test</a>",
|
||
|
flags: EntCompat,
|
||
|
},
|
||
|
want: "<a href='test'>Test</a>",
|
||
|
}, {
|
||
|
name: "t2",
|
||
|
args: args{
|
||
|
text: "<a href='test'>Test</a>",
|
||
|
flags: EntQuotes,
|
||
|
},
|
||
|
want: "<a href='test'>Test</a>",
|
||
|
}, {
|
||
|
name: "t3",
|
||
|
args: args{
|
||
|
text: "<p>this -> "</p>\n",
|
||
|
flags: EntNoQuotes,
|
||
|
},
|
||
|
want: "<p>this -> "</p>\n",
|
||
|
}, {
|
||
|
name: "t4",
|
||
|
args: args{
|
||
|
text: "<p>this -> "</p>\n",
|
||
|
flags: EntCompat,
|
||
|
},
|
||
|
want: "<p>this -> \"</p>\n",
|
||
|
}, {
|
||
|
name: "t5",
|
||
|
args: args{
|
||
|
text: "<p>this -> "</p>\n",
|
||
|
flags: EntCompat | EntSpace,
|
||
|
},
|
||
|
want: "<p>this -> \"</p>\n",
|
||
|
},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := htmlSpecialCharsDecode(tt.args.text, tt.args.flags); got != tt.want {
|
||
|
t.Errorf("htmlSpecialCharsDecode() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|