forked from exercism/wren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphone-number.spec.wren
112 lines (94 loc) · 3.27 KB
/
phone-number.spec.wren
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
import "./phone-number" for PhoneNumber
import "wren-testie/testie" for Testie, Expect
Testie.test("PhoneNumber") { |do, skip|
do.test("cleans the number") {
var actual = PhoneNumber.clean("(223) 456-7890")
var expected = "2234567890"
Expect.value(actual).toEqual(expected)
}
skip.test("cleans numbers with dots") {
var actual = PhoneNumber.clean("223.456.7890")
var expected = "2234567890"
Expect.value(actual).toEqual(expected)
}
skip.test("cleans numbers with multiple spaces") {
var actual = PhoneNumber.clean("223 456 7890 ")
var expected = "2234567890"
Expect.value(actual).toEqual(expected)
}
skip.test("invalid when 9 digits") {
Expect.that {
PhoneNumber.clean("123456789")
}.abortsWith("must not be fewer than 10 digits")
}
skip.test("invalid when 11 digits does not start with a 1") {
Expect.that {
PhoneNumber.clean("22234567890")
}.abortsWith("11 digits must start with 1")
}
skip.test("valid when 11 digits and starting with 1") {
var actual = PhoneNumber.clean("12234567890")
var expected = "2234567890"
Expect.value(actual).toEqual(expected)
}
skip.test("valid when 11 digits and starting with 1 even with punctuation") {
var actual = PhoneNumber.clean("+1 (223) 456-7890")
var expected = "2234567890"
Expect.value(actual).toEqual(expected)
}
skip.test("invalid when more than 11 digits") {
Expect.that {
PhoneNumber.clean("321234567890")
}.abortsWith("must not be greater than 11 digits")
}
skip.test("invalid with letters") {
Expect.that {
PhoneNumber.clean("523-abc-7890")
}.abortsWith("letters not permitted")
}
skip.test("invalid with punctuations") {
Expect.that {
PhoneNumber.clean("523-@:!-7890")
}.abortsWith("punctuations not permitted")
}
skip.test("invalid if area code starts with 0") {
Expect.that {
PhoneNumber.clean("(023) 456-7890")
}.abortsWith("area code cannot start with zero")
}
skip.test("invalid if area code starts with 1") {
Expect.that {
PhoneNumber.clean("(123) 456-7890")
}.abortsWith("area code cannot start with one")
}
skip.test("invalid if exchange code starts with 0") {
Expect.that {
PhoneNumber.clean("(223) 056-7890")
}.abortsWith("exchange code cannot start with zero")
}
skip.test("invalid if exchange code starts with 1") {
Expect.that {
PhoneNumber.clean("(223) 156-7890")
}.abortsWith("exchange code cannot start with one")
}
skip.test("invalid if area code starts with 0 on valid 11-digit number") {
Expect.that {
PhoneNumber.clean("1 (023) 456-7890")
}.abortsWith("area code cannot start with zero")
}
skip.test("invalid if area code starts with 1 on valid 11-digit number") {
Expect.that {
PhoneNumber.clean("1 (123) 456-7890")
}.abortsWith("area code cannot start with one")
}
skip.test("invalid if exchange code starts with 0 on valid 11-digit number") {
Expect.that {
PhoneNumber.clean("1 (223) 056-7890")
}.abortsWith("exchange code cannot start with zero")
}
skip.test("invalid if exchange code starts with 1 on valid 11-digit number") {
Expect.that {
PhoneNumber.clean("1 (223) 156-7890")
}.abortsWith("exchange code cannot start with one")
}
}