-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganisationsnummer_test.go
114 lines (94 loc) · 2.28 KB
/
organisationsnummer_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
package organisationsnummer
import (
"log"
"os"
"testing"
"github.com/frozzare/go-assert"
"github.com/frozzare/go/http2"
)
type TestListItem struct {
LongFormat string `json:"long_format"`
ShortFormat string `json:"short_format"`
Valid bool `json:"valid"`
Type string `json:"type"`
Input string `json:"input"`
VatNumber string `json:"vat_number"`
}
var testList []*TestListItem
func TestMain(m *testing.M) {
if err := http2.GetJSON("https://raw.githubusercontent.com/organisationsnummer/meta/main/testdata/list.json", &testList); err != nil {
log.Fatal(err)
}
code := m.Run()
os.Exit(code)
}
func TestValidOrganisationsnummer(t *testing.T) {
for _, item := range testList {
if !item.Valid {
continue
}
assert.True(t, Valid(item.Input))
}
}
func TestInvalidOrganisationsnummer(t *testing.T) {
for _, item := range testList {
if item.Valid {
continue
}
assert.False(t, Valid(item.Input))
}
}
func TestValidOrganisationsnummerFormatShort(t *testing.T) {
for _, item := range testList {
if !item.Valid {
continue
}
o, _ := Parse(item.Input)
assert.Equal(t, o.Format(false), item.ShortFormat)
}
}
func TestValidOrganisationsnummerFormatLong(t *testing.T) {
for _, item := range testList {
if !item.Valid {
continue
}
o, _ := Parse(item.Input)
assert.Equal(t, o.Format(true), item.LongFormat)
}
}
func TestValidOrganisationsnummerType(t *testing.T) {
for _, item := range testList {
if !item.Valid {
continue
}
o, _ := Parse(item.Input)
assert.Equal(t, o.GetType(), item.Type)
}
}
func TestValidOrganisationsnummerVatNumber(t *testing.T) {
for _, item := range testList {
if !item.Valid {
continue
}
o, _ := Parse(item.Input)
assert.Equal(t, o.VatNumber(), item.VatNumber)
}
}
func TestValidPersonnummer(t *testing.T) {
for _, item := range testList {
if !item.Valid {
continue
}
if item.Type != "Enskild firma" {
continue
}
assert.True(t, Valid(item.LongFormat))
org, _ := Parse(item.Input)
assert.Equal(t, org.GetType(), item.Type)
assert.Equal(t, org.String(), item.Type)
assert.True(t, org.IsPersonnummer())
assert.Equal(t, org.VatNumber(), item.VatNumber)
assert.Equal(t, org.Format(true), item.LongFormat)
assert.Equal(t, org.Format(false), item.ShortFormat)
}
}