diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-02-17 21:02:42 +0100 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-02-17 21:02:42 +0100 |
commit | a68364d4d7593d43a83a1d16d71db32bde0a6465 (patch) | |
tree | 02809896fa49655ad2e21aad1c703e18bfd1fdfe | |
parent | 2b5e836a3329917f1af4c0de51974b672994ec4b (diff) | |
download | gitbook-a68364d4d7593d43a83a1d16d71db32bde0a6465.zip gitbook-a68364d4d7593d43a83a1d16d71db32bde0a6465.tar.gz gitbook-a68364d4d7593d43a83a1d16d71db32bde0a6465.tar.bz2 |
Add test for location
-rw-r--r-- | test/all.js | 3 | ||||
-rw-r--r-- | test/location.js | 36 |
2 files changed, 39 insertions, 0 deletions
diff --git a/test/all.js b/test/all.js index f8ba153..97913d7 100644 --- a/test/all.js +++ b/test/all.js @@ -1,4 +1,7 @@ +// Utilities +require('./location'); + // Parsing require('./config'); require('./readme'); diff --git a/test/location.js b/test/location.js new file mode 100644 index 0000000..4d949fa --- /dev/null +++ b/test/location.js @@ -0,0 +1,36 @@ +var location = require('../lib/utils/location'); + +describe('Location', function() { + it('should correctly test external location', function() { + location.isExternal('http://google.fr').should.be.exactly(true); + location.isExternal('https://google.fr').should.be.exactly(true); + location.isExternal('test.md').should.be.exactly(false); + location.isExternal('folder/test.md').should.be.exactly(false); + location.isExternal('/folder/test.md').should.be.exactly(false); + }); + + it('should correctly detect anchor location', function() { + location.isAnchor('#test').should.be.exactly(true); + location.isAnchor(' #test').should.be.exactly(true); + location.isAnchor('https://google.fr#test').should.be.exactly(false); + location.isAnchor('test.md#test').should.be.exactly(false); + }); + + describe('toAbsolute', function() { + it('should correctly transform as absolute', function() { + location.toAbsolute('http://google.fr').should.be.equal('http://google.fr'); + location.toAbsolute('test.md', './', './').should.be.equal('test.md'); + location.toAbsolute('folder/test.md', './', './').should.be.equal('folder/test.md'); + }); + + it('should correctly handle windows path', function() { + location.toAbsolute('folder\\test.md', './', './').should.be.equal('folder/test.md'); + }); + + it('should correctly handle absolute path', function() { + location.toAbsolute('/test.md', './', './').should.be.equal('test.md'); + location.toAbsolute('/test.md', 'test', 'test').should.be.equal('../test.md'); + location.toAbsolute('/sub/test.md', 'test', 'test').should.be.equal('../sub/test.md'); + }); + }); +}); |