Skip to content

Commit

Permalink
feat: Allow every possible number as a defaultValue for a number opti…
Browse files Browse the repository at this point in the history
…on (#1296)

Closes #1291
  • Loading branch information
krisztianb committed May 15, 2020
1 parent bc20444 commit f93c76b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 39 deletions.
3 changes: 3 additions & 0 deletions src/lib/utils/options/options.ts
Expand Up @@ -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);
}
Expand Down
41 changes: 2 additions & 39 deletions src/test/utils/options/options.test.ts
Expand Up @@ -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);
});

Expand Down

0 comments on commit f93c76b

Please sign in to comment.