Skip to content

Commit 4d6bc89

Browse files
committed
Include VimError args in expression tests
1 parent 7b7df9d commit 4d6bc89

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

test/vimscript/expression.test.ts

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function removeIds(value: Value): unknown {
4545

4646
function exprTest(
4747
input: string,
48-
asserts: { expr?: Expression } & ({ value?: Value; display?: string } | { error: ErrorCode }),
48+
asserts: { expr?: Expression } & ({ value?: Value; display?: string } | { error: VimError }),
4949
) {
5050
test(input, () => {
5151
try {
@@ -69,7 +69,7 @@ function exprTest(
6969
} catch (e: unknown) {
7070
if (e instanceof VimError) {
7171
if ('error' in asserts) {
72-
assert.deepStrictEqual(e.code, asserts.error);
72+
assert.deepStrictEqual(e, asserts.error);
7373
} else {
7474
throw e;
7575
}
@@ -147,7 +147,7 @@ suite('Vimscript expressions', () => {
147147
value: blob(new Uint8Array([171, 205])),
148148
});
149149
exprTest('0zabc', {
150-
error: ErrorCode.BlobLiteralShouldHaveAnEvenNumberOfHexCharacters,
150+
error: VimError.BlobLiteralShouldHaveAnEvenNumberOfHexCharacters(),
151151
});
152152
});
153153

@@ -219,7 +219,7 @@ suite('Vimscript expressions', () => {
219219
exprTest("#{one: 1, two: 2, three: 3}['two']", { value: int(2) });
220220
exprTest("#{one: 1, two: 2, three: 3}['three']", { value: int(3) });
221221
exprTest("#{one: 1, two: 2, three: 3}['four']", {
222-
error: ErrorCode.KeyNotPresentInDictionary,
222+
error: VimError.KeyNotPresentInDictionary('four'),
223223
});
224224

225225
exprTest('0zABCD[0]', { value: int(171) });
@@ -231,7 +231,9 @@ suite('Vimscript expressions', () => {
231231
exprTest('#{one: 1, two: 2, three: 3}.one', { value: int(1) });
232232
exprTest('#{one: 1, two: 2, three: 3}.two', { value: int(2) });
233233
exprTest('#{one: 1, two: 2, three: 3}.three', { value: int(3) });
234-
exprTest('#{one: 1, two: 2, three: 3}.four', { error: ErrorCode.KeyNotPresentInDictionary });
234+
exprTest('#{one: 1, two: 2, three: 3}.four', {
235+
error: VimError.KeyNotPresentInDictionary('four'),
236+
});
235237
});
236238

237239
suite('Slice', () => {
@@ -467,11 +469,11 @@ suite('Vimscript expressions', () => {
467469
exprTest('0 is {}', { value: bool(false) });
468470
exprTest('[4] == ["4"]', { value: bool(false) });
469471
exprTest('3.2 > 3', { value: bool(true) });
470-
exprTest('5 == [5]', { error: ErrorCode.CanOnlyCompareListWithList });
471-
exprTest('[] == {}', { error: ErrorCode.CanOnlyCompareListWithList });
472-
exprTest('{} == []', { error: ErrorCode.CanOnlyCompareListWithList });
473-
exprTest('{} == 10', { error: ErrorCode.CanOnlyCompareDictionaryWithDictionary });
474-
exprTest('0 == 0z00', { error: ErrorCode.CanOnlyCompareBlobWithBlob });
472+
exprTest('5 == [5]', { error: VimError.CanOnlyCompareListWithList() });
473+
exprTest('[] == {}', { error: VimError.CanOnlyCompareListWithList() });
474+
exprTest('{} == []', { error: VimError.CanOnlyCompareListWithList() });
475+
exprTest('{} == 10', { error: VimError.CanOnlyCompareDictionaryWithDictionary() });
476+
exprTest('0 == 0z00', { error: VimError.CanOnlyCompareBlobWithBlob() });
475477
exprTest('2 == function("abs")', { value: bool(false) });
476478
});
477479
});
@@ -504,8 +506,8 @@ suite('Vimscript expressions', () => {
504506
exprTest("!'0'", { value: int(1) });
505507
exprTest("!'1'", { value: int(0) });
506508
exprTest("!'xyz'", { value: int(1) });
507-
exprTest('![]', { error: ErrorCode.UsingAListAsANumber });
508-
exprTest('!{}', { error: ErrorCode.UsingADictionaryAsANumber });
509+
exprTest('![]', { error: VimError.UsingAListAsANumber() });
510+
exprTest('!{}', { error: VimError.UsingADictionaryAsANumber() });
509511
});
510512

511513
suite('+', () => {
@@ -518,8 +520,8 @@ suite('Vimscript expressions', () => {
518520
exprTest("+'5'", { value: int(5) });
519521
exprTest("+'-5'", { value: int(-5) });
520522
exprTest("+'xyz'", { value: int(0) });
521-
exprTest('+[]', { error: ErrorCode.UsingAListAsANumber });
522-
exprTest('+{}', { error: ErrorCode.UsingADictionaryAsANumber });
523+
exprTest('+[]', { error: VimError.UsingAListAsANumber() });
524+
exprTest('+{}', { error: VimError.UsingADictionaryAsANumber() });
523525
});
524526

525527
suite('-', () => {
@@ -532,8 +534,8 @@ suite('Vimscript expressions', () => {
532534
exprTest("-'5'", { value: int(-5) });
533535
exprTest("-'-5'", { value: int(5) });
534536
exprTest("-'xyz'", { value: int(-0) });
535-
exprTest('-[]', { error: ErrorCode.UsingAListAsANumber });
536-
exprTest('-{}', { error: ErrorCode.UsingADictionaryAsANumber });
537+
exprTest('-[]', { error: VimError.UsingAListAsANumber() });
538+
exprTest('-{}', { error: VimError.UsingADictionaryAsANumber() });
537539
});
538540
});
539541

@@ -553,9 +555,9 @@ suite('Vimscript expressions', () => {
553555
exprTest('5 % 0', { value: int(0) });
554556
exprTest('-5 % 0', { value: int(0) });
555557

556-
exprTest('5.2 % 2.1', { error: ErrorCode.CannotUseModuloWithFloat });
557-
exprTest('5.2 % 2', { error: ErrorCode.CannotUseModuloWithFloat });
558-
exprTest('5 % 2.1', { error: ErrorCode.CannotUseModuloWithFloat });
558+
exprTest('5.2 % 2.1', { error: VimError.CannotUseModuloWithFloat() });
559+
exprTest('5.2 % 2', { error: VimError.CannotUseModuloWithFloat() });
560+
exprTest('5 % 2.1', { error: VimError.CannotUseModuloWithFloat() });
559561
});
560562
});
561563
});
@@ -655,10 +657,10 @@ suite('Vimscript expressions', () => {
655657
exprTest("function('abs')", { display: 'abs' });
656658
exprTest("function('abs', [])", { display: 'abs' });
657659
exprTest("function('abs', [-5])", { display: "function('abs', [-5])" });
658-
exprTest("function('abs', -5)", { error: ErrorCode.SecondArgumentOfFunction });
659-
exprTest("function('abs', '-5')", { error: ErrorCode.SecondArgumentOfFunction });
660-
exprTest("function('abs', [], [])", { error: ErrorCode.ExpectedADict });
661-
exprTest("function('abs', {}, {})", { error: ErrorCode.SecondArgumentOfFunction });
660+
exprTest("function('abs', -5)", { error: VimError.SecondArgumentOfFunction() });
661+
exprTest("function('abs', '-5')", { error: VimError.SecondArgumentOfFunction() });
662+
exprTest("function('abs', [], [])", { error: VimError.ExpectedADict() });
663+
exprTest("function('abs', {}, {})", { error: VimError.SecondArgumentOfFunction() });
662664
exprTest("function('abs', [], {})", { display: "function('abs', {})" });
663665
exprTest("function('abs', [], #{x:5})", { display: "function('abs', {'x': 5})" });
664666

@@ -673,8 +675,8 @@ suite('Vimscript expressions', () => {
673675
exprTest('flatten([1, [2, [3, 4]], 5], 1)', { display: '[1, 2, [3, 4], 5]' });
674676
exprTest('flatten([1, [2, [3, 4]], 5], 0)', { display: '[1, [2, [3, 4]], 5]' });
675677

676-
exprTest('flatten({})', { error: ErrorCode.ArgumentMustBeAList });
677-
exprTest('flatten([], -2)', { error: ErrorCode.MaxDepthMustBeANonNegativeNumber });
678+
exprTest('flatten({})', { error: VimError.ArgumentMustBeAList('flatten') });
679+
exprTest('flatten([], -2)', { error: VimError.MaxDepthMustBeANonNegativeNumber() });
678680
});
679681

680682
suite('float2nr', () => {
@@ -783,7 +785,7 @@ suite('Vimscript expressions', () => {
783785
exprTest('len("hello world!")', { value: int(12) });
784786
exprTest('len([5, 2, 3, 7])', { value: int(4) });
785787
exprTest('len(#{a:1, b:2, c:3})', { value: int(3) });
786-
exprTest('len(function("abs"))', { error: ErrorCode.InvalidTypeForLen });
788+
exprTest('len(function("abs"))', { error: VimError.InvalidTypeForLen() });
787789
});
788790

789791
suite('map', () => {
@@ -812,27 +814,27 @@ suite('Vimscript expressions', () => {
812814
exprTest('max({})', { value: int(0) });
813815
exprTest('max([4, 3, 1, 5, 2])', { value: int(5) });
814816
exprTest('max(#{ten:10,twenty:20,thirty:30})', { value: int(30) });
815-
exprTest('max([1.2, 1.5])', { error: ErrorCode.UsingAFloatAsANumber });
816-
exprTest("max('1,2,3')", { error: ErrorCode.ArgumentOfFuncMustBeAListOrDictionary });
817+
exprTest('max([1.2, 1.5])', { error: VimError.UsingAFloatAsANumber() });
818+
exprTest("max('1,2,3')", { error: VimError.ArgumentOfFuncMustBeAListOrDictionary('max') });
817819
});
818820
suite('min', () => {
819821
exprTest('min([])', { value: int(0) });
820822
exprTest('min({})', { value: int(0) });
821823
exprTest('min([4, 3, 1, 5, 2])', { value: int(1) });
822824
exprTest('min(#{ten:10,twenty:20,thirty:30})', { value: int(10) });
823-
exprTest('min([1.2, 1.5])', { error: ErrorCode.UsingAFloatAsANumber });
824-
exprTest("min('1,2,3')", { error: ErrorCode.ArgumentOfFuncMustBeAListOrDictionary });
825+
exprTest('min([1.2, 1.5])', { error: VimError.UsingAFloatAsANumber() });
826+
exprTest("min('1,2,3')", { error: VimError.ArgumentOfFuncMustBeAListOrDictionary('min') });
825827
});
826828

827829
suite('tolower', () => {
828830
exprTest("tolower('Hello, World!')", { display: 'hello, world!' });
829831
exprTest('tolower(123)', { display: '123' });
830-
exprTest('tolower(1.23)', { error: ErrorCode.UsingFloatAsAString });
832+
exprTest('tolower(1.23)', { error: VimError.UsingFloatAsAString() });
831833
});
832834
suite('toupper', () => {
833835
exprTest("toupper('Hello, World!')", { display: 'HELLO, WORLD!' });
834836
exprTest('toupper(123)', { display: '123' });
835-
exprTest('toupper(1.23)', { error: ErrorCode.UsingFloatAsAString });
837+
exprTest('toupper(1.23)', { error: VimError.UsingFloatAsAString() });
836838
});
837839

838840
suite('range', () => {
@@ -842,9 +844,9 @@ suite('Vimscript expressions', () => {
842844
exprTest('range(2, -2, -1)', { display: '[2, 1, 0, -1, -2]' });
843845
exprTest('range(2, -2, -2)', { display: '[2, 0, -2]' });
844846
exprTest('range(0)', { display: '[]' });
845-
exprTest('range(1, 10, 0)', { error: ErrorCode.StrideIsZero });
846-
exprTest('range(2, 0)', { error: ErrorCode.StartPastEnd });
847-
exprTest('range(0, 2, -1)', { error: ErrorCode.StartPastEnd });
847+
exprTest('range(1, 10, 0)', { error: VimError.StrideIsZero() });
848+
exprTest('range(2, 0)', { error: VimError.StartPastEnd() });
849+
exprTest('range(0, 2, -1)', { error: VimError.StartPastEnd() });
848850
});
849851

850852
// TODO: remove()
@@ -856,7 +858,7 @@ suite('Vimscript expressions', () => {
856858
exprTest('repeat([], 3)', { display: '[]' });
857859
exprTest('repeat([1,2], 3)', { display: '[1, 2, 1, 2, 1, 2]' });
858860
exprTest('repeat(range(2,6,2), 3)', { display: '[2, 4, 6, 2, 4, 6, 2, 4, 6]' });
859-
exprTest('repeat(1.0, 3)', { error: ErrorCode.UsingFloatAsAString });
861+
exprTest('repeat(1.0, 3)', { error: VimError.UsingFloatAsAString() });
860862
});
861863

862864
suite('reverse', () => {
@@ -886,7 +888,7 @@ suite('Vimscript expressions', () => {
886888
exprTest('str2nr("123", 10)', { value: int(123) });
887889
exprTest('str2nr("DEADBEEF", 16)', { value: int(3735928559) });
888890
exprTest('str2nr("DEADBEEF", 10)', { value: int(0) });
889-
exprTest('str2nr("DEADBEEF", 9)', { error: ErrorCode.InvalidArgument474 });
891+
exprTest('str2nr("DEADBEEF", 9)', { error: VimError.InvalidArgument474() });
890892

891893
exprTest('str2nr("0xDEADBEEF", 16)', { value: int(3735928559) });
892894
exprTest('str2nr("0XDEADBEEF", 16)', { value: int(3735928559) });
@@ -914,7 +916,7 @@ suite('Vimscript expressions', () => {
914916
exprTest('strlen("")', { value: int(0) });
915917
exprTest('strlen("654321")', { value: int(6) });
916918
exprTest('strlen(654321)', { value: int(6) });
917-
exprTest('strlen([1,2,3])', { error: ErrorCode.UsingListAsAString });
919+
exprTest('strlen([1,2,3])', { error: VimError.UsingListAsAString() });
918920
});
919921

920922
suite('strpart', () => {
@@ -936,7 +938,9 @@ suite('Vimscript expressions', () => {
936938
});
937939

938940
suite('tr', () => {
939-
exprTest("tr('whatever', 'short', 'longer')", { error: ErrorCode.InvalidArgument475 });
941+
exprTest("tr('whatever', 'short', 'longer')", {
942+
error: VimError.InvalidArgument475('short'),
943+
});
940944
exprTest("tr('hello there', 'ht', 'HT')", { value: str('Hello THere') });
941945
});
942946

0 commit comments

Comments
 (0)