-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/pure-fix-tests
- Loading branch information
Showing
9 changed files
with
219 additions
and
24 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import 'package:glade_forms/src/src.dart'; | ||
|
||
class IntValidator extends GladeValidator<int> { | ||
IntValidator(); | ||
|
||
/// Compares given value with [min] and [max] values. With [inclusiveInterval] set to true(default), the comparison is inclusive. | ||
void isBetween({ | ||
required int min, | ||
required int max, | ||
OnValidateError<int>? devError, | ||
Object? key, | ||
ShouldValidateCallback<int>? shouldValidate, | ||
bool inclusiveInterval = true, | ||
}) => | ||
satisfy( | ||
(value) => inclusiveInterval ? value >= min && value <= max : value > min && value < max, | ||
devError: devError ?? | ||
(value) => | ||
'Value ${value ?? 'NULL'} (inclusiveInterval: $inclusiveInterval) is not in between $min and $max.', | ||
key: key ?? GladeErrorKeys.intCompareError, | ||
shouldValidate: shouldValidate, | ||
); | ||
|
||
/// Compares given value with [min] value. | ||
void isMin({ | ||
required int min, | ||
OnValidateError<int>? devError, | ||
Object? key, | ||
ShouldValidateCallback<int>? shouldValidate, | ||
}) => | ||
satisfy( | ||
(value) => value >= min, | ||
devError: devError ?? (value) => 'Value ${value ?? 'NULL'} is less than $min.', | ||
key: key ?? GladeErrorKeys.intCompareError, | ||
shouldValidate: shouldValidate, | ||
); | ||
|
||
/// Compares given value with [max] value. | ||
void isMax({ | ||
required int max, | ||
OnValidateError<int>? devError, | ||
Object? key, | ||
ShouldValidateCallback<int>? shouldValidate, | ||
}) => | ||
satisfy( | ||
(value) => value <= max, | ||
devError: devError ?? (value) => 'Value ${value ?? 'NULL'} is bigger than $max.', | ||
key: key ?? GladeErrorKeys.intCompareError, | ||
shouldValidate: shouldValidate, | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// ignore_for_file: avoid-unsafe-collection-methods | ||
|
||
import 'package:glade_forms/src/validator/int_validator.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('inBetween', () { | ||
test('success', () { | ||
final validator = (IntValidator()..isBetween(min: 5, max: 10)).build(); | ||
|
||
final result = validator.validate(6); | ||
|
||
expect(result.isValid, isTrue); | ||
expect(result.isInvalid, isFalse); | ||
}); | ||
|
||
test('success inclusive max', () { | ||
final validator = (IntValidator()..isBetween(min: 5, max: 10)).build(); | ||
|
||
final result = validator.validate(10); | ||
|
||
expect(result.isValid, isTrue); | ||
expect(result.isInvalid, isFalse); | ||
}); | ||
|
||
test('success inclusive min', () { | ||
final validator = (IntValidator()..isBetween(min: 5, max: 10)).build(); | ||
|
||
final result = validator.validate(5); | ||
|
||
expect(result.isValid, isTrue); | ||
expect(result.isInvalid, isFalse); | ||
}); | ||
|
||
test('fails non-inclusive max', () { | ||
final validator = (IntValidator()..isBetween(min: 5, max: 10, inclusiveInterval: false)).build(); | ||
|
||
final result = validator.validate(10); | ||
|
||
expect(result.isValid, isFalse); | ||
expect(result.isInvalid, isTrue); | ||
}); | ||
|
||
test('fails non-inclusive min', () { | ||
final validator = (IntValidator()..isBetween(min: 5, max: 10, inclusiveInterval: false)).build(); | ||
|
||
final result = validator.validate(5); | ||
|
||
expect(result.isValid, isFalse); | ||
expect(result.isInvalid, isTrue); | ||
}); | ||
|
||
test('fails', () { | ||
final validator = (IntValidator()..isBetween(min: 5, max: 10)).build(); | ||
|
||
final result = validator.validate(1); | ||
|
||
expect(result.isValid, isFalse); | ||
expect(result.isInvalid, isTrue); | ||
}); | ||
}); | ||
|
||
group('isMax', () { | ||
test('success', () { | ||
final validator = (IntValidator()..isMax(max: 10)).build(); | ||
|
||
final result = validator.validate(5); | ||
|
||
expect(result.isValid, isTrue); | ||
expect(result.isInvalid, isFalse); | ||
}); | ||
|
||
test('fails', () { | ||
final validator = (IntValidator()..isMax(max: 10)).build(); | ||
|
||
final result = validator.validate(25); | ||
|
||
expect(result.isValid, isFalse); | ||
expect(result.isInvalid, isTrue); | ||
}); | ||
}); | ||
|
||
group('isMin', () { | ||
test('success', () { | ||
final validator = (IntValidator()..isMin(min: 1)).build(); | ||
|
||
final result = validator.validate(5); | ||
|
||
expect(result.isValid, isTrue); | ||
expect(result.isInvalid, isFalse); | ||
}); | ||
|
||
test('fails', () { | ||
final validator = (IntValidator()..isMin(min: 10)).build(); | ||
|
||
final result = validator.validate(5); | ||
|
||
expect(result.isValid, isFalse); | ||
expect(result.isInvalid, isTrue); | ||
}); | ||
}); | ||
} |
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