Skip to content

Commit

Permalink
Support parentheses in removeWhenContext() #296
Browse files Browse the repository at this point in the history
  • Loading branch information
tshino committed Dec 24, 2023
1 parent 5ff24e2 commit 1861952
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
10 changes: 5 additions & 5 deletions generator/gen_wrapper_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ const containsWhenContext = function(when, context) {
};

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(' || ');
return decomposeWhenClause(when).map(
cond => cond.map(
cond => cond.trim()
).filter(cond => cond !== context).join(' && ')
).filter(cond => cond !== '').join(' || ');
};

function negateContext(context) {
Expand Down
3 changes: 0 additions & 3 deletions test/suite/gen_wrapper_util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ describe('gen_wrapper_util', () => {
it('should handle non-logical operators', () => {
assert.strictEqual(removeWhenContext('c1 && a == b || c == d && c1', 'c1'), 'a == b || c == d');
});
// TODO: https://github.com/tshino/vscode-kb-macro/issues/296
/*
it('should leave parenthesized portion unchanged', () => {
assert.strictEqual(removeWhenContext('(c1 && c2)', 'c1'), '(c1 && c2)');
assert.strictEqual(removeWhenContext('(c2 && c1 && c3)', 'c1'), '(c2 && c1 && c3)');
Expand All @@ -144,7 +142,6 @@ describe('gen_wrapper_util', () => {
assert.strictEqual(removeWhenContext('(c2 || c3) && c1', 'c1'), '(c2 || c3)');
assert.strictEqual(removeWhenContext('(c2 && c1 || c3) && c1', 'c1'), '(c2 && c1 || c3)');
});
*/
});
describe('negateContext', () => {
const negateContext = genWrapperUtil.negateContext;
Expand Down

0 comments on commit 1861952

Please sign in to comment.