This commit is contained in:
Pine Wu 2019-09-09 15:56:36 -07:00
parent d163340556
commit 55825e9ad2
2 changed files with 13 additions and 0 deletions

View file

@ -1043,6 +1043,13 @@ export function createValidator(prop: IConfigurationPropertySchema): (value: any
const stringArrayValue = value as string[];
if (prop.uniqueItems) {
if (new Set(stringArrayValue).size < stringArrayValue.length) {
message += nls.localize('validations.stringArrayUniqueItems', 'Array has duplicate items');
message += '\n';
}
}
if (prop.minItems && stringArrayValue.length < prop.minItems) {
message += nls.localize('validations.stringArrayMinItem', 'Array must have at least {0} items', prop.minItems);
message += '\n';

View file

@ -328,4 +328,10 @@ suite('Preferences Model test', () => {
arr.rejects(['a']).withMessage(`err: must be friendly`);
});
test('uniqueItems', () => {
const arr = new ArrayTester({ type: 'array', items: { type: 'string' }, uniqueItems: true });
arr.rejects(['a', 'a']).withMessage(`Array has duplicate items`);
});
});