Permalink
Browse files

use exclusiveMaximum/Minimum according to https://groups.google.com/f…

  • Loading branch information...
marianoguerra committed Jul 10, 2012
1 parent 0b16a43 commit f45d6c1211480a9cc7f9ecb13bba726a897805cc
Showing with 28 additions and 43 deletions.
  1. +28 −33 src/json.schema.js
  2. +0 −10 test/json.edit.test.js
View
@@ -256,11 +256,7 @@
}
if (schema.minItems !== undefined) {
- if (schema.exclusiveMinimum) {
- size = schema.minItems + 1;
- } else {
- size = schema.minItems;
- }
+ size = schema.minItems;
if (value.length < size) {
return failed(errs.ARRAY_TOO_SMALL, {
@@ -272,11 +268,7 @@
}
if (schema.maxItems !== undefined) {
- if (schema.exclusiveMaximum) {
- size = schema.maxItems - 1;
- } else {
- size = schema.maxItems;
- }
+ size = schema.maxItems;
if (value.length > size) {
return failed(errs.ARRAY_TOO_BIG, {
@@ -427,31 +419,42 @@
}
if (schema.minimum !== undefined) {
+ size = schema.minimum;
+
if (schema.exclusiveMinimum) {
+ if (value <= size) {
+ return failed(errs.NUM_TOO_SMALL, {
+ minimum: size
+ });
+ }
size = schema.minimum + 1;
} else {
- size = schema.minimum;
+ if (value < size) {
+ return failed(errs.NUM_TOO_SMALL, {
+ minimum: size
+ });
+ }
}
- if (value < size) {
- return failed(errs.NUM_TOO_SMALL, {
- minimum: schema.minimum
- });
- }
}
if (schema.maximum !== undefined) {
+ size = schema.maximum;
+
if (schema.exclusiveMaximum) {
- size = schema.maximum - 1;
+ if (value >= size) {
+ return failed(errs.NUM_TOO_BIG, {
+ maximum: size
+ });
+ }
} else {
- size = schema.maximum;
+ if (value > size) {
+ return failed(errs.NUM_TOO_BIG, {
+ maximum: size
+ });
+ }
}
- if (value > size) {
- return failed(errs.NUM_TOO_BIG, {
- maximum: schema.maximum
- });
- }
}
if (!priv.checkEnum(value, schema)) {
@@ -536,11 +539,7 @@
}
if (schema.minLength !== undefined) {
- if (schema.exclusiveMinimum) {
- size = schema.minLength + 1;
- } else {
- size = schema.minLength;
- }
+ size = schema.minLength;
if (value.length < size) {
return failed(errs.TOO_SMALL, {
@@ -552,11 +551,7 @@
}
if (schema.maxLength !== undefined) {
- if (schema.exclusiveMaximum) {
- size = schema.maxLength - 1;
- } else {
- size = schema.maxLength;
- }
+ size = schema.maxLength;
if (value.length > size) {
return failed(errs.TOO_BIG, {
View
@@ -410,9 +410,7 @@ require(["json.edit", "json.schema", "jquery", "qunit", "json"], function (jsonE
checkValidation("", {type: "string", minLength: 1}, false, "name", errs.TO_SMALL);
- checkValidation("", {type: "string", minLength: 0, exclusiveMinimum: true}, false, "name", errs.TO_SMALL);
checkValidation("a", {type: "string", minLength: 2}, false, "name", errs.TO_SMALL);
- checkValidation("a", {type: "string", minLength: 1, exclusiveMinimum: true}, false, "name", errs.TO_SMALL);
checkValidation("", {type: "string", maxLength: 0}, true);
@@ -422,9 +420,7 @@ require(["json.edit", "json.schema", "jquery", "qunit", "json"], function (jsonE
checkValidation("a", {type: "string", maxLength: 1}, true, "num", null, true);
checkValidation("aa", {type: "string", maxLength: 1}, false, "name", errs.TO_BIG);
- checkValidation("aa", {type: "string", maxLength: 2, exclusiveMaximum: true}, false, "name", errs.TO_BIG);
checkValidation("a", {type: "string", maxLength: 0}, false, "name", errs.TO_BIG);
- checkValidation("a", {type: "string", maxLength: 1, exclusiveMaximum: true}, false, "name", errs.TO_BIG);
checkValidation("a", {type: "string", "enum": ['a']}, true);
checkValidation("b", {type: "string", "enum": ['a', 'b']}, true);
@@ -611,22 +607,16 @@ require(["json.edit", "json.schema", "jquery", "qunit", "json"], function (jsonE
});
checkValidation([], {type: "array", minItems: 0}, true);
- checkValidation([1], {type: "array", minItems: 0, exclusiveMinimum: true}, true);
checkValidation([], {type: "array", minItems: 1}, false, "items", errs.ARRAY_TOO_SMALL);
- checkValidation([], {type: "array", minItems: 0, exclusiveMinimum: true}, false, "items", errs.ARRAY_TOO_SMALL);
checkValidation([1], {type: "array", minItems: 2}, false, "items", errs.ARRAY_TOO_SMALL);
- checkValidation([1], {type: "array", minItems: 1, exclusiveMinimum: true}, false, "items", errs.ARRAY_TOO_SMALL);
checkValidation([], {type: "array", maxItems: 0}, true);
- checkValidation([1], {type: "array", maxItems: 2, exclusiveMaximum: true}, true);
checkValidation([1, 2, 3], {type: "array", maxItems: 1}, false, "items", errs.ARRAY_TOO_BIG);
- checkValidation([1, 2], {type: "array", maxItems: 0, exclusiveMaximum: true}, false, "items", errs.ARRAY_TOO_BIG);
checkValidation([1, 2, 3], {type: "array", maxItems: 2}, false, "items", errs.ARRAY_TOO_BIG);
- checkValidation([1, 2], {type: "array", maxItems: 1, exclusiveMaximum: true}, false, "items", errs.ARRAY_TOO_BIG);
checkValidation([], {type: "array", uniqueItems: true}, true);
checkValidation([1], {type: "array", uniqueItems: true}, true);

0 comments on commit f45d6c1

Please sign in to comment.