2017-04-19 21:15:28 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-02-01 09:08:48 +01:00
|
|
|
// ensure that all arguments are validated
|
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
let assert = require('assert');
|
2014-02-01 09:08:48 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
describe('index.js app', test('index.js'));
|
|
|
|
describe('index-api.js app', test('index-api.js'));
|
|
|
|
describe('index-web.js app', test('index-web.js'));
|
2014-11-13 18:13:37 +01:00
|
|
|
|
|
|
|
function test(file) {
|
|
|
|
return function() {
|
2017-04-19 21:15:28 +02:00
|
|
|
let source = require('fs').readFileSync(__dirname + '/../../lib/' + file, 'utf8');
|
2014-11-13 18:13:37 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
let very_scary_regexp = /\n\s*app\.(\w+)\s*\(\s*(("[^"]*")|('[^']*'))\s*,/g;
|
|
|
|
let m;
|
|
|
|
let params = {};
|
2014-11-13 18:13:37 +01:00
|
|
|
|
|
|
|
while ((m = very_scary_regexp.exec(source)) != null) {
|
2017-04-19 21:15:28 +02:00
|
|
|
if (m[1] === 'set') continue;
|
2014-11-13 18:13:37 +01:00
|
|
|
|
2017-04-19 21:15:28 +02:00
|
|
|
let inner = m[2].slice(1, m[2].length-1);
|
|
|
|
var t;
|
2014-11-13 18:13:37 +01:00
|
|
|
|
|
|
|
inner.split('/').forEach(function(x) {
|
2017-04-23 20:02:26 +02:00
|
|
|
t = x.match(/^:([^?:]*)\??$/);
|
2014-11-13 18:13:37 +01:00
|
|
|
if (m[1] === 'param') {
|
2017-04-19 21:15:28 +02:00
|
|
|
params[x] = 'ok';
|
2017-04-23 20:02:26 +02:00
|
|
|
} else if (t) {
|
2017-04-19 21:15:28 +02:00
|
|
|
params[t[1]] = params[t[1]] || m[0].trim();
|
2014-11-13 18:13:37 +01:00
|
|
|
}
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2014-11-13 18:13:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Object.keys(params).forEach(function(param) {
|
|
|
|
it('should validate ":'+param+'"', function() {
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(params[param], 'ok');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2014-11-13 18:13:37 +01:00
|
|
|
}
|
2014-02-01 09:08:48 +01:00
|
|
|
|