summaryrefslogtreecommitdiffstats
path: root/test/resolve.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-09-15 12:27:07 +0200
committerSamy Pessé <samypesse@gmail.com>2015-09-15 12:27:07 +0200
commit57a0c3bad8333d93815257d7ff603bc34b8b3f4d (patch)
treecf5f447e84e3b4ac2d74d7092d8c522bd6e67b79 /test/resolve.js
parent463a947df1e5c8c862c555a5b0ae675e356a0d5c (diff)
parent2a52326a454a23444bd8f0395a9ab8a1f5f68831 (diff)
downloadgitbook-57a0c3bad8333d93815257d7ff603bc34b8b3f4d.zip
gitbook-57a0c3bad8333d93815257d7ff603bc34b8b3f4d.tar.gz
gitbook-57a0c3bad8333d93815257d7ff603bc34b8b3f4d.tar.bz2
Merge pull request #929 from GitbookIO/feature/improve_resolve
Improve paths resolving for conrefs
Diffstat (limited to 'test/resolve.js')
-rw-r--r--test/resolve.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/resolve.js b/test/resolve.js
new file mode 100644
index 0000000..b31a10d
--- /dev/null
+++ b/test/resolve.js
@@ -0,0 +1,61 @@
+var fs = require('fs');
+var path = require('path');
+
+describe('Resolve Files', function () {
+ var book;
+
+ before(function() {
+ return books.parse("basic")
+ .then(function(_book) {
+ book = _book;
+ });
+ });
+
+ describe('book.fileIsInBook', function() {
+ it('should return true for correct paths', function() {
+ book.fileIsInBook(path.join(book.root, 'README.md')).should.equal(true);
+ book.fileIsInBook(path.join(book.root, 'styles/website.css')).should.equal(true);
+ });
+
+ it('should return true for root folder', function() {
+ book.fileIsInBook(path.join(book.root, './')).should.equal(true);
+ book.fileIsInBook(book.root).should.equal(true);
+ });
+
+ it('should return false for files out of scope', function() {
+ book.fileIsInBook(path.join(book.root, '../')).should.equal(false);
+ book.fileIsInBook('README.md').should.equal(false);
+ book.fileIsInBook(path.resolve(book.root, '../README.md')).should.equal(false);
+ });
+
+ it('should correctly handle windows paths', function() {
+ book.fileIsInBook(path.join(book.root, '\\styles\\website.css')).should.equal(true);
+ });
+ });
+
+ describe('book.resolve', function() {
+ it('should resolve a file to its absolute path', function() {
+ book.resolve('README.md').should.equal(path.resolve(book.root, 'README.md'));
+ book.resolve('website/README.md').should.equal(path.resolve(book.root, 'website/README.md'));
+ });
+
+ it('should correctly handle windows paths', function() {
+ book.resolve('styles\\website.css').should.equal(path.resolve(book.root, 'styles\\website.css'));
+ });
+
+ it('should correctly resolve all arguments', function() {
+ book.resolve('test', 'hello', '..', 'README.md').should.equal(path.resolve(book.root, 'test/README.md'));
+ });
+
+ it('should correctly resolve to root folder', function() {
+ book.resolve('test', '/README.md').should.equal(path.resolve(book.root, 'README.md'));
+ book.resolve('test', '\\README.md').should.equal(path.resolve(book.root, 'README.md'));
+ });
+
+ it('should throw an error for file out of book', function() {
+ (function() {
+ return book.resolve('../README.md');
+ }).should.throw();
+ });
+ });
+});