test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. 'use strict';
  2. const Bench = require('bench');
  3. const Address = require('../');
  4. const Isemail = require('isemail');
  5. const tests = [
  6. ['', false],
  7. ['\r', false],
  8. ['test', false],
  9. ['@', false],
  10. ['test@', false],
  11. ['test@io', false],
  12. ['test@io', true, { minDomainSegments: 1 }],
  13. ['@io', false],
  14. ['@iana.org', false],
  15. ['test@iana.org', true],
  16. ['test@nominet.org.uk', true],
  17. ['test@about.museum', true],
  18. ['a@iana.org', true],
  19. ['êjness@iana.org', true],
  20. ['ñoñó1234@iana.org', true],
  21. ['ñoñó1234@something.com', true],
  22. ['伊昭傑@郵件.商務', true],
  23. ['\ud801\udc37\ud852\udf62@iana.org', true],
  24. ['test.test@iana.org', true],
  25. ['.test@iana.org', false],
  26. ['test.@iana.org', false],
  27. ['test..iana.org', false],
  28. ['test_exa-mple.com', false],
  29. ['!#$%&`*+/=?^`{|}~@iana.org', true],
  30. ['test\\@test@iana.org', false],
  31. ['123@iana.org', true],
  32. ['test@123.com', true],
  33. ['test@iana.123', false],
  34. ['test@255.255.255.255', false],
  35. ['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@iana.org', true],
  36. ['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklmn@iana.org', false],
  37. ['\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06@iana.org', false],
  38. ['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm', false],
  39. ['test@\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06.org', true],
  40. ['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmno\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06.org', false],
  41. ['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm.com', false],
  42. ['test@mason-dixon.com', true],
  43. ['test@-iana.org', false],
  44. ['test@iana-.com', false],
  45. ['test@.iana.org', false],
  46. ['test@iana.org.', false],
  47. ['test@iana..com', false],
  48. ['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmno', false],
  49. ['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.\ud83d\ude06\ud83d\ude06\ud83d\ude06\ud83d\ude06', false],
  50. ['abcdef@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdef.hijklmnopqrstuv', false],
  51. ['abcdef@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghi.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd\ud83d\ude06', false],
  52. ['abcdef@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghi.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\ud83d\ude06', false],
  53. ['a@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijkl.hijk', false],
  54. ['a@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijkl.\ud83d\ude06', false],
  55. ['\"\r', false],
  56. ['\"test\"@iana.org', false],
  57. ['\"\"@iana.org', false],
  58. ['\"\"\"@iana.org', false],
  59. ['\"\\a\"@iana.org', false],
  60. ['\"\\\"\"@iana.org', false],
  61. ['\"\\\"@iana.org', false],
  62. ['\"\\\\\"@iana.org', false],
  63. ['test\"@iana.org', false],
  64. ['\"test@iana.org', false],
  65. ['\"test\"test@iana.org', false],
  66. ['test\"text\"@iana.org', false],
  67. ['\"test\"\"test\"@iana.org', false],
  68. ['\"test\".\"test\"@iana.org', false],
  69. ['\"test\\ test\"@iana.org', false],
  70. ['\"test\".test@iana.org', false],
  71. ['\"test\u0000\"@iana.org', false],
  72. ['\"test\\\u0000\"@iana.org', false],
  73. ['\"test\r\n test\"@iana.org', false],
  74. ['\"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghj\"@iana.org', false],
  75. ['\"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefg\\h\"@iana.org', false],
  76. ['test@[255.255.255.255]', false],
  77. ['test@a[255.255.255.255]', false],
  78. ['test@[255.255.255]', false],
  79. ['test@[255.255.255.255.255]', false],
  80. ['test@[255.255.255.256]', false],
  81. ['test@[1111:2222:3333:4444:5555:6666:7777:8888]', false],
  82. ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777]', false],
  83. ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]', false],
  84. ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]', false],
  85. ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:888G]', false],
  86. ['test@[IPv6:1111:2222:3333:4444:5555:6666::8888]', false],
  87. ['test@[IPv6:1111:2222:3333:4444:5555::8888]', false],
  88. ['test@[IPv6:1111:2222:3333:4444:5555:6666::7777:8888]', false],
  89. ['test@[IPv6::3333:4444:5555:6666:7777:8888]', false],
  90. ['test@[IPv6:::3333:4444:5555:6666:7777:8888]', false],
  91. ['test@[IPv6:1111::4444:5555::8888]', false],
  92. ['test@[IPv6:::]', false],
  93. ['test@[IPv6:1111:2222:3333:4444:5555:255.255.255.255]', false],
  94. ['test@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255]', false],
  95. ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:255.255.255.255]', false],
  96. ['test@[IPv6:1111:2222:3333:4444::255.255.255.255]', false],
  97. ['test@[IPv6:1111:2222:3333:4444:5555:6666::255.255.255.255]', false],
  98. ['test@[IPv6:1111:2222:3333:4444:::255.255.255.255]', false],
  99. ['test@[IPv6::255.255.255.255]', false],
  100. ['test@[255.255.255.255].local', false],
  101. ['test@local.[255.255.255.255]', false],
  102. ['test@local.[255.255.255.255].local', false],
  103. ['test@local.(comment)[255.255.255.255].local', false],
  104. ['test@local. [255.255.255.255].local', false],
  105. ['test@local.[255.255.255.255](comment).local', false],
  106. ['test@local.[255.255.255.255] .local', false],
  107. [' test @iana.org', false],
  108. ['test@ iana .com', false],
  109. ['test . test@iana.org', false],
  110. ['\r\n test@iana.org', false],
  111. ['\r\n \r\n test@iana.org', false],
  112. ['(\r', false],
  113. ['(comment)test@iana.org', false],
  114. ['((comment)test@iana.org', false],
  115. ['(comment(comment))test@iana.org', false],
  116. ['test@(comment)iana.org', false],
  117. ['test(comment)@iana.org', false],
  118. ['test(comment)test@iana.org', false],
  119. ['test@(comment)[255.255.255.255]', false],
  120. ['(comment)abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@iana.org', false],
  121. ['test@(comment)abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.com', false],
  122. ['(comment)test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.abcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrst', false],
  123. ['test@iana.org\n', false],
  124. ['xn--test@iana.org', true],
  125. ['test@iana.org-', false],
  126. ['\"test@iana.org', false],
  127. ['(test@iana.org', false],
  128. ['test@(iana.org', false],
  129. ['test@[1.2.3.4', false],
  130. ['\"test\\\"@iana.org', false],
  131. ['(comment\\)test@iana.org', false],
  132. ['test@iana.org(comment\\)', false],
  133. ['test@iana.org(comment\\', false],
  134. ['test@[RFC-5322-domain-literal]', false],
  135. ['test@[RFC-5322-郵件ñó-domain-literal]', false],
  136. ['test@[RFC-5322]-domain-literal]', false],
  137. ['test@[RFC-5322].domain-literal]', false],
  138. ['test@[RFC-5322-[domain-literal]', false],
  139. ['test@[€', false],
  140. ['test@[\u0007]', false],
  141. ['test@[RFC-5322-\\\u0007-domain-literal]', false],
  142. ['test@[RFC-5322-\\\t-domain-literal]', false],
  143. ['test@[RFC-5322-\\]-domain-literal]', false],
  144. ['test@[RFC-5322-\\郵-no-domain-literal]', false],
  145. ['test@[RFC-5322--domain-literal]', false],
  146. ['test@[RFC-5322-domain-literal\\]', false],
  147. ['test@[RFC-5322-domain-literal\\', false],
  148. ['test@[RFC 5322 domain literal]', false],
  149. ['test@[RFC-5322-domain-literal] (comment)', false],
  150. ['@iana.org', false],
  151. ['test@.org', false],
  152. ['\"\"@iana.org', false],
  153. ['\"€\"@iana.org', false],
  154. ['\"\\\"@iana.org', false],
  155. ['()test@iana.org', false],
  156. ['(€)test@iana.org', false],
  157. ['test@iana.org\r', false],
  158. ['\rtest@iana.org', false],
  159. ['\"\rtest\"@iana.org', false],
  160. ['(\r)test@iana.org', false],
  161. ['test@iana.org(\r)', false],
  162. ['test@<iana>.org', false],
  163. ['\ntest@iana.org', false],
  164. ['\"\n\"@iana.org', false],
  165. ['\"\\\n\"@iana.org', false],
  166. ['(\n)test@iana.org', false],
  167. ['\u0007@iana.org', false],
  168. ['test@\u0007.org', false],
  169. ['\"\u0007\"@iana.org', false],
  170. ['\"\\\u0007\"@iana.org', false],
  171. ['(\u0007)test@iana.org', false],
  172. ['\r\ntest@iana.org', false],
  173. ['\r\n \r\ntest@iana.org', false],
  174. [' \r\ntest@iana.org', false],
  175. [' \r\n test@iana.org', false],
  176. [' \r\n \r\ntest@iana.org', false],
  177. [' \r\n\r\ntest@iana.org', false],
  178. [' \r\n\r\n test@iana.org', false],
  179. ['test@iana.org\r\n ', false],
  180. ['test@iana.org\r\n \r\n ', false],
  181. ['test@iana.org\r\n', false],
  182. ['test@iana.org \r', false],
  183. ['test@iana.org\r\n \r\n', false],
  184. ['test@iana.org \r\n', false],
  185. ['test@iana.org \r\n ', false],
  186. ['test@iana.org \r\n \r\n', false],
  187. ['test@iana.org \r\n\r\n', false],
  188. ['test@iana.org \r\n\r\n ', false],
  189. ['test@iana. org', false],
  190. ['test@[\r', false],
  191. ['test@[\r\n', false],
  192. [' test@iana.org', false],
  193. ['test@iana.org ', false],
  194. ['test@[IPv6:1::2:]', false],
  195. ['\"test\\\u0094\"@iana.org', false],
  196. ['test@iana/icann.org', false],
  197. ['test@iana!icann.org', false],
  198. ['test@iana?icann.org', false],
  199. ['test@iana^icann.org', false],
  200. ['test@iana{icann}.org', false],
  201. ['test.(comment)test@iana.org', false],
  202. ['test@iana.(comment)org', false],
  203. ['test@iana(comment)iana.org', false],
  204. ['(comment\r\n comment)test@iana.org', false],
  205. ['test@org', true, { minDomainSegments: 1 }],
  206. ['test\ud800@invalid', false],
  207. ['\"\ud800\"@invalid', false],
  208. ['\"\\\ud800\"@invalid', false],
  209. ['(\ud800)thing@invalid', false],
  210. ['\"\\\ud800\"@invalid', false],
  211. ['test@\ud800\udfffñoñó郵件ñoñó郵件.郵件ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.noñó郵件.商務', true],
  212. ['test@\ud800\udfffñoñó郵件ñoñó郵件.郵件ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.noñó郵件ñoñó郵.商務', false],
  213. ['test@\ud800\udfffñoñó郵件ñoñó郵件.郵件ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.ñoñó郵件ñoñó郵件.oñó郵件ñoñó郵件ñoñó郵件.商務', false],
  214. ['test@ñoñoñó郵件\ud83d\ude06ñoñ.oñó郵件\uc138ñoñ.oñó郵件\u0644\u4eec\u010dñoñoñó郵件\u05dcño.ñoñó郵件\u092f\u672cñoñoñó郵件\uc138añoñ.oñó郵件\ud83d\ude06bc\uc138郵\ud83d\ude06ño.ñoñó郵件ñoñoñó郵件\ud83d\ude06ñoñoñó郵件\uc138ñoñ.oñó郵件\u0644\u4eecñoñoñó.郵件\ud83d\ude06ñoñoñó郵件郵\uc138ñoñoñó郵件\u0644\u4eecñoñoñó郵件.\ud83d\ude06ñoñoñó郵件郵\uc138\u0644\u4eec.郵件\ud83d\ude06ñoñoñó郵.件郵\uc138\u4eec\ud83d\ude06ñoñoñó件郵\uc138ñoñoñó郵件', false],
  215. ['test@ñoñó郵件ñoñó郵件ñoñó郵件ñoñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件ñoñó郵件.商務', false],
  216. ['\ud83d\ude06ñoñó郵件ñoñó郵件ñoñó\ud83d\ude06郵件ñoñoñó郵@\ud83d\ude06郵件ñoñó郵件ñoñó.\ud83d\ude06郵件ñoñó郵件ñoñó.\ud83d\ude06郵件ñoñó郵件ñoñó.郵件ñoñó郵件ñoñó\ud83d\ude06.郵件ñoñó郵件ñoñó.郵件ñoñó郵件.ñoñó郵件ñoñó.郵件ñoñó郵件.\ud83d\ude06郵件ñoñó郵件ñoñó.\ud83d\ude06郵件ñoñó郵件ñoñó.\ud83d\ude06商務.郵件ñoñó郵件ñoñó郵件.\ud83d\ude06商務.\ud83d\ude06商務.\ud83d\ude06商務', false]
  217. ];
  218. exports.compare = {
  219. address: function () {
  220. for (const test of tests) {
  221. Address.email.isValid(test[0]);
  222. }
  223. },
  224. isemail: function () {
  225. for (const test of tests) {
  226. Isemail.validate(test[0]);
  227. }
  228. }
  229. };
  230. Bench.runMain();