Skip to content

Commit 286e4c0

Browse files
number range test cases
1 parent 6653b29 commit 286e4c0

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

library/src/helpers/__tests__/schema.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,37 +219,37 @@ describe('SchemaHelpers', () => {
219219
test('should handle number/integer inclusive range', () => {
220220
const schema = new Schema({ minimum: 2, maximum: 5 });
221221
const result = SchemaHelpers.humanizeConstraints(schema);
222-
expect(result).toEqual(['[ 2 .. 5 ]']);
222+
expect(result).toEqual(['2 <= value <= 5']);
223223
});
224224

225225
test('should handle number/integer exclusive range', () => {
226226
const schema = new Schema({ minimum: 2, exclusiveMaximum: 5 });
227227
const result = SchemaHelpers.humanizeConstraints(schema);
228-
expect(result).toEqual(['[ 2 .. 5 )']);
228+
expect(result).toEqual(['2 <= value < 5']);
229229
});
230230

231231
test('should handle inclusive minimum', () => {
232232
const schema = new Schema({ minimum: 2 });
233233
const result = SchemaHelpers.humanizeConstraints(schema);
234-
expect(result).toEqual(['>= 2']);
234+
expect(result).toEqual(['2 <= value']);
235235
});
236236

237237
test('should handle inclusive maximum', () => {
238238
const schema = new Schema({ maximum: 2 });
239239
const result = SchemaHelpers.humanizeConstraints(schema);
240-
expect(result).toEqual(['<= 2']);
240+
expect(result).toEqual(['value <= 2']);
241241
});
242242

243243
test('should handle exclusive minimum', () => {
244244
const schema = new Schema({ exclusiveMinimum: 5 });
245245
const result = SchemaHelpers.humanizeConstraints(schema);
246-
expect(result).toEqual(['> 5']);
246+
expect(result).toEqual(['5 < value']);
247247
});
248248

249249
test('should handle exclusive maximum', () => {
250250
const schema = new Schema({ exclusiveMaximum: 5 });
251251
const result = SchemaHelpers.humanizeConstraints(schema);
252-
expect(result).toEqual(['< 5']);
252+
expect(result).toEqual(['value < 5']);
253253
});
254254

255255
test('should handle integer multipleOf', () => {

library/src/helpers/schema.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -466,28 +466,23 @@ export class SchemaHelpers {
466466

467467
let numberRange;
468468
if (hasMin && hasMax) {
469-
// Alternative number range format: "[ 0 .. 1 ]"
470-
// numberRange = hasExclusiveMin ? '( ' : '[ ';
471-
// numberRange += hasExclusiveMin ? exclusiveMin : min;
472-
// numberRange += ' .. ';
473-
// numberRange += hasExclusiveMax ? exclusiveMax : max;
474-
// numberRange += hasExclusiveMax ? ' )' : ' ]';
475-
476-
// Alternative number range format: "0 <= value <= 1"
469+
// number range format: "0 <= value <= 1"
477470
numberRange = '';
478471
numberRange += hasExclusiveMin ? exclusiveMin : min;
479472
numberRange += hasExclusiveMin ? ' < ' : ' <= ';
480473
numberRange += 'value';
481474
numberRange += hasExclusiveMax ? ' < ' : ' <= ';
482475
numberRange += hasExclusiveMax ? exclusiveMax : max;
483476
} else if (hasMin) {
484-
numberRange = 'value ';
485-
numberRange += hasExclusiveMin ? '> ' : '>= ';
477+
numberRange = '';
486478
numberRange += hasExclusiveMin ? exclusiveMin : min;
479+
numberRange += hasExclusiveMin ? ' < ' : ' <= ';
480+
numberRange += 'value';
487481
} else if (hasMax) {
488-
numberRange = 'value ';
489-
numberRange = hasExclusiveMax ? '< ' : '<= ';
490-
numberRange += 'value ' + hasExclusiveMax ? exclusiveMax : max;
482+
numberRange = '';
483+
numberRange += 'value';
484+
numberRange += hasExclusiveMax ? ' < ' : ' <= ';
485+
numberRange += hasExclusiveMax ? exclusiveMax : max;
491486
}
492487
return numberRange;
493488
}

0 commit comments

Comments
 (0)