File: example_test.go

package info (click to toggle)
golang-github-leodido-ragel-machinery 0.0~git20181214.299bdde-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 116 kB
  • sloc: makefile: 26
file content (57 lines) | stat: -rw-r--r-- 812 bytes parent folder | download | duplicates (2)
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 examples

import (
	"fmt"
	"strings"
)

func Example_newlines() {
	in := `example 0
example 1
example 2
example X
`

	results := (&newlinesMachine{}).Parse(strings.NewReader(in))

	for _, elem := range results {
		fmt.Println("RECV", elem)
	}
	// Output:
	// OnEOF
	// OnCompletion
	// RECV example 0
	// RECV example 1
	// RECV example 2
}

func Example_multiline() {
	in := `$1
2
$3
`
	fsm := &multilineMachine{}
	fsm.Parse(strings.NewReader(in))
	for _, item := range fsm.items {
		fmt.Println("RECV", item)
	}
	// Output:
	// OnEOF
	// OnCompletion
	// RECV $1
	// 2
	// RECV $3
}

func Example_multiline_err() {
	in := `$1`
	fsm := &multilineMachine{}
	fsm.Parse(strings.NewReader(in))
	for _, item := range fsm.items {
		fmt.Println("RECV", item)
	}
	// Output:
	// OnErr
	// $1
	// OnCompletion
}