diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-03-24 14:52:24 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-03-24 14:52:24 +0100 |
commit | c07ddc77f74138b205ebd13fa007a3feb86a9099 (patch) | |
tree | b31ea0221b9d0f8696208cc86eca95399788b1c0 | |
parent | 303fc992d46bc76801376a4469c26a3c61c370d7 (diff) | |
download | gitbook-c07ddc77f74138b205ebd13fa007a3feb86a9099.zip gitbook-c07ddc77f74138b205ebd13fa007a3feb86a9099.tar.gz gitbook-c07ddc77f74138b205ebd13fa007a3feb86a9099.tar.bz2 |
Add tests for links
-rw-r--r-- | test/links.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/links.js b/test/links.js new file mode 100644 index 0000000..5c7823d --- /dev/null +++ b/test/links.js @@ -0,0 +1,37 @@ +var should = require('should'); +var links = require("../lib/utils/links"); + +describe('Links', function () { + it('should correctly test external links', function() { + links.isExternal("http://google.fr").should.be.exactly(true); + links.isExternal("https://google.fr").should.be.exactly(true); + links.isExternal("test.md").should.be.exactly(false); + links.isExternal("folder/test.md").should.be.exactly(false); + links.isExternal("/folder/test.md").should.be.exactly(false); + }); + + it('should correctly detect anchor links', function() { + links.isAnchor("#test").should.be.exactly(true); + links.isAnchor(" #test").should.be.exactly(true); + links.isAnchor("https://google.fr#test").should.be.exactly(false); + links.isAnchor("test.md#test").should.be.exactly(false); + }); + + describe('toAbsolute', function() { + it('should correctly transform as absolute', function() { + links.toAbsolute("http://google.fr").should.be.equal("http://google.fr"); + links.toAbsolute("test.md", "./", "./").should.be.equal("test.md"); + links.toAbsolute("folder/test.md", "./", "./").should.be.equal("folder/test.md"); + }); + + it('should correctly handle windows path', function() { + links.toAbsolute("folder\\test.md", "./", "./").should.be.equal("folder/test.md"); + }); + + it('should correctly handle absolute path', function() { + links.toAbsolute("/test.md", "./", "./").should.be.equal("test.md"); + links.toAbsolute("/test.md", "test", "test").should.be.equal("../test.md"); + links.toAbsolute("/sub/test.md", "test", "test").should.be.equal("../sub/test.md"); + }); + }); +}); |