2019-07-05 15:52:37 +00:00
|
|
|
const JsUnit = imports.jsUnit;
|
2023-07-10 09:53:00 +00:00
|
|
|
import * as Params from '../../js/misc/params.js';
|
2019-07-05 15:52:37 +00:00
|
|
|
|
2023-07-10 05:59:46 +00:00
|
|
|
/**
|
|
|
|
* Asserts that two "param" objects have the same properties
|
|
|
|
* with the same values.
|
|
|
|
*
|
|
|
|
* @param {object} params the parsed params
|
|
|
|
* @param {object} expected the expected params
|
|
|
|
*/
|
2019-07-05 15:52:37 +00:00
|
|
|
function assertParamsEqual(params, expected) {
|
|
|
|
for (let p in params) {
|
|
|
|
JsUnit.assertTrue(p in expected);
|
|
|
|
JsUnit.assertEquals(params[p], expected[p]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let defaults = {
|
|
|
|
foo: 'This is a test',
|
|
|
|
bar: null,
|
2023-07-10 05:59:46 +00:00
|
|
|
baz: 42,
|
2019-07-05 15:52:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
assertParamsEqual(
|
|
|
|
Params.parse(null, defaults),
|
|
|
|
defaults);
|
|
|
|
|
|
|
|
assertParamsEqual(
|
2023-07-10 05:59:46 +00:00
|
|
|
Params.parse({bar: 23}, defaults),
|
|
|
|
{foo: 'This is a test', bar: 23, baz: 42});
|
2019-07-05 15:52:37 +00:00
|
|
|
|
|
|
|
JsUnit.assertRaises(
|
|
|
|
() => {
|
2023-07-10 05:59:46 +00:00
|
|
|
Params.parse({extraArg: 'quz'}, defaults);
|
2019-07-05 15:52:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assertParamsEqual(
|
2023-07-10 05:59:46 +00:00
|
|
|
Params.parse({extraArg: 'quz'}, defaults, true),
|
|
|
|
{foo: 'This is a test', bar: null, baz: 42, extraArg: 'quz'});
|