Skip to content

Commit 8ccf974

Browse files
committed
Implement invert()
1 parent 9670580 commit 8ccf974

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/vimscript/expression/evaluate.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,13 @@ export class EvaluationContext {
10111011
// TODO: indexof()
10121012
// TODO: input()/inputlist()
10131013
// TODO: insert()
1014-
// TODO: invert()
1014+
case 'invert': {
1015+
const [x] = getArgs(1);
1016+
// eslint-disable-next-line no-bitwise
1017+
return int(~toInt(x!));
1018+
}
1019+
// TODO: isabsolutepath()
1020+
// TODO: isdirectory()
10151021
case 'isinf': {
10161022
const [x] = getArgs(1);
10171023
const _x = toFloat(x!);

test/vimscript/expression.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ suite('Vimscript expressions', () => {
673673
exprTest('index(["A","C","D","C"], "C", 5)', { value: int(-1) });
674674
});
675675

676+
suite('invert', () => {
677+
exprTest('invert(123)', { value: int(-124) });
678+
});
679+
676680
suite('isnan/isinf', () => {
677681
exprTest('isnan(2.0 / 3.0)', { value: bool(false) });
678682
exprTest('isnan(0.0 / 0.0)', { value: bool(true) });

0 commit comments

Comments
 (0)