-
Notifications
You must be signed in to change notification settings - Fork 0
/
letterboxed_test.go
73 lines (69 loc) · 1.67 KB
/
letterboxed_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
package qordle_test
import (
"encoding/json"
"errors"
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"
"github.com/bzimmer/qordle"
)
func TestLetterboxedCommand(t *testing.T) {
a := assert.New(t)
decode := func(c *cli.Context) [][]string {
var results [][]string
dec := json.NewDecoder(c.App.Writer.(io.Reader))
for {
var res []string
err := dec.Decode(&res)
if err != nil {
if errors.Is(err, io.EOF) {
return results
}
a.FailNow(err.Error())
}
results = append(results, res)
}
}
for _, tt := range []harness{
{
name: "letterboxed with 0 arguments",
args: []string{"letterboxed", "-w", "solutions", "--max", "4"},
after: func(c *cli.Context) error {
a.Equal(3, len(decode(c)))
return nil
},
},
{
name: "letterboxed with 1 argument",
args: []string{"letterboxed", "-w", "solutions", "--max", "4", "rul-eya-gdh-opb"},
after: func(c *cli.Context) error {
a.Equal(57, len(decode(c)))
return nil
},
},
{
name: "letterboxed with 4 arguments",
args: []string{"letterboxed", "-w", "solutions", "--max", "4", "rul", "eya", "gdh", "opb"},
after: func(c *cli.Context) error {
a.Equal(57, len(decode(c)))
return nil
},
},
{
name: "letterboxed with invalid wordlist",
args: []string{"letterboxed", "-w", "missing", "--max", "4"},
err: "invalid wordlist `missing`",
},
{
name: "letterboxed with 5 arguments",
args: []string{"letterboxed", "-w", "solutions", "--max", "4", "rul", "eya", "gdh", "opb", "qst"},
err: "found 5 sides",
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
run(t, &tt, qordle.CommandLetterBoxed)
})
}
}