-
Notifications
You must be signed in to change notification settings - Fork 55
/
scanner_test.go
36 lines (32 loc) · 906 Bytes
/
scanner_test.go
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
package robotstxt
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestScanner(t *testing.T) {
t.Parallel()
type tcase struct {
input string
expect []string
errCount int
}
cases := []tcase{
{"foo", []string{"foo"}, 0},
{"\u2010", []string{"‐"}, 0},
{"# comment \r\nSomething: Somewhere\r\n", []string{tokEOL, "Something", "Somewhere", tokEOL}, 0},
{"# comment \r\n# more comments\n\nDisallow:\r", []string{tokEOL, tokEOL, "Disallow", tokEOL}, 0},
{"\xef\xbb\xbfUser-agent: *\n", []string{"User-agent", "*", tokEOL}, 0},
{"\xd9\xd9", []string{"\uFFFD\uFFFD"}, 2},
}
for i, c := range cases {
tag := fmt.Sprintf("test-%d", i)
t.Run(tag, func(t *testing.T) {
sc := newByteScanner(tag, true)
sc.feed([]byte(c.input), true)
tokens := sc.scanAll()
assert.Equal(t, c.errCount, sc.ErrorCount)
assert.Equal(t, c.expect, tokens)
})
}
}