-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
haiku_test.go
42 lines (37 loc) · 909 Bytes
/
haiku_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
package haiku
import (
"bufio"
"log"
"os"
"strings"
"testing"
"github.com/ikawaha/kagome-dict/uni"
)
func testMatch(t *testing.T, filename string, rules []int, judge bool) {
f, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer f.Close()
opts := &Opt{
Dict: uni.Dict(),
Debug: testing.Verbose(),
}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
text := scanner.Text()
if strings.HasPrefix(text, "#") {
continue
}
t.Logf("%s (%v:%v)", text, filename, judge)
if MatchWithOpt(text, rules, opts) != judge {
t.Fatalf("%q for %q must be %v", text, filename, rules)
}
}
}
func TestHaiku(t *testing.T) {
testMatch(t, "testdata/haiku.good", []int{5, 7, 5}, true)
testMatch(t, "testdata/haiku.bad", []int{5, 7, 5}, false)
testMatch(t, "testdata/tanka.good", []int{5, 7, 5, 7, 7}, true)
testMatch(t, "testdata/tanka.bad", []int{5, 7, 5, 7, 7}, false)
}