-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
133 lines (114 loc) · 4.58 KB
/
main_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
package main
import (
"fmt"
"os"
"testing"
"github.com/tychy/toukibo-parser/toukibo"
"gopkg.in/yaml.v3"
)
type TestData struct {
HoujinKaku string `yaml:"HoujinKaku"`
HoujinName string `yaml:"HoujinName"`
HoujinAddress string `yaml:"HoujinAddress"`
HoujinExecutiveValues []toukibo.HoujinExecutiveValue `yaml:"HoujinExecutiveValues"`
HoujinExecutiveNames []string `yaml:"HoujinExecutiveNames"`
HoujinRepresentativeNames []string `yaml:"HoujinRepresentativeNames"`
HoujinCapital string `yaml:"HoujinCapital"`
HoujinCreatedAt string `yaml:"HoujinCreatedAt"`
HoujinBankruptedAt string `yaml:"HoujinBankruptedAt"`
HoujinDissolvedAt string `yaml:"HoujinDissolvedAt"`
HoujinContinuedAt string `yaml:"HoujinContinuedAt"`
}
func TestToukiboParser(t *testing.T) {
testCount := 789
for i := 1; i <= testCount; i++ {
t.Run(fmt.Sprintf("test%d", i), func(t *testing.T) {
pdfFileName := fmt.Sprintf("testdata/pdf/sample%d.pdf", i)
yamlFileName := fmt.Sprintf("testdata/yaml/sample%d.yaml", i)
content, err := readPdf(pdfFileName)
if err != nil {
t.Fatal(err)
}
h, err := toukibo.Parse(content)
if err != nil {
t.Fatal(err)
}
yamlContent, err := os.ReadFile(yamlFileName)
if err != nil {
t.Fatal(err)
}
td := TestData{}
err = yaml.Unmarshal([]byte(yamlContent), &td)
if err != nil {
t.Fatal(err)
}
// check
if h.GetHoujinKaku() != td.HoujinKaku {
t.Fatalf("kaku is not match,\nwant : %s,\ngot : %s,", td.HoujinKaku, h.GetHoujinKaku())
}
if h.GetHoujinName() != td.HoujinName {
t.Fatalf("name is not match,\nwant : %s,\ngot : %s,", td.HoujinName, h.GetHoujinName())
}
if h.GetHoujinAddress() != td.HoujinAddress {
t.Fatalf("address is not match,\nwant : %s,\ngot : %s,", td.HoujinAddress, h.GetHoujinAddress())
}
// Exec
execs, err := h.GetHoujinExecutives()
if err != nil {
t.Fatal(err)
}
if len(execs) != len(td.HoujinExecutiveValues) {
t.Fatalf("executive count is not match,\nwant : %d,\ngot : %d", len(td.HoujinExecutiveValues), len(execs))
}
for i, v := range execs {
if v.Name != td.HoujinExecutiveValues[i].Name {
t.Fatalf("executive name is not match,\nwant : %s,\ngot : %s", td.HoujinExecutiveValues[i].Name, v.Name)
}
if v.Position != td.HoujinExecutiveValues[i].Position {
t.Fatalf("executive position is not match,\nwant : %s,\ngot : %s", td.HoujinExecutiveValues[i].Position, v.Position)
}
}
// ExecutiveNames
execNames, err := h.GetHoujinExecutiveNames()
if err != nil {
t.Fatal(err)
}
if len(execNames) != len(td.HoujinExecutiveNames) {
t.Fatalf("executive name count is not match,\nwant : %d,\ngot : %d", len(td.HoujinExecutiveNames), len(execNames))
}
for i, v := range execNames {
if v != td.HoujinExecutiveNames[i] {
t.Fatalf("executive name is not match,\nwant : %s,\ngot : %s", td.HoujinExecutiveNames[i], v)
}
}
// RepresentativeNames
repNames, err := h.GetHoujinRepresentativeNames()
if err != nil {
t.Fatal(err)
}
if len(repNames) != len(td.HoujinRepresentativeNames) {
t.Fatalf("representative name count is not match,\nwant : %d,\ngot : %d", len(td.HoujinRepresentativeNames), len(repNames))
}
for i, v := range repNames {
if v != td.HoujinRepresentativeNames[i] {
t.Fatalf("representative name is not match,\nwant : %s,\ngot : %s", td.HoujinRepresentativeNames[i], v)
}
}
if fmt.Sprint(h.GetHoujinCapital()) != td.HoujinCapital {
t.Fatalf("capital is not match,\nwant : %s,\ngot : %d,", td.HoujinCapital, h.GetHoujinCapital())
}
if h.GetHoujinCreatedAt() != td.HoujinCreatedAt {
t.Fatalf("created_at is not match,\nwant : %s,\ngot : %s,", td.HoujinCreatedAt, h.GetHoujinCreatedAt())
}
if h.GetHoujinBankruptedAt() != td.HoujinBankruptedAt {
t.Fatalf("bankrupted_at is not match,\nwant : %s,\ngot : %s,", td.HoujinBankruptedAt, h.GetHoujinBankruptedAt())
}
if h.GetHoujinDissolvedAt() != td.HoujinDissolvedAt {
t.Fatalf("dissolved_at is not match,\nwant : %s,\ngot : %s,", td.HoujinDissolvedAt, h.GetHoujinDissolvedAt())
}
if h.GetHoujinContinuedAt() != td.HoujinContinuedAt {
t.Fatalf("continued_at is not match,\nwant : %s,\ngot : %s,", td.HoujinContinuedAt, h.GetHoujinContinuedAt())
}
})
}
}