@@ -4,17 +4,27 @@ import (
4
4
"testing"
5
5
)
6
6
7
- var stripTests = []struct {
8
- v string
9
- want string
10
- }{
11
- {"<h1>Hello World</h1>" , "Hello World" }}
12
-
13
7
func TestStripTags (t * testing.T ) {
14
- for _ , tt := range stripTests {
15
- got := StripTags (tt .v )
16
- if got != tt .want {
17
- t .Errorf ("StripTags(%v): want %v, got %v" , tt .v , tt .want , got )
8
+ tests := []struct {
9
+ input , want string
10
+ }{
11
+ {"" , "" },
12
+ {"Hello, World!" , "Hello, World!" },
13
+ {"foo&bar" , "foo&bar" },
14
+ {`Hello <a href="www.example.com/">World</a>!` , "Hello World!" },
15
+ {"Foo <textarea>Bar</textarea> Baz" , "Foo Bar Baz" },
16
+ {"Foo <!-- Bar --> Baz" , "Foo Baz" },
17
+ {"<" , "<" },
18
+ {"foo < bar" , "foo < bar" },
19
+ {`Foo<script type="text/javascript">alert(1337)</script>Bar` , "FooBar" },
20
+ {`Foo<div title="1>2">Bar` , "FooBar" },
21
+ {`I <3 Ponies!` , `I <3 Ponies!` },
22
+ {`<script>foo()</script>` , `` },
23
+ }
24
+
25
+ for _ , test := range tests {
26
+ if got := StripTags (test .input ); got != test .want {
27
+ t .Errorf ("%q: want %q, got %q" , test .input , test .want , got )
18
28
}
19
29
}
20
30
}
0 commit comments