commas
This commit is contained in:
parent
72d1e1d2bf
commit
2ffd607230
5 changed files with 36 additions and 24 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -27,3 +27,5 @@ doc/api/
|
||||||
pubspec.lock
|
pubspec.lock
|
||||||
|
|
||||||
log.txt
|
log.txt
|
||||||
|
|
||||||
|
.idea
|
|
@ -1,5 +1,5 @@
|
||||||
# validate
|
# 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)
|
[![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)
|
[Live Example](https://angel-dart.github.io/validate)
|
||||||
|
|
|
@ -61,30 +61,33 @@ class Validator extends Matcher {
|
||||||
final List<String> requiredFields = [];
|
final List<String> requiredFields = [];
|
||||||
|
|
||||||
void _importSchema(Map<String, dynamic> schema) {
|
void _importSchema(Map<String, dynamic> schema) {
|
||||||
for (var key in schema.keys) {
|
for (var keys in schema.keys) {
|
||||||
var fieldName = key
|
for (var key in keys.split(',')) {
|
||||||
.replaceAll(_asterisk, '')
|
var fieldName = key
|
||||||
.replaceAll(_forbidden, '')
|
.replaceAll(_asterisk, '')
|
||||||
.replaceAll(_optional, '');
|
.replaceAll(_forbidden, '')
|
||||||
var isForbidden = _forbidden.hasMatch(key),
|
.replaceAll(_optional, '');
|
||||||
isRequired = _asterisk.hasMatch(key);
|
var isForbidden = _forbidden.hasMatch(key),
|
||||||
|
isRequired = _asterisk.hasMatch(key);
|
||||||
|
|
||||||
if (isForbidden) {
|
if (isForbidden) {
|
||||||
forbiddenFields.add(fieldName);
|
forbiddenFields.add(fieldName);
|
||||||
} else if (isRequired) {
|
} else if (isRequired) {
|
||||||
requiredFields.add(fieldName);
|
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) {
|
for (var rule in iterable) {
|
||||||
if (rule is Matcher) {
|
if (rule is Matcher) {
|
||||||
addRule(fieldName, rule);
|
addRule(fieldName, rule);
|
||||||
} else if (rule is Filter) {
|
} else if (rule is Filter) {
|
||||||
addRule(fieldName, predicate(rule));
|
addRule(fieldName, predicate(rule));
|
||||||
} else {
|
} else {
|
||||||
throw new ArgumentError(
|
throw new ArgumentError(
|
||||||
'Cannot use a(n) ${rule.runtimeType} as a validation rule.');
|
'Cannot use a(n) ${rule.runtimeType} as a validation rule.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: angel_validate
|
name: angel_validate
|
||||||
description: Cross-platform validation library based on `matcher`.
|
description: Cross-platform validation library based on `matcher`.
|
||||||
version: 1.0.1
|
version: 1.0.2
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/validate
|
homepage: https://github.com/angel-dart/validate
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -7,7 +7,8 @@ final Validator emailSchema = new Validator({'to': isEmail},
|
||||||
final Validator todoSchema = new Validator({
|
final Validator todoSchema = new Validator({
|
||||||
'id': [isInt, isPositive],
|
'id': [isInt, isPositive],
|
||||||
'text*': isString,
|
'text*': isString,
|
||||||
'completed*': isBool
|
'completed*': isBool,
|
||||||
|
'foo,bar': [isTrue]
|
||||||
}, defaultValues: {
|
}, defaultValues: {
|
||||||
'completed': false
|
'completed': false
|
||||||
});
|
});
|
||||||
|
@ -33,4 +34,10 @@ main() {
|
||||||
var only = filter(inputData, ['foo']);
|
var only = filter(inputData, ['foo']);
|
||||||
expect(only, equals({'foo': 'bar'}));
|
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)));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue