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