Skip to content

Commit 3c965cd

Browse files
committed
Trivial refactor
1 parent e07106d commit 3c965cd

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

src/error.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export enum ErrorCode {
5858
SliceRequiresAListOrBlobValue = 709,
5959
ListValueHasMoreItemsThanTarget = 710,
6060
ListValueHasNotEnoughItems = 711,
61-
ArgumentOfMaxMustBeAListOrDictionary = 712,
61+
ArgumentOfFuncMustBeAListOrDictionary = 712,
6262
ListRequired = 714,
6363
DictionaryRequired = 715,
6464
KeyNotPresentInDictionary = 716,
@@ -317,16 +317,10 @@ export class VimError extends Error {
317317
static ListValueHasNotEnoughItems(): VimError {
318318
return new VimError(ErrorCode.ListValueHasNotEnoughItems, 'List value has not enough items');
319319
}
320-
static ArgumentOfMaxMustBeAListOrDictionary(): VimError {
320+
static ArgumentOfFuncMustBeAListOrDictionary(func: string): VimError {
321321
return new VimError(
322-
ErrorCode.ArgumentOfMaxMustBeAListOrDictionary,
323-
'Argument of max() must be a List or Dictionary',
324-
);
325-
}
326-
static ArgumentOfMinMustBeAListOrDictionary(): VimError {
327-
return new VimError(
328-
ErrorCode.ArgumentOfMaxMustBeAListOrDictionary,
329-
'Argument of min() must be a List or Dictionary',
322+
ErrorCode.ArgumentOfFuncMustBeAListOrDictionary,
323+
`Argument of ${func} must be a List or Dictionary`,
330324
);
331325
}
332326
static ListRequired(): VimError {

src/vimscript/expression/evaluate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ export class EvaluationContext {
965965
}
966966
break;
967967
default:
968-
throw VimError.ArgumentOfMaxMustBeAListOrDictionary();
968+
throw VimError.ArgumentOfFuncMustBeAListOrDictionary(call.func);
969969
}
970970
return int(count);
971971
}
@@ -1370,7 +1370,7 @@ export class EvaluationContext {
13701370
} else if (l?.type === 'dictionary') {
13711371
values = [...l.items.values()];
13721372
} else {
1373-
throw VimError.ArgumentOfMaxMustBeAListOrDictionary();
1373+
throw VimError.ArgumentOfFuncMustBeAListOrDictionary(call.func);
13741374
}
13751375
return int(values.length === 0 ? 0 : Math.max(...values.map(toInt)));
13761376
}
@@ -1382,7 +1382,7 @@ export class EvaluationContext {
13821382
} else if (l?.type === 'dictionary') {
13831383
values = [...l.items.values()];
13841384
} else {
1385-
throw VimError.ArgumentOfMinMustBeAListOrDictionary();
1385+
throw VimError.ArgumentOfFuncMustBeAListOrDictionary(call.func);
13861386
}
13871387
return int(values.length === 0 ? 0 : Math.min(...values.map(toInt)));
13881388
}

test/vimscript/expression.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,15 +813,15 @@ suite('Vimscript expressions', () => {
813813
exprTest('max([4, 3, 1, 5, 2])', { value: int(5) });
814814
exprTest('max(#{ten:10,twenty:20,thirty:30})', { value: int(30) });
815815
exprTest('max([1.2, 1.5])', { error: ErrorCode.UsingAFloatAsANumber });
816-
exprTest("max('1,2,3')", { error: ErrorCode.ArgumentOfMaxMustBeAListOrDictionary });
816+
exprTest("max('1,2,3')", { error: ErrorCode.ArgumentOfFuncMustBeAListOrDictionary });
817817
});
818818
suite('min', () => {
819819
exprTest('min([])', { value: int(0) });
820820
exprTest('min({})', { value: int(0) });
821821
exprTest('min([4, 3, 1, 5, 2])', { value: int(1) });
822822
exprTest('min(#{ten:10,twenty:20,thirty:30})', { value: int(10) });
823823
exprTest('min([1.2, 1.5])', { error: ErrorCode.UsingAFloatAsANumber });
824-
exprTest("min('1,2,3')", { error: ErrorCode.ArgumentOfMaxMustBeAListOrDictionary });
824+
exprTest("min('1,2,3')", { error: ErrorCode.ArgumentOfFuncMustBeAListOrDictionary });
825825
});
826826

827827
suite('tolower', () => {

0 commit comments

Comments
 (0)