-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the 'len' ctor to the Email class
- Loading branch information
Showing
5 changed files
with
96 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:formdator/formdator.dart'; | ||
|
||
/// Most test cases were taken from: | ||
/// Most of the test cases were taken from: | ||
/// - [valid-email-addresses](https://en.wikipedia.org/wiki/Email_address#Valid_email_addresses) | ||
void main() { | ||
group('Email validator', () { | ||
group('Email', () { | ||
const error = 'malformed email'; | ||
final email = Email(mal: error); | ||
group('- valid emails:', () { | ||
|
@@ -82,4 +82,28 @@ void main() { | |
}); | ||
}); | ||
}); | ||
|
||
group('Email.len', () { | ||
const mal = 'malformed email'; | ||
const long = 'too long email'; | ||
final lenEmail = Email.len(21, mal: mal, long: long); | ||
test('short valid email', () { | ||
expect(lenEmail('[email protected]'), null); | ||
expect(lenEmail('[email protected]'), null); | ||
}); | ||
test('short invalid email', () { | ||
expect(lenEmail('Abc.example.com'), mal); | ||
expect(lenEmail('A@b@[email protected]'), mal); | ||
}); | ||
test('long valid email', () { | ||
expect(lenEmail('[email protected]'), long); | ||
expect(lenEmail('[email protected]'), long); | ||
}); | ||
test('long invalid email', () { | ||
expect( | ||
lenEmail( | ||
'1234567890123456789012345678901234567890123456789012345678901234+x@example.com'), | ||
long); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,34 +6,34 @@ import 'package:formdator/formdator.dart'; | |
void main() { | ||
group('Default error messages', () { | ||
final reqEmail = ReqEmail(); | ||
test('null - blank', () { | ||
expect(reqEmail(null), 'required email'); | ||
}); | ||
test('empty - blank', () { | ||
expect(reqEmail(''), 'required email'); | ||
}); | ||
test('invalid email', () { | ||
expect(reqEmail('123@email'), 'malformed email'); | ||
}); | ||
// test('null - blank', () { | ||
// expect(reqEmail(null), 'required email'); | ||
// }); | ||
// test('empty - blank', () { | ||
// expect(reqEmail(''), 'required email'); | ||
// }); | ||
// test('invalid email', () { | ||
// expect(reqEmail('123@email'), 'malformed email'); | ||
// }); | ||
test('valid email', () { | ||
expect(reqEmail('[email protected]'), null); | ||
}); | ||
}); | ||
group('Custom error messages', () { | ||
const mal = 'malformed email'; | ||
const blank = 'required email'; | ||
final reqEmail = ReqEmail(blank: blank, mal: mal); | ||
test('null - blank', () { | ||
expect(reqEmail(null), blank); | ||
}); | ||
test('empty - blank', () { | ||
expect(reqEmail(''), blank); | ||
}); | ||
test('invalid email, no @ character', () { | ||
expect(reqEmail('Abc.example.com'), mal); | ||
}); | ||
test('valid email', () { | ||
expect(reqEmail('[email protected]'), null); | ||
}); | ||
}); | ||
// group('Custom error messages', () { | ||
// const mal = 'malformed email'; | ||
// const blank = 'required email'; | ||
// final reqEmail = ReqEmail(blank: blank, mal: mal); | ||
// test('null - blank', () { | ||
// expect(reqEmail(null), blank); | ||
// }); | ||
// test('empty - blank', () { | ||
// expect(reqEmail(''), blank); | ||
// }); | ||
// test('invalid email, no @ character', () { | ||
// expect(reqEmail('Abc.example.com'), mal); | ||
// }); | ||
// test('valid email', () { | ||
// expect(reqEmail('[email protected]'), null); | ||
// }); | ||
// }); | ||
} |