Skip to content

Commit 6c1938c

Browse files
committed
add validateFunction for info_array
1 parent a5bc7fe commit 6c1938c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/lib/coerce.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,20 @@ exports.valObjects = {
241241
}
242242

243243
propOut.set(vOut);
244+
},
245+
validateFunction: function(v, opts) {
246+
if(!Array.isArray(v)) return false;
247+
248+
var items = opts.items;
249+
250+
// valid when one item is valid (which is subject to debate)
251+
for(var i = 0; i < items.length; i++) {
252+
var isItemValid = exports.validate(v[i], opts.items[i]);
253+
254+
if(isItemValid) return true;
255+
}
256+
257+
return false;
244258
}
245259
}
246260
};

test/jasmine/tests/lib_test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ describe('Test lib.js:', function() {
770770
});
771771
});
772772

773-
fdescribe('validate', function() {
773+
describe('validate', function() {
774774

775775
function assert(shouldPass, shouldFail, valObject) {
776776
shouldPass.forEach(function(v) {
@@ -974,11 +974,9 @@ describe('Test lib.js:', function() {
974974
});
975975

976976
it('should work for valType \'info_array\' where', function() {
977-
var shouldPass = [[1, 2]],
977+
var shouldPass = [[1, 2], [10], [null, 10], [1, 10, null]],
978978
shouldFail = [{}, [], ['aads', null], 'red', null, undefined, ''];
979979

980-
// This fails. All array including [] are considered valid
981-
982980
assert(shouldPass, shouldFail, {
983981
valType: 'info_array',
984982
items: [{

0 commit comments

Comments
 (0)