-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examplebbs_test.go
279 lines (223 loc) · 5.67 KB
/
examplebbs_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package bbs_test
import (
"bytes"
"fmt"
"strings"
"github.com/bengarrett/bbs"
)
func ExampleCelerityHTML() {
src := []byte("|cHello |C|S|wworld")
var buf bytes.Buffer
if err := bbs.CelerityHTML(&buf, src); err != nil {
fmt.Print(err)
}
fmt.Print(buf.String())
// Output: <i class="PBk PFc">Hello </i><i class="PBk PFC"></i><i class="PBw PFC">world</i>
}
func ExampleIsCelerity() {
src := []byte("|cHello |C|S|wworld")
fmt.Print(bbs.IsCelerity(src))
// Output: true
}
func ExampleIsPCBoard() {
src := []byte("@X03Hello world")
fmt.Print(bbs.IsPCBoard(src))
// Output: true
}
func ExampleIsRenegade() {
src := []byte("|03Hello |07|19world")
fmt.Print(bbs.IsRenegade(src))
// Output: true
}
func ExampleIsTelegard() {
const grave = "\u0060" // godoc treats a grave character as a special control
src := []byte(grave + "7Hello world")
fmt.Print(bbs.IsTelegard(src))
// Output: true
}
func ExampleIsWWIVHash() {
src := []byte("|#7Hello world")
fmt.Print(bbs.IsWWIVHash(src))
// Output: true
}
func ExampleIsWWIVHeart() {
src := []byte("\x037Hello world")
fmt.Print(bbs.IsWWIVHeart(src))
// Output: true
}
func ExampleIsWildcat() {
src := []byte("@0F@Hello world")
fmt.Print(bbs.IsWildcat(src))
// Output: true
}
func ExampleHTML() {
src := strings.NewReader("@X03Hello world")
var buf bytes.Buffer
r, err := bbs.HTML(&buf, src)
if err != nil {
fmt.Print(err)
return
}
fmt.Printf("<!-- %s code -->\n", r)
fmt.Print(buf.String())
// Output: <!-- PCBoard @X code -->
// <i class="PB0 PF3">Hello world</i>
}
func ExampleRenegadeHTML() {
src := []byte("|03Hello |07|19world")
var buf bytes.Buffer
if err := bbs.RenegadeHTML(&buf, src); err != nil {
fmt.Print(err)
}
fmt.Print(buf.String())
// Output: <i class="P0 P3">Hello </i><i class="P0 P7"></i><i class="P19 P7">world</i>
}
func ExamplePCBoardHTML() {
src := []byte("@X03Hello world")
var buf bytes.Buffer
if err := bbs.PCBoardHTML(&buf, src); err != nil {
fmt.Print(err)
}
fmt.Print(buf.String())
// Output: <i class="PB0 PF3">Hello world</i>
}
func ExampleTrimControls() {
src := []byte("@CLS@@PAUSE@Hello world")
fmt.Printf("%q trims to %s", src, string(bbs.TrimControls(src)))
// Output: "@CLS@@PAUSE@Hello world" trims to Hello world
}
func ExampleFind() {
src := strings.NewReader("@X03Hello world")
f := bbs.Find(src)
fmt.Printf("Found %s text", f.Name())
// Output: Found PCBoard text
}
func ExampleFind_none() {
src := strings.NewReader("Hello world")
f := bbs.Find(src)
if !f.Valid() {
fmt.Print("Found plain text")
return
}
fmt.Printf("Found %s text", f.Name())
// Output: Found plain text
}
func ExampleFind_ansi() {
const reset = "\x1b[0m" // an ANSI escape sequence to reset the terminal
src := strings.NewReader(reset + "Hello world")
f := bbs.Find(src)
if !f.Valid() {
fmt.Print("Found plain text")
return
}
fmt.Printf("Found %s text", f.Name())
// Output: Found ANSI text
}
func ExampleBBS_Bytes() {
b := bbs.PCBoard.Bytes()
fmt.Printf("Code as bytes %v\n", b)
fmt.Printf("Code as string %s", b)
// Output: Code as bytes [64 88]
// Code as string @X
}
func ExampleBBS_CSS() {
var css bytes.Buffer
if err := bbs.PCBoard.CSS(&css); err != nil {
fmt.Print(err)
}
// print the first 8 lines of the css
lines := strings.Split(css.String(), "\n")
for i := 0; i < 8; i++ {
fmt.Println(lines[i])
}
// Output: @import url("text_bbs.css");
// @import url("text_blink.css");
//
// /* PCBoard and WildCat! BBS colours */
//
// i.PF0 {
// color: var(--black);
// }
}
func ExampleBBS_HTML() {
src := []byte("@X03Hello @X04world@X00")
var buf bytes.Buffer
if err := bbs.PCBoard.HTML(&buf, src); err != nil {
fmt.Print(err)
return
}
fmt.Print(buf.String())
// Output: <i class="PB0 PF3">Hello </i><i class="PB0 PF4">world</i><i class="PB0 PF0"></i>
}
func ExampleBBS_HTML_find() {
src := []byte("@X03Hello @X04world@X00")
result := bbs.Find(bytes.NewReader(src))
var buf bytes.Buffer
if err := result.HTML(&buf, src); err != nil {
fmt.Print(err)
return
}
fmt.Print(buf.String())
// Output: <i class="PB0 PF3">Hello </i><i class="PB0 PF4">world</i><i class="PB0 PF0"></i>
}
func ExampleBBS_HTML_ansi() {
const reset = "\x1b[0m" // an ANSI escape sequence to reset the terminal
src := []byte(reset + "Hello world")
result := bbs.Find(bytes.NewReader(src))
var buf bytes.Buffer
if err := result.HTML(&buf, src); err != nil {
fmt.Printf("error: %s", err)
return
}
fmt.Print(buf.String())
// Output: error: ansi escape code found
}
func ExampleBBS_Name() {
fmt.Print(bbs.PCBoard.Name())
// Output: PCBoard
}
func ExampleBBS_Remove() {
src := []byte("@X03Hello @X07world")
var buf bytes.Buffer
if err := bbs.PCBoard.Remove(&buf, src); err != nil {
fmt.Print(err)
}
fmt.Printf("%q to %s", src, buf.String())
// Output: "@X03Hello @X07world" to Hello world
}
func ExampleBBS_Remove_find() {
src := []byte("@X03Hello @X07world")
result := bbs.Find(bytes.NewReader(src))
var buf bytes.Buffer
if err := result.Remove(&buf, src); err != nil {
fmt.Print(err)
}
fmt.Printf("%q to %s", src, buf.String())
// Output: "@X03Hello @X07world" to Hello world
}
func ExampleBBS_String() {
fmt.Print(bbs.PCBoard)
// Output: PCBoard @X
}
func ExampleBBS_Valid() {
src := "@X03Hello @X07world"
r := strings.NewReader(src)
ok := bbs.Find(r).Valid()
fmt.Print(ok)
// Output: true
}
func ExampleBBS_Valid_false() {
src := "Hello world"
r := strings.NewReader(src)
ok := bbs.Find(r).Valid()
fmt.Print(ok)
// Output: false
}
func ExampleBBS_Valid_ansi() {
const reset = "\x1b[0m" // an ANSI escape sequence to reset the terminal
src := reset + "Hello world"
r := strings.NewReader(src)
ok := bbs.Find(r).Valid()
fmt.Print(ok)
// Output: true
}