-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnoscript_test.go
More file actions
44 lines (40 loc) · 1.26 KB
/
Copy pathnoscript_test.go
File metadata and controls
44 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package smallprox
import (
"bytes"
"strings"
"testing"
"golang.org/x/exp/errors"
)
func TestNoscript(t *testing.T) {
for _, test := range noscriptTests {
input := test[0]
t.Logf("Input: `%s`", input)
expect := test[1]
outputbuf := &strings.Builder{}
inputbuf := bytes.NewBufferString(input)
err := noscriptStreamer(inputbuf, outputbuf)
if err != nil {
t.Error(err)
continue
}
output := outputbuf.String()
t.Logf("Output: `%s`", output)
if expect != output {
t.Logf("Expect: `%s`", expect)
t.Error(errors.New("Did not get expected output"))
continue
}
}
}
var noscriptTests = [][]string{
[]string{" foo bar ", " foo bar "},
[]string{" <b > bold </b > ", " <b > bold </b > "},
[]string{" <button onclick='stuff()'>foo</button> ", " <button>foo</button> "},
[]string{" <script/> foo ", " foo "},
[]string{" <script>x</script> foo ", " foo "},
[]string{" <script> <script/> x() </script> foo ", " foo "},
[]string{" <script> a() <script> b() </script> x() </script> foo ", " x() foo "},
[]string{" foo <noscript>x</noscript> bar ", " foo <div data-from-noscript=true>x</div> bar "},
[]string{`<a href="/asdf">foo</a>`, `<a href="/asdf">foo</a>`},
[]string{`<a href="javascript:x()">foo</a>`, `<a href=#noscript>foo</a>`},
}