UNPKG

2.06 kBJavaScriptView Raw
1var mapping = {'/aaa/a': 'a.html',
2 '/aaa/b/c': 'bucunzai.html', //映射到不存在的内容
3 '/aaa/b': 'a.html',
4 '/aaa/c': 'xx/yy/zz/a.html',
5 '/aaa/d/e': 'a.html',
6 '/bbb' : 'aaa' //目录映射
7};
8var assert = require('assert');
9var path = require('path');
10var prjDir = path.join(__dirname, 'jspage');
11var mappedFile = require('../lib/jspage.js').mappedFile;
12
13
14describe('JsPage', function(){
15 describe('#mappedFile()', function(){
16 it('应该正确的返回映射结果', function(){
17 assert.equal(mappedFile('/aaasdfasfasd', prjDir, mapping), null);
18 assert.equal(mappedFile('/aaa/a', prjDir, mapping), 'a.html');
19 assert.equal(mappedFile('/aaa/b/c', prjDir, mapping), null);
20 assert.equal(mappedFile('/aaa/b', prjDir, mapping), 'a.html');
21 assert.equal(mappedFile('/aaa/c', prjDir, mapping), 'xx/yy/zz/a.html');
22 assert.equal(mappedFile('/aaa/b/bucunzai', prjDir, mapping), null);
23 assert.deepEqual(mappedFile('/aaa/d', prjDir, mapping), [{name: 'e', isDir: false}]);
24 assert.equal(mappedFile('/aaa/d/e', prjDir, mapping), 'a.html');
25 assert.deepEqual(mappedFile('/aaa', prjDir, mapping), [{name: 'rengong', isDir: true},{name: 'a', isDir: false},{name: 'b', isDir: false},{name: 'c', isDir: false},{name: 'd', isDir: true}]);
26 assert.deepEqual(mappedFile('/bbb/rengong', prjDir, mapping), [{name : 'ttt', isDir: false}]);
27 assert.deepEqual(mappedFile('/bbb/rengong/ttt', prjDir, mapping), 'aaa/rengong/ttt');
28 assert.deepEqual(mappedFile('/aaa/rengong/ttt', prjDir, mapping), 'aaa/rengong/ttt');
29 assert.deepEqual(mappedFile('/xx', prjDir, mapping), [{name: 'yy', isDir: true}]);
30 assert.deepEqual(mappedFile('/', prjDir, mapping), [{name: "a.html", isDir: false},{name: "aaa", isDir: true},{name:"xx", isDir: true},{name: "bbb", isDir:true}]);
31 assert.deepEqual(mappedFile('/bbb', prjDir, mapping),[{name: 'rengong', isDir: true}]);
32 });
33 })
34})