var expect = require('chai').expect;

// diagnoses
var diagnoses = {
  ISEMAIL_VALID: 0,
  ISEMAIL_DNSWARN_NO_MX_RECORD: 5,
  ISEMAIL_DNSWARN_NO_RECORD: 6,
  ISEMAIL_RFC5321_TLD: 9,
  ISEMAIL_RFC5321_TLDNUMERIC: 10,
  ISEMAIL_RFC5321_QUOTEDSTRING: 11,
  ISEMAIL_RFC5321_ADDRESSLITERAL: 12,
  ISEMAIL_RFC5321_IPV6DEPRECATED: 13,
  ISEMAIL_CFWS_COMMENT: 17,
  ISEMAIL_CFWS_FWS: 18,
  ISEMAIL_DEPREC_LOCALPART: 33,
  ISEMAIL_DEPREC_FWS: 34,
  ISEMAIL_DEPREC_QTEXT: 35,
  ISEMAIL_DEPREC_QP: 36,
  ISEMAIL_DEPREC_COMMENT: 37,
  ISEMAIL_DEPREC_CTEXT: 38,
  ISEMAIL_DEPREC_CFWS_NEAR_AT: 49,
  ISEMAIL_RFC5322_DOMAIN: 65,
  ISEMAIL_RFC5322_TOOLONG: 66,
  ISEMAIL_RFC5322_LOCAL_TOOLONG: 67,
  ISEMAIL_RFC5322_DOMAIN_TOOLONG: 68,
  ISEMAIL_RFC5322_LABEL_TOOLONG: 69,
  ISEMAIL_RFC5322_DOMAINLITERAL: 70,
  ISEMAIL_RFC5322_DOMLIT_OBSDTEXT: 71,
  ISEMAIL_RFC5322_IPV6_GRPCOUNT: 72,
  ISEMAIL_RFC5322_IPV6_2X2XCOLON: 73,
  ISEMAIL_RFC5322_IPV6_BADCHAR: 74,
  ISEMAIL_RFC5322_IPV6_MAXGRPS: 75,
  ISEMAIL_RFC5322_IPV6_COLONSTRT: 76,
  ISEMAIL_RFC5322_IPV6_COLONEND: 77,
  ISEMAIL_ERR_EXPECTING_DTEXT: 129,
  ISEMAIL_ERR_NOLOCALPART: 130,
  ISEMAIL_ERR_NODOMAIN: 131,
  ISEMAIL_ERR_CONSECUTIVEDOTS: 132,
  ISEMAIL_ERR_ATEXT_AFTER_CFWS: 133,
  ISEMAIL_ERR_ATEXT_AFTER_QS: 134,
  ISEMAIL_ERR_ATEXT_AFTER_DOMLIT: 135,
  ISEMAIL_ERR_EXPECTING_QPAIR: 136,
  ISEMAIL_ERR_EXPECTING_ATEXT: 137,
  ISEMAIL_ERR_EXPECTING_QTEXT: 138,
  ISEMAIL_ERR_EXPECTING_CTEXT: 139,
  ISEMAIL_ERR_BACKSLASHEND: 140,
  ISEMAIL_ERR_DOT_START: 141,
  ISEMAIL_ERR_DOT_END: 142,
  ISEMAIL_ERR_DOMAINHYPHENSTART: 143,
  ISEMAIL_ERR_DOMAINHYPHENEND: 144,
  ISEMAIL_ERR_UNCLOSEDQUOTEDSTR: 145,
  ISEMAIL_ERR_UNCLOSEDCOMMENT: 146,
  ISEMAIL_ERR_UNCLOSEDDOMLIT: 147,
  ISEMAIL_ERR_FWS_CRLF_X2: 148,
  ISEMAIL_ERR_FWS_CRLF_END: 149,
  ISEMAIL_ERR_CR_NO_LF: 150,
  ISEMAIL_ERR_UNKNOWN_TLD: 160,
  ISEMAIL_ERR_TOOSHORT_TLD: 161
};

