Skip to content

Commit 7772ef4

Browse files
authored
Merge pull request #531 from awhitford/moreVals
Form Field Validator - removed `double_` and added unit tests.
2 parents 723f1ed + 202d1ae commit 7772ef4

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

lib/src/form_builder_validators.dart

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -244,25 +244,6 @@ class FormBuilderValidators {
244244
};
245245
}
246246

247-
// TODO(any): l10n
248-
/// [FormFieldValidator] that requires the field's value to be a valid double.
249-
static FormFieldValidator double_(
250-
BuildContext context, {
251-
String errorText,
252-
}) {
253-
return (valueCandidate) {
254-
if (null != valueCandidate) {
255-
assert(valueCandidate is String);
256-
if (valueCandidate.isNotEmpty &&
257-
double.tryParse(valueCandidate) == null) {
258-
return errorText ??
259-
FormBuilderLocalizations.of(context).numericErrorText;
260-
}
261-
}
262-
return null;
263-
};
264-
}
265-
266247
/// [FormFieldValidator] that requires the field's value to be a valid credit card number.
267248
static FormFieldValidator creditCard(
268249
BuildContext context, {

test/form_builder_validators_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,38 @@ void main() {
150150
expect(validator('XYZ'), isNotNull);
151151
}));
152152

153+
testWidgets(
154+
'FormBuilderValidators.integer',
155+
(WidgetTester tester) => testValidations(tester, (context) {
156+
final validator = FormBuilderValidators.integer(context);
157+
// Pass
158+
expect(validator(null), isNull);
159+
expect(validator(''), isNull);
160+
expect(validator('0'), isNull);
161+
expect(validator('31'), isNull);
162+
expect(validator('-1'), isNull);
163+
// Fail
164+
expect(validator('-1.01'), isNotNull);
165+
expect(validator('1.'), isNotNull);
166+
expect(validator('A'), isNotNull);
167+
expect(validator('XYZ'), isNotNull);
168+
}));
169+
170+
testWidgets(
171+
'FormBuilderValidators.match',
172+
(WidgetTester tester) => testValidations(tester, (context) {
173+
final validator = FormBuilderValidators.match(context, '^A[0-9]\$');
174+
// Pass
175+
expect(validator(null), isNull);
176+
expect(validator(''), isNull);
177+
expect(validator('A1'), isNull);
178+
expect(validator('A9'), isNull);
179+
// Fail
180+
expect(validator('A'), isNotNull);
181+
expect(validator('Z9'), isNotNull);
182+
expect(validator('A12'), isNotNull);
183+
}));
184+
153185
testWidgets(
154186
'FormBuilderValidators.url',
155187
(WidgetTester tester) => testValidations(tester, (context) {

0 commit comments

Comments
 (0)