mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 19:25:10 +00:00
39 lines
882 B
JavaScript
39 lines
882 B
JavaScript
const path = require('path');
|
|
const assert = require('assert');
|
|
|
|
const create_matchers = require('./create_matchers.js');
|
|
|
|
describe('create_matchers', () => {
|
|
it('sorts routes correctly', () => {
|
|
const matchers = create_matchers(['index.html', 'about.html', '%wildcard%.html', 'post/%id%.html']);
|
|
|
|
assert.deepEqual(
|
|
matchers.map(m => m.file),
|
|
[
|
|
'about.html',
|
|
'index.html',
|
|
'post/%id%.html',
|
|
'%wildcard%.html'
|
|
]
|
|
);
|
|
});
|
|
|
|
it('generates params', () => {
|
|
const matchers = create_matchers(['index.html', 'about.html', '%wildcard%.html', 'post/%id%.html']);
|
|
|
|
let file;
|
|
let params;
|
|
for (let i = 0; i < matchers.length; i += 1) {
|
|
const matcher = matchers[i];
|
|
if (params = matcher.exec('/post/123')) {
|
|
file = matcher.file;
|
|
break;
|
|
}
|
|
}
|
|
|
|
assert.equal(file, 'post/%id%.html');
|
|
assert.deepEqual(params, {
|
|
id: '123'
|
|
});
|
|
});
|
|
}); |