Skip to content

Commit f96e59b

Browse files
committed
Added email-address tests
1 parent afcbbfb commit f96e59b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/valip/predicates.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
(defn valid-email-domain?
4646
"Returns true if the domain of the supplied email address has a MX DNS entry."
4747
[email]
48-
(let [domain (second (re-matches #".*@(.*)" email))]
48+
(if-let [domain (second (re-matches #".*@(.*)" email))]
4949
(boolean (dns-lookup domain "MX"))))
5050

5151
(defn integer-string?

test/valip/test/predicates.clj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
(is ((matches #"...") "foo"))
1313
(is (not ((matches #"...") "foobar"))))
1414

15+
(deftest test-email-address?
16+
(is (email-address? "foo@example.com"))
17+
(is (email-address? "foo+bar@example.com"))
18+
(is (email-address? "foo-bar@example.com"))
19+
(is (email-address? "foo.bar@example.com"))
20+
(is (email-address? "foo@example.co.uk"))
21+
(is (not (email-address? "foo")))
22+
(is (not (email-address? "foo@bar")))
23+
(is (not (email-address? "foo bar@example.com")))
24+
(is (not (email-address? "foo@foo_bar.com"))))
25+
26+
(deftest test-valid-email-domain?
27+
(is (valid-email-domain? "example@google.com"))
28+
(is (not (valid-email-domain? "foo@example.com")))
29+
(is (not (valid-email-domain? "foo@google.com.nospam")))
30+
(is (not (valid-email-domain? "foo"))))
31+
1532
(deftest test-integer-string?
1633
(is (integer-string? "10"))
1734
(is (integer-string? "-9"))

0 commit comments

Comments
 (0)