parser - reader_test.go
1 package parser_test
2
3 import (
4 "fmt"
5 "strings"
6 "testing"
7
8 "vimagination.zapto.org/parser"
9 )
10
11 func TestReaderAccept(t *testing.T) {
12 testTokeniserAccept(t, parser.NewReaderTokeniser(strings.NewReader("ABC£")))
13 }
14
15 func TestReaderAcceptRun(t *testing.T) {
16 testTokeniserAcceptRun(t, parser.NewReaderTokeniser(strings.NewReader("123ABC££$$%%^^\n")))
17 }
18
19 func TestReaderExcept(t *testing.T) {
20 testTokeniserExcept(t, parser.NewReaderTokeniser(strings.NewReader("123")))
21 }
22
23 func TestReaderExceptRun(t *testing.T) {
24 testTokeniserExceptRun(t, parser.NewReaderTokeniser(strings.NewReader("12345ABC\n67890DEF\nOH MY!")))
25 }
26
27 func ExampleNewReaderTokeniser() {
28 p := parser.NewReaderTokeniser(strings.NewReader("Hello, World!"))
29 alphaNum := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
30 p.AcceptRun(alphaNum)
31 word := p.Get()
32 fmt.Println("got word:", word)
33
34 p.ExceptRun(alphaNum)
35 p.Get()
36
37 p.AcceptRun(alphaNum)
38 word = p.Get()
39 fmt.Println("got word:", word)
40 // Output:
41 // got word: Hello
42 // got word: World
43 }