Skip to content

Commit 9d1dcfc

Browse files
committed
Implement assert_inrange()
1 parent 9f8da4f commit 9d1dcfc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/vimscript/expression/evaluate.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,20 @@ export class EvaluationContext {
710710
msg ? toString(msg) : `Expected False but got ${displayValue(actual!)}`,
711711
);
712712
}
713-
// TODO: assert_inrange()
713+
case 'assert_inrange': {
714+
const [lower, upper, actual, msg] = getArgs(3, 4);
715+
if (
716+
this.evaluateComparison('>=', true, actual!, lower!) &&
717+
this.evaluateComparison('<=', true, actual!, upper!)
718+
) {
719+
return assertPassed();
720+
}
721+
return assertFailed(
722+
msg
723+
? toString(msg)
724+
: `Expected range ${displayValue(lower!)} - ${displayValue(upper!)} but got ${displayValue(actual!)}`,
725+
);
726+
}
714727
case 'assert_match': {
715728
const [pattern, actual, msg] = getArgs(2, 3);
716729
if (this.evaluateComparison('=~', true, actual!, pattern!)) {

0 commit comments

Comments
 (0)