-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnopol_test.go
51 lines (44 loc) · 996 Bytes
/
nopol_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
package nopol
import (
"testing"
)
// Nopol struct
type Nopol struct {
s string
b bool
r string
}
var nopols = []Nopol{
{"AD 6742 DZ", true, "AD 6742 DZ"},
{"AD6742DZ", true, "AD 6742 DZ"},
{"AD-6742-DZ", true, "AD 6742 DZ"},
{" AD-6742 DZ ", true, "AD 6742 DZ"},
{"B 1 XYZ", true, "B 1 XYZ"},
{"RI 1", true, "RI 1"},
{"CD 123", true, "CD 123"},
{"12345", false, ""},
{"AB 1234567890 CD", false, ""},
{"AB 1 WXYZ", false, ""},
{"AB CDEF GHI", false, ""},
{"", false, ""},
{"ab 123-xyz", true, "AB 123 XYZ"},
{"nil", false, ""},
{"XY1234", true, "XY 1234"},
{"XYZ1234", false, ""},
}
func TestIsValid(t *testing.T) {
for _, n := range nopols {
r := IsValid(n.s)
if n.b != r {
t.Errorf("Vehicle registration number %s is not valid, got %t, want %t", n.s, r, n.b)
}
}
}
func TestFormat(t *testing.T) {
for _, n := range nopols {
r, _ := Format(n.s)
if n.r != r {
t.Errorf("Police number %s is not formatted, got %s, want %s", n.s, r, n.r)
}
}
}