diff --git a/.gitignore b/.gitignore index f519ca06..00eaddbb 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ doc/api/ pubspec.lock log.txt + +.idea \ No newline at end of file diff --git a/README.md b/README.md index 3b7061eb..812fc495 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # validate -[![version 1.0.1](https://img.shields.io/badge/pub-v1.0.1-brightgreen.svg)](https://pub.dartlang.org/packages/angel_validate) +[![version 1.0.2](https://img.shields.io/badge/pub-v1.0.2-brightgreen.svg)](https://pub.dartlang.org/packages/angel_validate) [![build status](https://travis-ci.org/angel-dart/validate.svg)](https://travis-ci.org/angel-dart/validate) [Live Example](https://angel-dart.github.io/validate) diff --git a/lib/src/validator.dart b/lib/src/validator.dart index 5d0c1c22..1cb1007d 100644 --- a/lib/src/validator.dart +++ b/lib/src/validator.dart @@ -61,30 +61,33 @@ class Validator extends Matcher { final List requiredFields = []; void _importSchema(Map schema) { - for (var key in schema.keys) { - var fieldName = key - .replaceAll(_asterisk, '') - .replaceAll(_forbidden, '') - .replaceAll(_optional, ''); - var isForbidden = _forbidden.hasMatch(key), - isRequired = _asterisk.hasMatch(key); + for (var keys in schema.keys) { + for (var key in keys.split(',')) { + var fieldName = key + .replaceAll(_asterisk, '') + .replaceAll(_forbidden, '') + .replaceAll(_optional, ''); + var isForbidden = _forbidden.hasMatch(key), + isRequired = _asterisk.hasMatch(key); - if (isForbidden) { - forbiddenFields.add(fieldName); - } else if (isRequired) { - requiredFields.add(fieldName); - } + if (isForbidden) { + forbiddenFields.add(fieldName); + } else if (isRequired) { + requiredFields.add(fieldName); + } - Iterable iterable = schema[key] is Iterable ? schema[key] : [schema[key]]; + Iterable iterable = + schema[keys] is Iterable ? schema[keys] : [schema[keys]]; - for (var rule in iterable) { - if (rule is Matcher) { - addRule(fieldName, rule); - } else if (rule is Filter) { - addRule(fieldName, predicate(rule)); - } else { - throw new ArgumentError( - 'Cannot use a(n) ${rule.runtimeType} as a validation rule.'); + for (var rule in iterable) { + if (rule is Matcher) { + addRule(fieldName, rule); + } else if (rule is Filter) { + addRule(fieldName, predicate(rule)); + } else { + throw new ArgumentError( + 'Cannot use a(n) ${rule.runtimeType} as a validation rule.'); + } } } } diff --git a/pubspec.yaml b/pubspec.yaml index e5d3b9a3..b3a0b2f3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: angel_validate description: Cross-platform validation library based on `matcher`. -version: 1.0.1 +version: 1.0.2 author: Tobe O homepage: https://github.com/angel-dart/validate environment: diff --git a/test/basic_test.dart b/test/basic_test.dart index 3429af59..49506a69 100644 --- a/test/basic_test.dart +++ b/test/basic_test.dart @@ -7,7 +7,8 @@ final Validator emailSchema = new Validator({'to': isEmail}, final Validator todoSchema = new Validator({ 'id': [isInt, isPositive], 'text*': isString, - 'completed*': isBool + 'completed*': isBool, + 'foo,bar': [isTrue] }, defaultValues: { 'completed': false }); @@ -33,4 +34,10 @@ main() { var only = filter(inputData, ['foo']); expect(only, equals({'foo': 'bar'})); }); + + test('comma in schema', () { + expect(todoSchema.rules.keys, allOf(contains('foo'), contains('bar'))); + expect([todoSchema.rules['foo'].first, todoSchema.rules['bar'].first], + everyElement(predicate((x) => x == isTrue))); + }); }