-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquip_test.go
63 lines (52 loc) · 1.13 KB
/
quip_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
package quip_test
import (
"bytes"
"strings"
"testing"
"github.com/xdg/maybe"
"github.com/xdg/quip"
"github.com/xdg/testy"
)
var dataLines = []string{"Line one", "Line two", "Line three"}
var dataWords = []string{"Line", "one", "Line", "two", "Line", "three"}
var dataInput = strings.Join(dataLines, "\n")
func newQuip(s string) *quip.Parser {
b := bytes.NewBufferString(s)
return quip.New(b)
}
func TestStringsToWords(t *testing.T) {
is := testy.New(t)
defer func() { t.Logf(is.Done()) }()
// Words from Lines
lines := maybe.JustAoS(dataLines)
words := lines.Bind(quip.StringsToWords)
wfl, err := words.Unbox()
is.Nil(err)
is.Equal(wfl, dataWords)
}
func TestParser(t *testing.T) {
is := testy.New(t)
defer func() { t.Logf(is.Done()) }()
// Empty input
{
q := newQuip("")
ss, err := q.Lines().Unbox()
is.Nil(err)
is.Equal(ss, []string{})
}
// Lines from Parser
{
q := newQuip(dataInput)
lines := q.Lines()
ss, err := lines.Unbox()
is.Nil(err)
is.Equal(ss, dataLines)
}
// Words from Parser
{
q := newQuip(dataInput)
wfp, err := q.Words().Unbox()
is.Nil(err)
is.Equal(wfp, dataWords)
}
}