|
1 |
| -;;; phone-number-test.el --- Tests for phone-number (exercism) -*- lexical-binding: t; -*- |
| 1 | +;;; phone-number-test.el --- Phone Number (exercism) -*- lexical-binding: t; -*- |
2 | 2 |
|
3 | 3 | ;;; Commentary:
|
4 | 4 |
|
|
9 | 9 | (declare-function area-code "phone-number.el" (num))
|
10 | 10 | (declare-function pprint "phone-number.el" (num))
|
11 | 11 |
|
12 |
| -(ert-deftest cleans-number-test () |
13 |
| - (should (equal (numbers "(223) 456-7890") "2234567890"))) |
| 12 | +(ert-deftest cleans-the-number () |
| 13 | + (should (string= (numbers "(223) 456-7890") "2234567890"))) |
14 | 14 |
|
| 15 | +(ert-deftest cleans-numbers-with-dots () |
| 16 | + (should (string= (numbers "223.456.7890") "2234567890"))) |
15 | 17 |
|
16 |
| -(ert-deftest cleans-numbers-with-dots-test () |
17 |
| - (should (equal (numbers "223.456.7890") "2234567890"))) |
| 18 | +(ert-deftest cleans-numbers-with-multiple-spaces () |
| 19 | + (should (string= (numbers "223 456 7890 ") "2234567890"))) |
18 | 20 |
|
| 21 | +(ert-deftest invalid-when-9-digits () |
| 22 | + (should-error (numbers "123456789") :type 'short-phone-num-error)) |
19 | 23 |
|
20 |
| -(ert-deftest valid-when-11-digits-and-first-is-1-test () |
21 |
| - (should (equal (numbers "12234567890") "2234567890"))) |
| 24 | +(ert-deftest invalid-when-11-digits-does-not-start-with-a-1 () |
| 25 | + (should-error (numbers "22234567890") :type 'country-code-error)) |
22 | 26 |
|
| 27 | +(ert-deftest valid-when-11-digits-and-starting-with-1 () |
| 28 | + (should (string= (numbers "12234567890") "2234567890"))) |
23 | 29 |
|
24 |
| -(ert-deftest invalid-when-11-digits-test () |
25 |
| - (should (equal (numbers "21234567890") "0000000000"))) |
| 30 | +(ert-deftest valid-when-11-digits-and-starting-with-1-even-with-punctuation () |
| 31 | + (should (string= (numbers "+1 (223) 456-7890") "2234567890"))) |
26 | 32 |
|
| 33 | +(ert-deftest invalid-when-more-than-11-digits () |
| 34 | + (should-error (numbers "321234567890") :type 'long-phone-num-error)) |
27 | 35 |
|
28 |
| -(ert-deftest invalid-when-9-digits-test () |
29 |
| - (should (equal (numbers "123456789") "0000000000"))) |
| 36 | +(ert-deftest invalid-with-letters () |
| 37 | + (should-error (numbers "523-abc-7890") :type 'letters-in-phone-num-error)) |
30 | 38 |
|
31 |
| -(ert-deftest invalid-when-more-than-11-digits-test () |
32 |
| - (should (equal (numbers "321234567890") "0000000000"))) |
| 39 | +(ert-deftest invalid-with-punctuations () |
| 40 | + (should-error (numbers "523-@:!-7890") :type 'punctuations-in-phone-num-error)) |
33 | 41 |
|
34 |
| -(ert-deftest invalid-with-letters () |
35 |
| - (should (equal (numbers "523-abc-7890") "0000000000"))) |
| 42 | +(ert-deftest invalid-if-area-code-starts-with-0 () |
| 43 | + (should-error (numbers "(023) 456-7890") :type 'area-code-starting-with-0-error)) |
36 | 44 |
|
| 45 | +(ert-deftest invalid-if-area-code-starts-with-1 () |
| 46 | + (should-error (numbers "(123) 456-7890") :type 'area-code-starting-with-1-error)) |
37 | 47 |
|
38 |
| -(ert-deftest invalid-with-punctuations () |
39 |
| - (should (equal (numbers "523-@:!-7890") "0000000000"))) |
| 48 | +(ert-deftest invalid-if-exchange-code-starts-with-0 () |
| 49 | + (should-error (numbers "(223) 056-7890") :type 'exchange-code-starting-with-0-error)) |
| 50 | + |
| 51 | +(ert-deftest invalid-if-exchange-code-starts-with-1 () |
| 52 | + (should-error (numbers "(223) 156-7890") :type 'exchange-code-starting-with-1-error)) |
40 | 53 |
|
| 54 | +(ert-deftest invalid-if-area-code-starts-with-0-on-valid-11-digit-number () |
| 55 | + (should-error (numbers "1 (023) 456-7890") :type 'area-code-starting-with-0-error)) |
| 56 | + |
| 57 | +(ert-deftest invalid-if-area-code-starts-with-1-on-valid-11-digit-number () |
| 58 | + (should-error (numbers "1 (123) 456-7890") :type 'area-code-starting-with-1-error)) |
| 59 | + |
| 60 | +(ert-deftest invalid-if-exchange-code-starts-with-0-on-valid-11-digit-number () |
| 61 | + (should-error (numbers "1 (223) 056-7890") :type 'exchange-code-starting-with-0-error)) |
| 62 | + |
| 63 | +(ert-deftest invalid-if-exchange-code-starts-with-1-on-valid-11-digit-number () |
| 64 | + (should-error (numbers "1 (223) 156-7890") :type 'exchange-code-starting-with-1-error)) |
41 | 65 |
|
42 | 66 | (ert-deftest area-code-test ()
|
43 | 67 | (should (equal (area-code "2234567890") "223")))
|
|
50 | 74 | (ert-deftest pprint-full-us-phone-number-test ()
|
51 | 75 | (should (equal (pprint "12234567890") "(223) 456-7890")))
|
52 | 76 |
|
53 |
| - |
54 |
| -(provide 'phone-number) |
| 77 | +(provide 'phone-number-test) |
55 | 78 | ;;; phone-number-test.el ends here
|
| 79 | + |
0 commit comments