redoc/tests/unit/JsonPointer.spec.ts

28 lines
1.1 KiB
TypeScript
Raw Normal View History

2015-12-12 19:31:59 +03:00
'use strict';
2016-06-12 20:44:34 +03:00
import {JsonPointer} from '../../lib/utils/JsonPointer';
2015-12-12 19:31:59 +03:00
// test extended JsonPointer
2015-12-19 20:36:28 +03:00
describe('Utils', () => {
describe('JsonPointer', () => {
it('should return correct base name', ()=> {
JsonPointer.baseName('/level1/level2/name').should.be.equal('name');
JsonPointer.baseName('/level1/level2/name', 2).should.be.equal('level2');
JsonPointer.baseName('/level1/level2/name', 3).should.be.equal('level1');
});
2015-12-12 19:31:59 +03:00
2015-12-19 20:36:28 +03:00
it('should return correct dir name', ()=> {
JsonPointer.dirName('/level1/level2/name').should.be.equal('/level1/level2');
JsonPointer.dirName('/level1/level2/name', 2).should.be.equal('/level1');
JsonPointer.dirName('/level1/level2/name', 3).should.be.equal('');
});
2015-12-12 19:31:59 +03:00
2015-12-19 20:36:28 +03:00
it('should handle relative pointers (starting with #) without errors', ()=> {
JsonPointer.parse('#/level1/level2/name').should.be.deepEqual(['level1', 'level2', 'name']);
});
2015-12-12 19:31:59 +03:00
2015-12-19 20:36:28 +03:00
it('should join correctly', ()=> {
JsonPointer.join('#/level1', ['level2', 'name']).should.be.equal('/level1/level2/name');
});
2015-12-12 19:31:59 +03:00
});
});