Permalink
Browse files

Fixed bug in logic for validating the maximum property. Added

corresponding tests.
  • Loading branch information...
1 parent 3361284 commit f75561086a74469474dc506c95fcff8e7ddad37d @ironcamel committed Sep 12, 2011
Showing with 47 additions and 1 deletion.
  1. +1 −1 lib/JSON/Schema.pm
  2. +46 −0 t/02-integer.t
View
2 lib/JSON/Schema.pm
@@ -398,7 +398,7 @@ sub checkProp
else
{
$addError->("must be less than or equal to maximum value " . $schema->{'maximum'})
- unless $value <= $schema->{'minimum'};
+ unless $value <= $schema->{'maximum'};
}
}
if ($schema->{'enum'})
View
46 t/02-integer.t
@@ -0,0 +1,46 @@
+use Test::More;
+use strict;
+use warnings;
+use JSON::Schema;
+
+my $schema = JSON::Schema->new({
+ type => 'object',
+ properties => {
+ mynumber => { type => 'integer', minimum => 1, maximum=>4 }
+ }
+});
+
+subtest 'maximum minimum integer' => sub {
+ my $data = { mynumber => 1 };
+ my $result = $schema->validate($data);
+ ok $result, 'min'
+ or map { diag "reason: $_" } $result->errors;
+
+ $data = { mynumber => 4 };
+ $result = $schema->validate($data);
+ ok $result, 'max'
+ or map { diag "reason: $_" } $result->errors;
+
+ $data = { mynumber => 2 };
+ $result = $schema->validate($data);
+ ok $result, 'in the middle'
+ or map { diag "reason: $_" } $result->errors;
+
+ $data = { mynumber => 0};
+ $result = $schema->validate($data);
+ ok !$result, 'too small'
+ or map { diag "reason: $_" } $result->errors;
+
+ $data = { mynumber => -1 };
+ $result = $schema->validate($data);
+ ok !$result, 'too small and neg'
+ or map { diag "reason: $_" } $result->errors;
+
+ $data = { mynumber => 5 };
+ $result = $schema->validate($data);
+ ok !$result, 'too big'
+ or map { diag "reason: $_" } $result->errors;
+};
+
+done_testing;
+

0 comments on commit f755610

Please sign in to comment.