1 | "use strict";
|
2 |
|
3 | var validator = require("./index");
|
4 |
|
5 | var validSupported =
|
6 | [
|
7 | "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@letters-in-local.org",
|
8 | "01234567890@numbers-in-local.net",
|
9 | "&'*+-./=?^_{}~@other-valid-characters-in-local.net",
|
10 | "mixed-1234-in-{+^}-local@sld.net",
|
11 | "a@single-character-in-local.org",
|
12 | "one-character-third-level@a.example.com",
|
13 | "single-character-in-sld@x.org",
|
14 | "local@dash-in-sld.com",
|
15 | "letters-in-sld@123.com",
|
16 | "one-letter-sld@x.org",
|
17 | "uncommon-tld@sld.museum",
|
18 | "uncommon-tld@sld.travel",
|
19 | "uncommon-tld@sld.mobi",
|
20 | "country-code-tld@sld.uk",
|
21 | "country-code-tld@sld.rw",
|
22 | "local@sld.newTLD",
|
23 | "the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-254-characters-exactly.so-it-should-be-valid.and-im-going-to-add-some-more-words-here.to-increase-the-lenght-blah-blah-blah-blah-bla.org",
|
24 | "the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-three-characters-so-it-is-valid-blah-blah.com",
|
25 | "local@sub.domains.com",
|
26 | "backticks`are`legit@test.com",
|
27 | "digit-only-domain@123.com",
|
28 | "digit-only-domain-with-subdomain@sub.123.com"
|
29 | ];
|
30 |
|
31 | var validUnsupported =
|
32 | [
|
33 | "\"quoted\"@sld.com",
|
34 | "\"\\e\\s\\c\\a\\p\\e\\d\"@sld.com",
|
35 | "\"quoted-at-sign@sld.org\"@sld.com",
|
36 | "\"escaped\\\"quote\"@sld.com",
|
37 | "\"back\\slash\"@sld.com",
|
38 | "punycode-numbers-in-tld@sld.xn--3e0b707e",
|
39 | "bracketed-IP-instead-of-domain@[127.0.0.1]"
|
40 | ];
|
41 |
|
42 | var invalidSupported =
|
43 | [
|
44 | "@missing-local.org",
|
45 | "! #$%`|@invalid-characters-in-local.org",
|
46 | "(),:;`|@more-invalid-characters-in-local.org",
|
47 | "<>@[]\\`|@even-more-invalid-characters-in-local.org",
|
48 | ".local-starts-with-dot@sld.com",
|
49 | "local-ends-with-dot.@sld.com",
|
50 | "two..consecutive-dots@sld.com",
|
51 | "partially.\"quoted\"@sld.com",
|
52 | "the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net",
|
53 | "missing-sld@.com",
|
54 | "sld-starts-with-dashsh@-sld.com",
|
55 | "sld-ends-with-dash@sld-.com",
|
56 | "invalid-characters-in-sld@! \"#$%(),/;<>_[]`|.org",
|
57 | "missing-dot-before-tld@com",
|
58 | "missing-tld@sld.",
|
59 | "invalid",
|
60 | "the-total-length@of-an-entire-address.cannot-be-longer-than-two-hundred-and-fifty-four-characters.and-this-address-is-255-characters-exactly.so-it-should-be-invalid.and-im-going-to-add-some-more-words-here.to-increase-the-lenght-blah-blah-blah-blah-bl.org",
|
61 | "the-character-limit@for-each-part.of-the-domain.is-sixty-three-characters.this-is-exactly-sixty-four-characters-so-it-is-invalid-blah-blah.com",
|
62 | "missing-at-sign.net",
|
63 | "unbracketed-IP@127.0.0.1",
|
64 | "invalid-ip@127.0.0.1.26",
|
65 | "another-invalid-ip@127.0.0.256",
|
66 | "IP-and-port@127.0.0.1:25",
|
67 | "trailing-dots@test.de.",
|
68 | "dot-on-dot-in-domainname@te..st.de",
|
69 | "dot-first-in-domain@.test.de",
|
70 | "mg@ns.i"
|
71 | ];
|
72 |
|
73 | console.log('SYNC VERSION TESTS')
|
74 | console.log('=====================')
|
75 | console.log("SUPPORTED BY MODULE:\n");
|
76 |
|
77 | console.log("SHOULD BE VALID:");
|
78 | validSupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); });
|
79 |
|
80 | console.log("\nSHOULD BE INVALID:");
|
81 | invalidSupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); });
|
82 |
|
83 | console.log("\n\nNOT SUPPORTED BY MODULE:\n");
|
84 |
|
85 | console.log("SHOULD BE VALID:");
|
86 | validUnsupported.forEach(function(email) { console.log("%s : %s", validator.validate(email) ? " VALID" : " INVALID", email); });
|
87 |
|
88 |
|
89 | console.log('------------------------------------------------------\n');
|
90 |
|
91 | console.log('ASYNC VERSION TESTS')
|
92 | console.log('=====================')
|
93 |
|
94 | console.log("SHOULD BE VALID:");
|
95 | validSupported.forEach(function(email) {
|
96 | validator.validate_async(email, function(err, isValidEmail) {
|
97 | console.log("%s : %s", isValidEmail ? " VALID" : " INVALID", email);
|
98 | });
|
99 | });
|
100 |
|
101 | console.log("\nSHOULD BE INVALID:");
|
102 | invalidSupported.forEach(function(email) {
|
103 | validator.validate_async(email, function(err, isValidEmail) {
|
104 | console.log("%s : %s", isValidEmail ? " VALID" : " INVALID", email);
|
105 | });
|
106 | });
|
107 |
|
108 | console.log("\n\nNOT SUPPORTED BY MODULE:\n");
|
109 |
|
110 | console.log("SHOULD BE VALID:");
|
111 | validUnsupported.forEach(function(email) {
|
112 | validator.validate_async(email, function(err, isValidEmail) {
|
113 | console.log("%s : %s", isValidEmail ? " VALID" : " INVALID", email);
|
114 | });
|
115 | });
|
116 |
|
117 | process.exit(0);
|