Skip to content

Commit

Permalink
Update verify_wrapper.js #10
Browse files Browse the repository at this point in the history
  • Loading branch information
tshino committed Nov 26, 2021
1 parent 9124016 commit 8110f79
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions generator/gen_wrapper_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ module.exports = {
writeJSON,
loadBaseKeybindings,
addWhenContext,
copyKeybinding,
keybindingsContains,
combineBaseKeybingings
};
43 changes: 40 additions & 3 deletions generator/verify_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const containsWhenContext = function(when, context) {
}
return false;
}
const removeWhenContext = function(when, context) {
return when.split('||').map(cond => {
return cond.split('&&').filter(cond => {
return cond.trim() !== context;
}).map(cond => cond.trim()).join(' && ');
}).filter(cond => cond !== '').join(' || ');
}

const availableOnWindows = function(keybinding) {
return (
Expand Down Expand Up @@ -50,6 +57,33 @@ const availableOnMac = function(keybinding) {
);
}

const unwrapCommon = function(keybinding) {
keybinding = genWrapperUtil.copyKeybinding(keybinding);
if (keybinding.command === 'kb-macro.wrap') {
keybinding.command = keybinding.args.command;
if ('args' in keybinding.args) {
keybinding.args = keybinding.args.args;
} else {
delete keybinding.args;
}
}
keybinding.when = removeWhenContext(keybinding.when, 'kb-macro.recording');
return keybinding;
}
const unwrapForWindows = function(keybinding) {
keybinding = unwrapCommon(keybinding);
keybinding.when = removeWhenContext(keybinding.when, 'isWindows');
keybinding.when = removeWhenContext(keybinding.when, '!isLinux');
keybinding.when = removeWhenContext(keybinding.when, '!isMac');
if (keybinding.when === '') {
delete keybinding.when;
}
if ('mac' in keybinding) {
delete keybinding.mac;
}
return keybinding;
}

async function verifyWrapper() {
const packageJson = await genWrapperUtil.readJSON(PackageJsonPath);
const config = await genWrapperUtil.readJSON(ConfigPath);
Expand Down Expand Up @@ -81,11 +115,14 @@ async function verifyWrapper() {
const wrapper = wrappers.filter(availableOnWindows);
const base = baseKeybindings.filter(({ context }) => context === 'isWindows')[0].keybindings;

// wrapper.sort((a,b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
// base.sort((a,b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
// await genWrapperUtil.writeJSON('wrapper.json', wrapper);
wrapper.sort((a,b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
base.sort((a,b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
const unwrapped = wrapper.map(unwrapForWindows);
// await genWrapperUtil.writeJSON('unwrapped.json', unwrapped);
// await genWrapperUtil.writeJSON('base.json', base);

assert.strictEqual(wrapper.length, base.length, 'the number of default keybindings should match to the base (Windows)');
assert.deepStrictEqual(unwrapped, base, 'unwrapped default keybindings should exactly match to the base (Windows)');
}
// Linux
{
Expand Down

0 comments on commit 8110f79

Please sign in to comment.