diff options
Diffstat (limited to 'raku/phone-number/phone-number.rakutest')
-rw-r--r-- | raku/phone-number/phone-number.rakutest | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/raku/phone-number/phone-number.rakutest b/raku/phone-number/phone-number.rakutest new file mode 100644 index 0000000..a8638ef --- /dev/null +++ b/raku/phone-number/phone-number.rakutest @@ -0,0 +1,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 |