From 5df70e5904bedbf5423390ff06eda88605498d51 Mon Sep 17 00:00:00 2001 From: mierenmanz Date: Mon, 3 May 2021 11:24:09 +0200 Subject: [PATCH] FIX(command) incorrect value for rest default value --- src/utils/command.ts | 2 +- test/argsparser_test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/utils/command.ts b/src/utils/command.ts index 4eda5bc..64bd821 100644 --- a/src/utils/command.ts +++ b/src/utils/command.ts @@ -103,5 +103,5 @@ function parseRest( ): void { const restValues = argsNullable.filter((x) => typeof x === 'string') args[entry.name] = - restValues !== null ? restValues?.join(' ') : entry.defaultValue + restValues.length > 0 ? restValues?.join(' ') : entry.defaultValue } diff --git a/test/argsparser_test.ts b/test/argsparser_test.ts index f428246..25777ed 100644 --- a/test/argsparser_test.ts +++ b/test/argsparser_test.ts @@ -148,3 +148,27 @@ Deno.test({ sanitizeResources: true, sanitizeExit: true }) + +const messageArgs5: string[] = ['<@!708544768342229012>'] +const expectedResult5 = { + user: '708544768342229012', + reason: 'No reason provided' +} +const commandArgs5: Args[] = [ + { + name: 'user', + match: 'mentionUser' + }, + { + name: 'reason', + match: 'rest', + defaultValue: 'No reason provided' + } +] +Deno.test({ + name: 'parse command arguments, rest match default', + fn: () => { + const result = parseArgs(commandArgs5, messageArgs5) + assertEquals(result, expectedResult5) + } +})