summary refs log tree commit diff stats
path: root/raku/phone-number/phone-number.rakutest
blob: a8638ef6aad39d4cd57c8bc7d2e2ce0cd26add27 (plain) (blame)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env raku
use Test;
use JSON::Fast;
use lib $?FILE.IO.dirname;
use Phone;
plan 18;

my @test-cases = from-json($=pod.pop.contents).List;
for @test-cases -> %case {
  given %case<expected> {
    when Str {
      is clean-number(%case<input><phrase>),
        |%case<expected description>;
    }

    when .<error>.so {
      throws-like
        { clean-number %case<input><phrase> },
        Exception,
        :message(%case<expected><error>),
        %case<description>;
    }
  }
}

=head2 Test Cases
=begin code
[
  {
    "description": "Cleanup user-entered phone numbers: cleans the number",
    "expected": "2234567890",
    "input": {
      "phrase": "(223) 456-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: cleans numbers with dots",
    "expected": "2234567890",
    "input": {
      "phrase": "223.456.7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: cleans numbers with multiple spaces",
    "expected": "2234567890",
    "input": {
      "phrase": "223 456   7890   "
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid when 9 digits",
    "expected": {
      "error": "incorrect number of digits"
    },
    "input": {
      "phrase": "123456789"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid when 11 digits does not start with a 1",
    "expected": {
      "error": "11 digits must start with 1"
    },
    "input": {
      "phrase": "22234567890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: valid when 11 digits and starting with 1",
    "expected": "2234567890",
    "input": {
      "phrase": "12234567890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: valid when 11 digits and starting with 1 even with punctuation",
    "expected": "2234567890",
    "input": {
      "phrase": "+1 (223) 456-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid when more than 11 digits",
    "expected": {
      "error": "more than 11 digits"
    },
    "input": {
      "phrase": "321234567890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid with letters",
    "expected": {
      "error": "letters not permitted"
    },
    "input": {
      "phrase": "123-abc-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid with punctuations",
    "expected": {
      "error": "punctuations not permitted"
    },
    "input": {
      "phrase": "123-@:!-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid if area code starts with 0",
    "expected": {
      "error": "area code cannot start with zero"
    },
    "input": {
      "phrase": "(023) 456-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid if area code starts with 1",
    "expected": {
      "error": "area code cannot start with one"
    },
    "input": {
      "phrase": "(123) 456-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid if exchange code starts with 0",
    "expected": {
      "error": "exchange code cannot start with zero"
    },
    "input": {
      "phrase": "(223) 056-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid if exchange code starts with 1",
    "expected": {
      "error": "exchange code cannot start with one"
    },
    "input": {
      "phrase": "(223) 156-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid if area code starts with 0 on valid 11-digit number",
    "expected": {
      "error": "area code cannot start with zero"
    },
    "input": {
      "phrase": "1 (023) 456-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid if area code starts with 1 on valid 11-digit number",
    "expected": {
      "error": "area code cannot start with one"
    },
    "input": {
      "phrase": "1 (123) 456-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid if exchange code starts with 0 on valid 11-digit number",
    "expected": {
      "error": "exchange code cannot start with zero"
    },
    "input": {
      "phrase": "1 (223) 056-7890"
    },
    "property": "clean"
  },
  {
    "description": "Cleanup user-entered phone numbers: invalid if exchange code starts with 1 on valid 11-digit number",
    "expected": {
      "error": "exchange code cannot start with one"
    },
    "input": {
      "phrase": "1 (223) 156-7890"
    },
    "property": "clean"
  }
]
=end code