### ----------------------------------------------------
### -- Email::Valid
### -- Licenses: Artistic-2.0
### -- Authors: Denis Kanchev <denis@fluxark.com>
### -- File: t/02-simple_valid.t
### ----------------------------------------------------
use v6;
use Test;

plan 54;
use Email::Valid;
my Email::Valid $validator .= new();

nok $validator.validate('taaach'), 'taaach';
nok $validator.validate('ta@aach'), 'ta@aach';
nok $validator.validate('taaach@'), 'taaach@';
ok $validator.validate('ta@aa.ch'), 'ta@aa.ch';
nok $validator.validate('t@aa.ch'), 'ta@aa.ch';
ok $validator.validate('test@gmail.co.uk'), 'test@gmail.co.uk OK';
ok $validator.validate('test@gmail.com'), 'test@gmail.com OK';
ok $validator.validate('t.123+asd@aa.tr'), 't.123+asd@aa.tr OK' ;
nok $validator.validate('-t.123+asd@aa.tr'), '-t.123+asd@aa.tr OK' ;
nok $validator.validate('t.123+asd-@aa.tr'), 't.123-@aa.tr OK' ;
nok $validator.validate('.ta@aa.tr'), '.ta@aa.tr OK' ;
nok $validator.validate('ta.@aa.tr'), 'ta.@aa.tr OK' ;
nok $validator.validate('ta@-aa.tr'), 'ta.@-aa.tr OK' ;
nok $validator.validate('ta@aa.-aa.tr'), 'ta.@aa.-aa.tr OK' ;
nok $validator.validate('test@aa-.tr'), 'test@aa-.tr OK' ;
nok $validator.validate('test@aa-.wt.tr'), 'test@aa-.wt.tr OK' ;
ok $validator.validate('ta@aa-wt.tr'), 'ta.@aa-wt.tr OK' ;
ok $validator.validate('ta@a.ch'), 'ta@a.ch OK' ;
nok $validator.validate('ta@a.c'), 'ta@a.c OK' ;
nok $validator.validate('12345678901234567890123456789012345678901234567890123456789012345@aa.tr'), 'Test long mailbox' ;
nok $validator.validate('wtf@1234567890123456789012345678901234567890123456789012345678901234.tr'), 'Test long host part 1' ;
ok $validator.validate('wtf@123456789012345678901234567890123456789012345678901234567890123.tr'), 'Test long host part 2' ;
ok $validator.validate('wtf@'~("1234567890." xx 3).join~'a.tr'), 'Subdomain number limit 1' ;
nok $validator.validate('wtf@'~("1234567890." xx 4).join~'a.tr'), 'Subdomain number limit 2' ;
nok $validator.validate('wtf@'~((("a" xx 63).join~'.') xx 3).join~'a.traftagag'), 'Domain length limit with 207 chars' ;
ok $validator.validate('wtf@'~((("a" xx 58).join~'.') xx 3).join~'a.tr'), 'Domain length limit with 185 chars' ;
ok $validator.validate('wtf@dom.trfgttrfgttrfgt'), 'Test long tld part 1' ;
ok $validator.validate('wtf@dom.trfgttrfgttrfg'), 'Test long tld part 2' ;
ok $validator.validate('box@xn--c1arf.xn--e1aybc.xn--90ae' ), 'IDN domain with idn TLD';
ok $validator.validate('кутия@xn--c1arf.xn--e1aybc.xn--90ae' ), 'IDN domain with idn TLD & cyrillic mailbox';
ok $validator.validate('omg@xn----7sbabaju1atr8asehc6bb.com' ), 'IDN domain with idn TLD & cyrillic mailbox2';
nok $validator.validate('omg@xn-_--7sbabaju1atr8asehc6bb.com' ), 'IDN domain with idn TLD & cyrillic mailbox & underscore';
nok $validator.validate('omg@-wf--7sbabaju1atr8asehc6bb.com' ), 'IDN domain with idn TLD & cyrillic mailbox & start hypen';
ok $validator.validate('кутия@тест.ру' ), 'Cyrillic mailbox & domain';
ok $validator.validate('кутия@те-ст.ру' ), 'Cyrillic mailbox & domain2';
nok $validator.validate('кутия@те_ст.ру' ), 'Cyrillic mailbox & domain underscore';

nok $validator.validate('"wtf is this"@test.ws' ), 'Quoted email';
nok $validator.validate('" "@test.ws' ), 'Quoted with empty space';
nok $validator.validate('"a"@test.ws' ), 'Quoted with 1 alpha';
nok $validator.validate('""@test.ws' ), 'Quoted empty';
nok $validator.validate('"a=a"@test.ws' ), 'Quoted =';
nok $validator.validate('"="@test.ws' ), 'Quoted = empty';


$validator = Email::Valid.new(:allow-quoted);

ok $validator.validate('"wtf is this"@test.ws' ), 'Quoted email';
ok $validator.validate('" "@test.ws' ), 'Quoted with empty space';
ok $validator.validate('"a"@test.ws' ), 'Quoted with 1 alpha';
nok $validator.validate('""@test.ws' ), 'Quoted empty';
nok $validator.validate('"a=a"@test.ws' ), 'Quoted =';
nok $validator.validate('"="@test.ws' ), 'Quoted = empty';
nok $validator.validate('test@ma_ail.com' ), 'Underscore';
nok $validator.validate('test@ma_.com' ), 'Underscore2';
nok $validator.validate('test@ma_-.com' ), 'Underscore3';
nok $validator.validate('test@123_321.com' ), 'Underscore4';
nok $validator.validate('test@xx-----321.com' ), 'RFC-5891 4.2.3.1 3,4 pos';
ok $validator.validate('test@xn-----321.com' ), 'RFC-5891 4.2.3.1 puny exclude';


