Skip to content

Commit 9a7b1aa

Browse files
Add immutability test case for match allowed extension validator
1 parent 256d2a4 commit 9a7b1aa

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/src/validators/path_validators/matches_allowed_extensions_validator_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,34 @@ void main() {
145145
// It seems to have a bug => https://github.com/dart-lang/core/issues/723
146146
//expect(v('/valid/.a.b'), errorMsg, reason: 'Input: "/valid/.a.b"');
147147
});
148+
149+
test('should be immutable even when the input list of extensions change',
150+
() {
151+
final List<String> validExtensions = <String>['.ext1', '.ext2'];
152+
153+
final Validator<String> v = matchesAllowedExtensions(validExtensions);
154+
expect(v('/valid/v.ext1'), isNull);
155+
expect(v('/valid/v.ext2'), isNull);
156+
expect(
157+
v('/valid/v.ext3'),
158+
FormBuilderLocalizations.current
159+
.fileExtensionErrorText(validExtensions.join(', ')));
160+
161+
validExtensions.removeLast();
162+
expect(v('/valid/v.ext1'), isNull);
163+
expect(v('/valid/v.ext2'), isNull);
164+
expect(
165+
v('/valid/v.ext3'),
166+
FormBuilderLocalizations.current
167+
.fileExtensionErrorText(validExtensions.join(', ')));
168+
169+
validExtensions.add('.ext3');
170+
expect(v('/valid/v.ext1'), isNull);
171+
expect(v('/valid/v.ext2'), isNull);
172+
expect(
173+
v('/valid/v.ext3'),
174+
FormBuilderLocalizations.current
175+
.fileExtensionErrorText(validExtensions.join(', ')));
176+
});
148177
});
149178
}

0 commit comments

Comments
 (0)