Skip to content

Commit

Permalink
feat: improved type string with minLength == maxLength
Browse files Browse the repository at this point in the history
closes #212
  • Loading branch information
RomanHotsiy committed Feb 25, 2017
1 parent a1aefa4 commit e76bcc3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
44 changes: 44 additions & 0 deletions lib/services/schema-helper.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,50 @@ describe('Spec Helper', () => {
expect(console.warn).toHaveBeenCalled();
(<jasmine.Spy>console.warn).and.callThrough();
});

describe('string', () => {
it('should calculate range for string with maxLength', () => {
let schema:any = {
type: 'string',
maxLength: 3
};

SchemaHelper.runInjectors(schema, schema, '#/');
schema._range.should.be.equal('<= 3 characters');
});

it('should calculate range for string with minLength', () => {
let schema:any = {
type: 'string',
minLength: 3,
};

SchemaHelper.runInjectors(schema, schema, '#/');
schema._range.should.be.equal('>= 3 characters');
});

it('should calculate range for string with both max and minLength', () => {
let schema:any = {
type: 'string',
minLength: 3,
maxLength: 5
};

SchemaHelper.runInjectors(schema, schema, '#/');
schema._range.should.be.equal('[ 3 .. 5 ] characters');
});

it('should calculate range for string with equal max and minLength', () => {
let schema:any = {
type: 'string',
minLength: 5,
maxLength: 5
};

SchemaHelper.runInjectors(schema, schema, '#/');
schema._range.should.be.equal('5 characters');
});
});
});

describe('preprocessProperties', () => {
Expand Down
6 changes: 5 additions & 1 deletion lib/services/schema-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ const injectors = {
inject: (injectTo, propertySchema = injectTo) => {
var range;
if (propertySchema.minLength != undefined && propertySchema.maxLength != undefined) {
range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ]`;
if (propertySchema.minLength === propertySchema.maxLength) {
range = `${propertySchema.minLength}`;
} else {
range = `[ ${propertySchema.minLength} .. ${propertySchema.maxLength} ]`;
}
} else if (propertySchema.maxLength != undefined) {
range = '<= ' + propertySchema.maxLength;
} else if (propertySchema.minLength != undefined) {
Expand Down

0 comments on commit e76bcc3

Please sign in to comment.