forked from bingsoo420/4ch-general
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_test.go
More file actions
64 lines (53 loc) · 1.15 KB
/
parser_test.go
File metadata and controls
64 lines (53 loc) · 1.15 KB
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
package main_test
import (
"encoding/json"
"fmt"
"os"
"testing"
. "github.com/fluteds/4ch-gen"
)
func TestItParseValidSubjects(t *testing.T) {
tests := []struct {
subject string
valid bool
want string
}{
{"/wdg/", true, "wdg"},
{"xdg", false, ""},
{"Anonymous", false, ""},
}
for _, tt := range tests {
t.Run(tt.subject, func(t *testing.T) {
isValid, extracted := ParseSubject(tt.subject)
if isValid != tt.valid || extracted != tt.want {
t.Errorf("got [%t, %s], want [%t, %s]", isValid, extracted, tt.valid, tt.want)
}
})
}
}
func TestItParseGeneralsFromFixtures(t *testing.T) {
tests := []struct {
board string
length int
}{
{"g", 24},
{"fit", 7},
{"biz", 14},
}
for _, tt := range tests {
t.Run(tt.board, func(t *testing.T) {
dat, err := os.ReadFile(fmt.Sprintf("./fixtures/%s_catalog.json", tt.board))
if err != nil {
panic(err)
}
var catalog Catalog
if err := json.Unmarshal(dat, &catalog); err != nil {
panic(err)
}
generals := BuildGenerals(tt.board, catalog)
if len(generals) != tt.length {
t.Errorf("got %d, want %d", len(generals), tt.length)
}
})
}
}