-
Notifications
You must be signed in to change notification settings - Fork 1
/
formatter_test.go
44 lines (37 loc) · 1.14 KB
/
formatter_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
package msisdn_tools
import (
"testing"
)
func TestFormatMsisdn(t *testing.T) {
formatTests := []struct {
Msisdn string
Format string
Expected string
}{
{"9955053777", CleanerMsisdnFormat, "9955053777"},
{"9955053777", CleanMsisdnFormat, "79955053777"},
{"9955053777", ShortMsisdnFormat, "995 505-3777"},
{"9955053777", UsualMsisdnFormat, "(995) 505-3777"},
{"9955053777", FullMsisdnFormat, "+7 (995) 505-3777"},
}
for _, formatTest := range formatTests {
formatTest := formatTest
t.Run(formatTest.Format, func(t *testing.T) {
t.Parallel()
formatted, err := FormatMsisdn(formatTest.Msisdn, formatTest.Format)
if err != nil {
t.Errorf("error while formatting %s to %s: %s",
formatTest.Msisdn, formatTest.Expected, err.Error())
}
if formatTest.Expected != formatted {
t.Errorf("invalid format result. expected: %s, got: %s", formatTest.Expected, formatted)
}
})
}
}
func TestFormatMsisdnInvalid(t *testing.T) {
_, err := FormatMsisdn("9912323", CleanerMsisdnFormat)
if err != ErrInvalidMsisdn {
t.Errorf("invalid error type. expected: %s, got: %s", ErrInvalidMsisdn.Error(), err.Error())
}
}