@@ -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