From 362cd3b7bfa765217fd71c44cc145dda6ee888e3 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Sat, 12 Dec 2015 18:31:59 +0200 Subject: [PATCH] JsonPointer testsuite --- tests/unit/JsonPointer.spec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/unit/JsonPointer.spec.js diff --git a/tests/unit/JsonPointer.spec.js b/tests/unit/JsonPointer.spec.js new file mode 100644 index 00000000..5048c364 --- /dev/null +++ b/tests/unit/JsonPointer.spec.js @@ -0,0 +1,26 @@ +'use strict'; + +import {JsonPointer} from 'lib/utils/JsonPointer'; +// test extended JsonPointer + +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'); + }); + + 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(''); + }); + + it('should handle relative pointers (starting with #) without errors', ()=> { + JsonPointer.parse('#/level1/level2/name').should.be.deep.equal(['level1', 'level2', 'name']); + }); + + it('should join correctly', ()=> { + JsonPointer.join('#/level1', ['level2', 'name']).should.be.equal('/level1/level2/name'); + }); +});