-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examplefields_test.go
53 lines (44 loc) · 1.05 KB
/
examplefields_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
package bbs_test
import (
"errors"
"fmt"
"log"
"strings"
"github.com/bengarrett/bbs"
)
func ExampleFields() {
r := strings.NewReader("@X03Hello @XF0world")
s, b, err := bbs.Fields(r)
if err != nil {
log.Print(err)
}
fmt.Printf("Found %d, %s sequences\n", len(s), b)
for i, item := range s {
fmt.Printf("Sequence %d: %q\n", i+1, item)
}
// Output: Found 2, PCBoard @X sequences
// Sequence 1: "03Hello "
// Sequence 2: "F0world"
//
}
func ExampleFields_ansi() {
const reset = "\x1b[0m" // an ANSI escape sequence to reset the terminal
r := strings.NewReader(reset + "Hello world")
s, b, err := bbs.Fields(r)
if errors.Is(err, bbs.ErrANSI) {
fmt.Printf("error: %s", err)
return
}
fmt.Printf("Found %d, %s sequences\n", len(s), b)
// Output: error: ansi escape code found
}
func ExampleFields_none() {
r := strings.NewReader("Hello world")
s, b, err := bbs.Fields(r)
if errors.Is(err, bbs.ErrNone) {
fmt.Printf("error: %s", err)
return
}
fmt.Printf("Found %d, %s sequences\n", len(s), b)
// Output: error: no bbs color code found
}