From 5edaca4211612c20172385dde4e05799d584207a Mon Sep 17 00:00:00 2001 From: gvergnaud Date: Sun, 6 Aug 2023 16:20:27 -0400 Subject: [PATCH] feat(select): add unit tests for variadic tuples --- tests/select.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/select.test.ts b/tests/select.test.ts index 2fe066cd..acb092b7 100644 --- a/tests/select.test.ts +++ b/tests/select.test.ts @@ -466,4 +466,24 @@ describe('select', () => { expect(res3).toEqual({ a: [] }); }); + + it('should work with variadic tuples', () => { + const fn = (input: string[]) => + match(input) + .with( + [P.string, 'some', 'cli', 'cmd', P.select(), ...P.array()], + (arg) => { + type t = Expect>; + return arg; + } + ) + .otherwise(() => '2'); + + expect(fn(['some cli cmd param', 'some', 'cli', 'cmd', 'param'])).toEqual( + 'param' + ); + expect( + fn(['some cli cmd param --flag', 'some', 'cli', 'cmd', 'param', '--flag']) + ).toEqual('param'); + }); });