MCPcopy
hub / github.com/ajv-validator/ajv / testRangeKeyword

Function testRangeKeyword

spec/keyword.spec.ts:929–979  ·  view source on GitHub ↗
(definition, createsErrors?: boolean, numErrors?: number)

Source from the content-addressed store, hash-verified

927 }
928
929 function testRangeKeyword(definition, createsErrors?: boolean, numErrors?: number) {
930 instances.forEach((_ajv) => {
931 _ajv.addKeyword(definition)
932 _ajv.addKeyword({keyword: "exclusiveRange", schemaType: "boolean"})
933
934 let schema: SchemaObject = {
935 type: ["number", "string"],
936 "x-range": [2, 4],
937 }
938 let validate = _ajv.compile(schema)
939
940 shouldBeValid(validate, 2)
941 shouldBeValid(validate, 3)
942 shouldBeValid(validate, 4)
943 shouldBeValid(validate, "abc")
944
945 shouldBeInvalid(validate, 1.99, numErrors)
946 if (createsErrors) {
947 shouldBeRangeError(validate.errors?.[0], "", "#/x-range", ">=", 2)
948 }
949 shouldBeInvalid(validate, 4.01, numErrors)
950 if (createsErrors) {
951 shouldBeRangeError(validate.errors?.[0], "", "#/x-range", "<=", 4)
952 }
953
954 schema = {
955 type: "object",
956 properties: {
957 foo: {
958 type: ["number"],
959 "x-range": [2, 4],
960 exclusiveRange: true,
961 },
962 },
963 }
964 validate = _ajv.compile(schema)
965
966 shouldBeValid(validate, {foo: 2.01})
967 shouldBeValid(validate, {foo: 3})
968 shouldBeValid(validate, {foo: 3.99})
969
970 shouldBeInvalid(validate, {foo: 2}, numErrors)
971 if (createsErrors) {
972 shouldBeRangeError(validate.errors?.[0], "/foo", "#/properties/foo/x-range", ">", 2, true)
973 }
974 shouldBeInvalid(validate, {foo: 4}, numErrors)
975 if (createsErrors) {
976 shouldBeRangeError(validate.errors?.[0], "/foo", "#/properties/foo/x-range", "<", 4, true)
977 }
978 })
979 }
980
981 function testMultipleRangeKeyword(definition, numErrors?: number) {
982 instances.forEach((_ajv) => {

Callers 1

keyword.spec.tsFile · 0.85

Calls 5

shouldBeRangeErrorFunction · 0.85
shouldBeValidFunction · 0.70
shouldBeInvalidFunction · 0.70
addKeywordMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…