Skip to content

Commit

Permalink
Added a new validator ‘exclusiveMaximum’, closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
František Hába committed Nov 29, 2011
1 parent ad5b9fc commit 189f421
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/amanda.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,12 @@
* Maximum
*/
'maximum': function(property, propertyValue, validator, propertyValidators, callback) {
return (typeof propertyValue !== 'number' || propertyValue > validator) ? callback(true) : callback();
if (typeof propertyValue === 'number') {
var condition = (propertyValidators.exclusiveMinimum) ? propertyValue <= validator : propertyValue < validator;
return (condition) ? callback() : callback(true);
} else {
return callback(true);
}
},

/**
Expand Down
8 changes: 2 additions & 6 deletions tests/validators/maximum.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ exports['Test #1'] = function(test) {
};

[
10,
11,
100,
{},
null,
[],
function() {},
'Hello!'
'Hello!'
].forEach(function(input) {
amanda.validate(input, schema, function(error) {
count += 1;
Expand All @@ -34,11 +35,6 @@ exports['Test #1'] = function(test) {
test.equal(error, undefined);
});

amanda.validate(10, schema, function(error) {
count += 1;
test.equal(error, undefined);
});

test.equal(count, 9);
test.done();

Expand Down

0 comments on commit 189f421

Please sign in to comment.