summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/all.js3
-rw-r--r--test/location.js36
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');
+ });
+ });
+});