From f93c76bbfd72dfb5c542896c86d1cb1e4620d82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kriszti=C3=A1n=20Balla?= Date: Fri, 15 May 2020 19:16:59 +0200 Subject: [PATCH] feat: Allow every possible number as a defaultValue for a number option (#1296) Closes #1291 --- src/lib/utils/options/options.ts | 3 ++ src/test/utils/options/options.test.ts | 41 ++------------------------ 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/src/lib/utils/options/options.ts b/src/lib/utils/options/options.ts index 981358d54..afb7270e3 100644 --- a/src/lib/utils/options/options.ts +++ b/src/lib/utils/options/options.ts @@ -303,6 +303,9 @@ export class Options { // No need to convert the defaultValue for a map type as it has to be of a specific type if (declaration.type === ParameterType.Map) { this._values[declaration.name] = declaration.defaultValue; + } else if (declaration.type === ParameterType.Number) { + // Don't use convert for number options to allow every possible number as a default value + this._values[declaration.name] = declaration.defaultValue || 0; } else { this._values[declaration.name] = convert(declaration.defaultValue, declaration); } diff --git a/src/test/utils/options/options.test.ts b/src/test/utils/options/options.test.ts index 0f93eb643..c48bfe3a6 100644 --- a/src/test/utils/options/options.test.ts +++ b/src/test/utils/options/options.test.ts @@ -41,53 +41,16 @@ describe('Options', () => { options.removeDeclarationByName(declaration.name); }); - it('Does not throw if default value is within range for number declaration', () => { + it('Does not throw if default value is out of range for number declaration', () => { const declaration: NumberDeclarationOption = { name: 'test-number-declaration', help: '', type: ParameterType.Number, minValue: 1, maxValue: 10, - defaultValue: 5 - }; - options.addDeclaration(declaration); - options.removeDeclarationByName(declaration.name); - }); - - it('Throws if default value is out of range for number declaration', () => { - const declaration: NumberDeclarationOption = { - name: 'test-number-declaration', - help: '', - type: ParameterType.Number, - minValue: 1, - maxValue: 10, - defaultValue: 0 - }; - throws(() => options.addDeclaration(declaration)); - options.removeDeclarationByName(declaration.name); - }); - - it('Throws if default value is lower than the min value', () => { - const declaration: NumberDeclarationOption = { - name: 'test-number-declaration', - help: '', - type: ParameterType.Number, - minValue: 1, defaultValue: 0 }; - throws(() => options.addDeclaration(declaration)); - options.removeDeclarationByName(declaration.name); - }); - - it('Throws if default value is greater than the max value', () => { - const declaration: NumberDeclarationOption = { - name: 'test-number-declaration', - help: '', - type: ParameterType.Number, - maxValue: 1, - defaultValue: 2 - }; - throws(() => options.addDeclaration(declaration)); + options.addDeclaration(declaration); options.removeDeclarationByName(declaration.name); });