// expectations
var expectations = [
  ['', diagnoses.ISEMAIL_ERR_NODOMAIN],
  ['test', diagnoses.ISEMAIL_ERR_NODOMAIN],
  ['@', diagnoses.ISEMAIL_ERR_NOLOCALPART],
  ['test@', diagnoses.ISEMAIL_ERR_NODOMAIN],
  ['test@io', diagnoses.ISEMAIL_VALID],
  ['@io', diagnoses.ISEMAIL_ERR_NOLOCALPART],
  ['@iana.org', diagnoses.ISEMAIL_ERR_NOLOCALPART],
  ['test@iana.org', diagnoses.ISEMAIL_VALID],
  ['test@nominet.org.uk', diagnoses.ISEMAIL_VALID],
  ['test@about.museum', diagnoses.ISEMAIL_VALID],
  ['a@iana.org', diagnoses.ISEMAIL_VALID],
  ['test@e.com', diagnoses.ISEMAIL_DNSWARN_NO_RECORD],
  ['test@iana.a', diagnoses.ISEMAIL_DNSWARN_NO_RECORD],
  ['test.test@iana.org', diagnoses.ISEMAIL_VALID],
  ['.test@iana.org', diagnoses.ISEMAIL_ERR_DOT_START],
  ['test.@iana.org', diagnoses.ISEMAIL_ERR_DOT_END],
  ['test..iana.org', diagnoses.ISEMAIL_ERR_CONSECUTIVEDOTS],
  ['test_exa-mple.com', diagnoses.ISEMAIL_ERR_NODOMAIN],
  ['!#$%&`*+/=?^`{|}~@iana.org', diagnoses.ISEMAIL_VALID],
  ['test\\@test@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['123@iana.org', diagnoses.ISEMAIL_VALID],
  ['test@123.com', diagnoses.ISEMAIL_VALID],
  ['test@iana.123', diagnoses.ISEMAIL_RFC5321_TLDNUMERIC],
  ['test@255.255.255.255', diagnoses.ISEMAIL_RFC5321_TLDNUMERIC],
  ['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@iana.org', diagnoses.ISEMAIL_VALID],
  ['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklmn@iana.org', diagnoses.ISEMAIL_RFC5322_LOCAL_TOOLONG],
  ['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm', diagnoses.ISEMAIL_RFC5322_LABEL_TOOLONG],
  ['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.com', diagnoses.ISEMAIL_DNSWARN_NO_RECORD],
  ['test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm.com', diagnoses.ISEMAIL_RFC5322_LABEL_TOOLONG],
  ['test@mason-dixon.com', diagnoses.ISEMAIL_VALID],
  ['test@-iana.org', diagnoses.ISEMAIL_ERR_DOMAINHYPHENSTART],
  ['test@iana-.com', diagnoses.ISEMAIL_ERR_DOMAINHYPHENEND],
  ['test@aaad.com', diagnoses.ISEMAIL_DNSWARN_NO_MX_RECORD],
  ['test@iana.co-uk', diagnoses.ISEMAIL_DNSWARN_NO_RECORD],
  ['test@.iana.org', diagnoses.ISEMAIL_ERR_DOT_START],
  ['test@iana.org.', diagnoses.ISEMAIL_ERR_DOT_END],
  ['test@iana..com', diagnoses.ISEMAIL_ERR_CONSECUTIVEDOTS],
  ['a@a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v', diagnoses.ISEMAIL_DNSWARN_NO_RECORD],
  ['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi', diagnoses.ISEMAIL_DNSWARN_NO_RECORD],
  ['abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghij', diagnoses.ISEMAIL_RFC5322_TOOLONG],
  ['a@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.hij', diagnoses.ISEMAIL_RFC5322_TOOLONG],
  ['a@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.hijk', diagnoses.ISEMAIL_RFC5322_DOMAIN_TOOLONG],
  ['"test"@iana.org', diagnoses.ISEMAIL_RFC5321_QUOTEDSTRING],
  ['""@iana.org', diagnoses.ISEMAIL_RFC5321_QUOTEDSTRING],
  ['"""@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['"\\a"@iana.org', diagnoses.ISEMAIL_RFC5321_QUOTEDSTRING],
  ['"\\""@iana.org', diagnoses.ISEMAIL_RFC5321_QUOTEDSTRING],
  ['"\\"@iana.org', diagnoses.ISEMAIL_ERR_UNCLOSEDQUOTEDSTR],
  ['"\\\\"@iana.org', diagnoses.ISEMAIL_RFC5321_QUOTEDSTRING],
  ['test"@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['"test@iana.org', diagnoses.ISEMAIL_ERR_UNCLOSEDQUOTEDSTR],
  ['"test"test@iana.org', diagnoses.ISEMAIL_ERR_ATEXT_AFTER_QS],
  ['test"text"@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['"test""test"@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['"test"."test"@iana.org', diagnoses.ISEMAIL_DEPREC_LOCALPART],
  ['"test\\ test"@iana.org', diagnoses.ISEMAIL_RFC5321_QUOTEDSTRING],
  ['"test".test@iana.org', diagnoses.ISEMAIL_DEPREC_LOCALPART],
  ['"test\0"@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_QTEXT],
  ['"test\\\0"@iana.org', diagnoses.ISEMAIL_DEPREC_QP],
  ['"test\r\n test"@iana.org', diagnoses.ISEMAIL_CFWS_FWS],
  ['"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefghj"@iana.org', diagnoses.ISEMAIL_RFC5322_LOCAL_TOOLONG],
  ['"abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz abcdefg\\h"@iana.org', diagnoses.ISEMAIL_RFC5322_LOCAL_TOOLONG],
  ['test@[255.255.255.255]', diagnoses.ISEMAIL_RFC5321_ADDRESSLITERAL],
  ['test@a[255.255.255.255]', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['test@[255.255.255]', diagnoses.ISEMAIL_RFC5322_DOMAINLITERAL],
  ['test@[255.255.255.255.255]', diagnoses.ISEMAIL_RFC5322_DOMAINLITERAL],
  ['test@[255.255.255.256]', diagnoses.ISEMAIL_RFC5322_DOMAINLITERAL],
  ['test@[1111:2222:3333:4444:5555:6666:7777:8888]', diagnoses.ISEMAIL_RFC5322_DOMAINLITERAL],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777]', diagnoses.ISEMAIL_RFC5322_IPV6_GRPCOUNT],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]', diagnoses.ISEMAIL_RFC5321_ADDRESSLITERAL],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]', diagnoses.ISEMAIL_RFC5322_IPV6_GRPCOUNT],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:888G]', diagnoses.ISEMAIL_RFC5322_IPV6_BADCHAR],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666::8888]', diagnoses.ISEMAIL_RFC5321_IPV6DEPRECATED],
  ['test@[IPv6:1111:2222:3333:4444:5555::8888]', diagnoses.ISEMAIL_RFC5321_ADDRESSLITERAL],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666::7777:8888]', diagnoses.ISEMAIL_RFC5322_IPV6_MAXGRPS],
  ['test@[IPv6::3333:4444:5555:6666:7777:8888]', diagnoses.ISEMAIL_RFC5322_IPV6_COLONSTRT],
  ['test@[IPv6:::3333:4444:5555:6666:7777:8888]', diagnoses.ISEMAIL_RFC5321_ADDRESSLITERAL],
  ['test@[IPv6:1111::4444:5555::8888]', diagnoses.ISEMAIL_RFC5322_IPV6_2X2XCOLON],
  ['test@[IPv6:::]', diagnoses.ISEMAIL_RFC5321_ADDRESSLITERAL],
  ['test@[IPv6:1111:2222:3333:4444:5555:255.255.255.255]', diagnoses.ISEMAIL_RFC5322_IPV6_GRPCOUNT],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666:255.255.255.255]', diagnoses.ISEMAIL_RFC5321_ADDRESSLITERAL],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666:7777:255.255.255.255]', diagnoses.ISEMAIL_RFC5322_IPV6_GRPCOUNT],
  ['test@[IPv6:1111:2222:3333:4444::255.255.255.255]', diagnoses.ISEMAIL_RFC5321_ADDRESSLITERAL],
  ['test@[IPv6:1111:2222:3333:4444:5555:6666::255.255.255.255]', diagnoses.ISEMAIL_RFC5322_IPV6_MAXGRPS],
  ['test@[IPv6:1111:2222:3333:4444:::255.255.255.255]', diagnoses.ISEMAIL_RFC5322_IPV6_2X2XCOLON],
  ['test@[IPv6::255.255.255.255]', diagnoses.ISEMAIL_RFC5322_IPV6_COLONSTRT],
  [' test @iana.org', diagnoses.ISEMAIL_DEPREC_CFWS_NEAR_AT],
  ['test@ iana .com', diagnoses.ISEMAIL_DEPREC_CFWS_NEAR_AT],
  ['test . test@iana.org', diagnoses.ISEMAIL_DEPREC_FWS],
  ['\r\n test@iana.org', diagnoses.ISEMAIL_CFWS_FWS],
  ['\r\n \r\n test@iana.org', diagnoses.ISEMAIL_DEPREC_FWS],
  ['(comment)test@iana.org', diagnoses.ISEMAIL_CFWS_COMMENT],
  ['((comment)test@iana.org', diagnoses.ISEMAIL_ERR_UNCLOSEDCOMMENT],
  ['(comment(comment))test@iana.org', diagnoses.ISEMAIL_CFWS_COMMENT],
  ['test@(comment)iana.org', diagnoses.ISEMAIL_DEPREC_CFWS_NEAR_AT],
  ['test(comment)test@iana.org', diagnoses.ISEMAIL_ERR_ATEXT_AFTER_CFWS],
  ['test@(comment)[255.255.255.255]', diagnoses.ISEMAIL_DEPREC_CFWS_NEAR_AT],
  ['(comment)abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@iana.org', diagnoses.ISEMAIL_CFWS_COMMENT],
  ['test@(comment)abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.com', diagnoses.ISEMAIL_DEPREC_CFWS_NEAR_AT],
  ['(comment)test@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghik.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghik.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstu', diagnoses.ISEMAIL_CFWS_COMMENT],
  ['test@iana.org\n', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['test@xn--hxajbheg2az3al.xn--jxalpdlp', diagnoses.ISEMAIL_DNSWARN_NO_RECORD],
  ['xn--test@iana.org', diagnoses.ISEMAIL_VALID],
  ['test@iana.org-', diagnoses.ISEMAIL_ERR_DOMAINHYPHENEND],
  ['"test@iana.org', diagnoses.ISEMAIL_ERR_UNCLOSEDQUOTEDSTR],
  ['(test@iana.org', diagnoses.ISEMAIL_ERR_UNCLOSEDCOMMENT],
  ['test@(iana.org', diagnoses.ISEMAIL_ERR_UNCLOSEDCOMMENT],
  ['test@[1.2.3.4', diagnoses.ISEMAIL_ERR_UNCLOSEDDOMLIT],
  ['"test\\"@iana.org', diagnoses.ISEMAIL_ERR_UNCLOSEDQUOTEDSTR],
  ['(comment\\)test@iana.org', diagnoses.ISEMAIL_ERR_UNCLOSEDCOMMENT],
  ['test@iana.org(comment\\)', diagnoses.ISEMAIL_ERR_UNCLOSEDCOMMENT],
  ['test@iana.org(comment\\', diagnoses.ISEMAIL_ERR_BACKSLASHEND],
  ['test@[RFC-5322-domain-literal]', diagnoses.ISEMAIL_RFC5322_DOMAINLITERAL],
  ['test@[RFC-5322]-domain-literal]', diagnoses.ISEMAIL_ERR_ATEXT_AFTER_DOMLIT],
  ['test@[RFC-5322-[domain-literal]', diagnoses.ISEMAIL_ERR_EXPECTING_DTEXT],
  ['test@[RFC-5322-\\\x07-domain-literal]', diagnoses.ISEMAIL_RFC5322_DOMLIT_OBSDTEXT],
  ['test@[RFC-5322-\\\t-domain-literal]', diagnoses.ISEMAIL_RFC5322_DOMLIT_OBSDTEXT],
  ['test@[RFC-5322-\\]-domain-literal]', diagnoses.ISEMAIL_RFC5322_DOMLIT_OBSDTEXT],
  ['test@[RFC-5322-\x7f-domain-literal]', diagnoses.ISEMAIL_RFC5322_DOMLIT_OBSDTEXT],
  ['test@[RFC-5322-domain-literal\\]', diagnoses.ISEMAIL_ERR_UNCLOSEDDOMLIT],
  ['test@[RFC-5322-domain-literal\\', diagnoses.ISEMAIL_ERR_BACKSLASHEND],
  ['test@[RFC 5322 domain literal]', diagnoses.ISEMAIL_RFC5322_DOMAINLITERAL],
  ['test@[RFC-5322-domain-literal] (comment)', diagnoses.ISEMAIL_RFC5322_DOMAINLITERAL],
  ['\x7f@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['test@\x7f.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['"\x7f"@iana.org', diagnoses.ISEMAIL_DEPREC_QTEXT],
  ['"\\\x7f"@iana.org', diagnoses.ISEMAIL_DEPREC_QP],
  ['(\x7f)test@iana.org', diagnoses.ISEMAIL_DEPREC_CTEXT],
  ['test@iana.org\r', diagnoses.ISEMAIL_ERR_CR_NO_LF],
  ['\rtest@iana.org', diagnoses.ISEMAIL_ERR_CR_NO_LF],
  ['"\rtest"@iana.org', diagnoses.ISEMAIL_ERR_CR_NO_LF],
  ['(\r)test@iana.org', diagnoses.ISEMAIL_ERR_CR_NO_LF],
  ['test@iana.org(\r)', diagnoses.ISEMAIL_ERR_CR_NO_LF],
  ['\ntest@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['"\n"@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_QTEXT],
  ['"\\\n"@iana.org', diagnoses.ISEMAIL_DEPREC_QP],
  ['(\n)test@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_CTEXT],
  ['\x07@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['test@\x07.org', diagnoses.ISEMAIL_ERR_EXPECTING_ATEXT],
  ['"\x07"@iana.org', diagnoses.ISEMAIL_DEPREC_QTEXT],
  ['"\\\x07"@iana.org', diagnoses.ISEMAIL_DEPREC_QP],
  ['(\x07)test@iana.org', diagnoses.ISEMAIL_DEPREC_CTEXT],
  ['\r\ntest@iana.org', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  ['\r\n \r\ntest@iana.org', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  [' \r\ntest@iana.org', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  [' \r\n test@iana.org', diagnoses.ISEMAIL_CFWS_FWS],
  [' \r\n \r\ntest@iana.org', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  [' \r\n\r\ntest@iana.org', diagnoses.ISEMAIL_ERR_FWS_CRLF_X2],
  [' \r\n\r\n test@iana.org', diagnoses.ISEMAIL_ERR_FWS_CRLF_X2],
  ['test@iana.org\r\n ', diagnoses.ISEMAIL_CFWS_FWS],
  ['test@iana.org\r\n \r\n ', diagnoses.ISEMAIL_DEPREC_FWS],
  ['test@iana.org\r\n', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  ['test@iana.org \r', diagnoses.ISEMAIL_ERR_CR_NO_LF],
  ['test@iana.org\r\n \r\n', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  ['test@iana.org \r\n', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  ['test@iana.org \r\n ', diagnoses.ISEMAIL_CFWS_FWS],
  ['test@iana.org \r\n \r\n', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  ['test@iana.org \r\n\r\n', diagnoses.ISEMAIL_ERR_FWS_CRLF_X2],
  ['test@iana.org \r\n\r\n ', diagnoses.ISEMAIL_ERR_FWS_CRLF_X2],
  ['test@iana. org', diagnoses.ISEMAIL_DEPREC_FWS],
  ['test@[\r', diagnoses.ISEMAIL_ERR_CR_NO_LF],
  ['test@[\r\n', diagnoses.ISEMAIL_ERR_FWS_CRLF_END],
  [' test@iana.org', diagnoses.ISEMAIL_CFWS_FWS],
  ['test@iana.org ', diagnoses.ISEMAIL_CFWS_FWS],
  ['test@[IPv6:1::2:]', diagnoses.ISEMAIL_RFC5322_IPV6_COLONEND],
  ['"test\\©"@iana.org', diagnoses.ISEMAIL_ERR_EXPECTING_QPAIR],
  ['test@iana/icann.org', diagnoses.ISEMAIL_RFC5322_DOMAIN],
  ['test.(comment)test@iana.org', diagnoses.ISEMAIL_DEPREC_COMMENT],
  ['test@iana.(comment)org', diagnoses.ISEMAIL_DEPREC_COMMENT],
  ['test@iana(comment)iana.org', diagnoses.ISEMAIL_ERR_ATEXT_AFTER_CFWS],
  ['(comment\r\n comment)test@iana.org', diagnoses.ISEMAIL_CFWS_FWS],
  ['test@org', diagnoses.ISEMAIL_RFC5321_TLD],
  ['test@example.com', diagnoses.ISEMAIL_DNSWARN_NO_MX_RECORD],
  ['test@nic.no', diagnoses.ISEMAIL_DNSWARN_NO_RECORD]
];

var tldExpectations = [
  ['shouldbe@invalid', diagnoses.ISEMAIL_ERR_UNKNOWN_TLD],
  ['shouldbe@example.com', diagnoses.ISEMAIL_VALID]
];

describe('isEmail', function() {
  var isEmail = require('..');

  expectations.forEach(function(obj, i) {
    var email = obj[0], result = obj[1];
    it('should handle test ' + (i + 1), function(done) {
      isEmail(email, {errorLevel: 0, checkDNS: true}, function(res) {
        expect(res).to.equal(result);
        done();
      });
    });
  });

  tldExpectations.forEach(function(obj, i) {
    var email = obj[0], result = obj[1];
    it('should handle tld test ' + (i + 1), function() {
      var res = isEmail(email, {errorLevel: 0, tldWhitelist: {com: true}});
      expect(res).to.equal(result);

      res = isEmail(email, {errorLevel: 0, tldWhitelist: ['com']});
      expect(res).to.equal(result);
    });
  });

  it('should handle domain atom test 1', function() {
    var res = isEmail('shouldbe@invalid', {errorLevel: 0, minDomainAtoms: 2});

    expect(res).to.equal(diagnoses.ISEMAIL_ERR_TOOSHORT_TLD);
  });

  it('should handle domain atom test 2', function() {
    var res = isEmail('valid@example.com', {errorLevel: 0, minDomainAtoms: 2});

    expect(res).to.equal(diagnoses.ISEMAIL_VALID);
  });
});
