diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-28 17:52:10 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-28 17:52:10 +0100 |
commit | f5ded5e5e1cccacd9288f8888943a105b6b3aaa5 (patch) | |
tree | 8d8c13386c0b53183d85fab8e9bf3e458293cf91 /test/links.js | |
parent | 56d1720aaea2472f12e045f61a2fb0bdf7da9343 (diff) | |
download | gitbook-f5ded5e5e1cccacd9288f8888943a105b6b3aaa5.zip gitbook-f5ded5e5e1cccacd9288f8888943a105b6b3aaa5.tar.gz gitbook-f5ded5e5e1cccacd9288f8888943a105b6b3aaa5.tar.bz2 |
Fix absolute path calcul
Add tests for links module
Diffstat (limited to 'test/links.js')
-rw-r--r-- | test/links.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/links.js b/test/links.js new file mode 100644 index 0000000..4dad4d4 --- /dev/null +++ b/test/links.js @@ -0,0 +1,33 @@ +var path = require('path'); +var _ = require('lodash'); +var assert = require('assert'); + +var links = require("../lib/utils/links"); + +describe('Links', function () { + it('should correctly test external links', function() { + assert(links.isExternal("http://google.fr")); + assert(links.isExternal("https://google.fr")); + assert(!links.isExternal("test.md")); + assert(!links.isExternal("folder/test.md")); + assert(!links.isExternal("/folder/test.md")); + }); + + describe('toAbsolute', function() { + it('should correctly transform as absolute', function() { + assert.equal(links.toAbsolute("http://google.fr"), "http://google.fr"); + assert.equal(links.toAbsolute("test.md", "./", "./"), "test.md"); + assert.equal(links.toAbsolute("folder/test.md", "./", "./"), "folder/test.md"); + }); + + it('should correctly handle windows path', function() { + assert.equal(links.toAbsolute("folder\\test.md", "./", "./"), "folder/test.md"); + }); + + it('should correctly handle absolute path', function() { + assert.equal(links.toAbsolute("/test.md", "./", "./"), "test.md"); + assert.equal(links.toAbsolute("/test.md", "test", "test"), "../test.md"); + assert.equal(links.toAbsolute("/sub/test.md", "test", "test"), "../sub/test.md"); + }); + }); +}); |