|
| 1 | +import 'package:flutter_form_builder/src/extensions/generic_validator.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('GenericValidator -', () { |
| 6 | + test('when type is String and value is empty then return true', () { |
| 7 | + final String value = ''; |
| 8 | + final result = value.emptyValidator(); |
| 9 | + expect(result, isTrue); |
| 10 | + }); |
| 11 | + test('when type is String and value is not empty then return false', () { |
| 12 | + final String value = 'not empty'; |
| 13 | + final result = value.emptyValidator(); |
| 14 | + expect(result, isFalse); |
| 15 | + }); |
| 16 | + test('when type is List and value is empty then return true', () { |
| 17 | + final List<int> value = []; |
| 18 | + final result = value.emptyValidator(); |
| 19 | + expect(result, isTrue); |
| 20 | + }); |
| 21 | + test('when type is List and value is not empty then return false', () { |
| 22 | + final List<int> value = [1, 2, 3]; |
| 23 | + final result = value.emptyValidator(); |
| 24 | + expect(result, isFalse); |
| 25 | + }); |
| 26 | + test('when type is Map and value is empty then return true', () { |
| 27 | + final Map<String, int> value = {}; |
| 28 | + final result = value.emptyValidator(); |
| 29 | + expect(result, isTrue); |
| 30 | + }); |
| 31 | + test('when type is Map and value is not empty then return false', () { |
| 32 | + final Map<String, int> value = {'key': 1}; |
| 33 | + final result = value.emptyValidator(); |
| 34 | + expect(result, isFalse); |
| 35 | + }); |
| 36 | + test('when type is Set and value is empty then return true', () { |
| 37 | + final Set<int> value = {}; |
| 38 | + final result = value.emptyValidator(); |
| 39 | + expect(result, isTrue); |
| 40 | + }); |
| 41 | + test('when type is Set and value is not empty then return false', () { |
| 42 | + final Set<int> value = {1, 2, 3}; |
| 43 | + final result = value.emptyValidator(); |
| 44 | + expect(result, isFalse); |
| 45 | + }); |
| 46 | + test('when type is Iterable and value is empty then return true', () { |
| 47 | + final Iterable<int> value = []; |
| 48 | + final result = value.emptyValidator(); |
| 49 | + expect(result, isTrue); |
| 50 | + }); |
| 51 | + test('when type is Iterable and value is not empty then return false', () { |
| 52 | + final Iterable<int> value = [1, 2, 3]; |
| 53 | + final result = value.emptyValidator(); |
| 54 | + expect(result, isFalse); |
| 55 | + }); |
| 56 | + test('when type is not and empty possible then return false', () { |
| 57 | + final int value = 1; |
| 58 | + final result = value.emptyValidator(); |
| 59 | + expect(result, isFalse); |
| 60 | + }); |
| 61 | + test('when value is null then return true', () { |
| 62 | + final String? value = null; |
| 63 | + final result = value.emptyValidator(); |
| 64 | + expect(result, isTrue); |
| 65 | + }); |
| 66 | + }); |
| 67 | +} |
0 commit comments