-
Notifications
You must be signed in to change notification settings - Fork 11
/
stringScanner_test.go
57 lines (41 loc) · 1.01 KB
/
stringScanner_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package decimal
import (
"strings"
"testing"
"unicode"
)
func TestStringScannerSkipSpace(t *testing.T) {
t.Parallel()
state := &scanner{reader: strings.NewReader(" \tx")}
state.SkipSpace()
r, size, err := state.ReadRune()
isnil(t, err)
equal(t, 1, size)
equal(t, 'x', r)
nopanic(t, func() { state.SkipSpace() })
}
func TestStringScannerTokenSkipSpace(t *testing.T) {
t.Parallel()
state := &scanner{reader: strings.NewReader(" \txyz")}
token, err := state.Token(false, unicode.IsLetter)
isnil(t, err)
equal(t, 0, len(token))
token, err = state.Token(true, unicode.IsLetter)
isnil(t, err)
equal(t, "xyz", string(token))
}
func TestStringScannerRead(t *testing.T) {
t.Parallel()
state := &scanner{reader: strings.NewReader("hello world!")}
var hello [5]byte
var world [10]byte
n, err := state.Read(hello[:])
isnil(t, err)
equal(t, 5, n)
equal(t, "hello", string(hello[:]))
state.SkipSpace()
n, err = state.Read(world[:])
isnil(t, err)
equal(t, 6, n)
equal(t, "world!", string(world[:n]))
}