Skip to content

Commit 7872fb1

Browse files
committed
Add a few assert_* functions
1 parent 99e8949 commit 7872fb1

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

src/vimscript/expression/evaluate.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,14 @@ export class EvaluationContext {
623623
}
624624

625625
private evaluateFunctionCall(call: FunctionCallExpression): Value {
626+
const assertPassed = () => {
627+
return int(0);
628+
};
629+
const assertFailed = (msg: string) => {
630+
// TODO: Include file & line
631+
this.errors.push(msg);
632+
return int(1);
633+
};
626634
const getArgs = (min: number, max?: number) => {
627635
if (max === undefined) {
628636
max = min;
@@ -668,42 +676,56 @@ export class EvaluationContext {
668676
// eslint-disable-next-line no-bitwise
669677
return int(toInt(x!) & toInt(y!));
670678
}
671-
// TODO: assert_*()
679+
case 'assert_beeps': {
680+
return assertFailed('VSCodeVim does not support beeps');
681+
}
672682
case 'assert_equal': {
673683
const [expected, actual, msg] = getArgs(2, 3);
674684
if (this.evaluateComparison('==', true, expected!, actual!)) {
675-
return int(0);
685+
return assertPassed();
676686
}
677-
this.errors.push(
687+
return assertFailed(
678688
msg
679689
? toString(msg)
680-
: `Expected ${displayValue(expected!)} but got ${displayValue(actual!)}`, // TODO: Include file & line
690+
: `Expected ${displayValue(expected!)} but got ${displayValue(actual!)}`,
691+
);
692+
}
693+
// TODO: assert_equalfile()
694+
// TODO: assert_exception()
695+
// TODO: assert_fails()
696+
case 'assert_false': {
697+
const [actual, msg] = getArgs(1, 2);
698+
if (this.evaluateComparison('==', true, bool(false), actual!)) {
699+
return assertPassed();
700+
}
701+
return assertFailed(
702+
msg ? toString(msg) : `Expected False but got ${displayValue(actual!)}`,
681703
);
682-
return int(1);
704+
}
705+
// TODO: assert_inrange()
706+
// TODO: assert_match()
707+
case 'assert_nobeep': {
708+
return assertPassed();
683709
}
684710
case 'assert_notequal': {
685711
const [expected, actual, msg] = getArgs(2, 3);
686712
if (this.evaluateComparison('!=', true, expected!, actual!)) {
687-
return int(0);
713+
return assertPassed();
688714
}
689-
this.errors.push(
690-
msg ? toString(msg) : `Expected not equal to ${displayValue(expected!)}`, // TODO: Include file & line
715+
return assertFailed(
716+
msg ? toString(msg) : `Expected not equal to ${displayValue(expected!)}`,
691717
);
692-
return int(1);
693718
}
719+
// TODO: assert_notmatch()
694720
case 'assert_report': {
695-
this.errors.push(toString(getArgs(1)[0]!));
696-
return int(1);
721+
return assertFailed(toString(getArgs(1)[0]!));
697722
}
698723
case 'assert_true': {
699724
const [actual, msg] = getArgs(2, 3);
700725
if (this.evaluateComparison('==', true, bool(true), actual!)) {
701-
return int(0);
726+
return assertPassed();
702727
}
703-
this.errors.push(
704-
msg ? toString(msg) : `Expected True but got ${displayValue(actual!)}`, // TODO: Include file & line
705-
);
706-
return int(1);
728+
return assertFailed(msg ? toString(msg) : `Expected True but got ${displayValue(actual!)}`);
707729
}
708730
// TODO: call()
709731
case 'ceil': {

0 commit comments

Comments
 (0)