-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow every possible number as a defaultValue for a number option #1296
Changes from all commits
474606f
294a675
58fb056
cf16a00
f9b73a4
3095a52
52eeb65
1fa1bd1
95bf83d
dc33b99
1b5fcc8
52d6e26
1b0a71e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make the default value explicit so that the test is obvious and doesn't break in the (admittedly very unlikely) situation that the default value is changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't understand. What do you mean by "make it explicit"? Do you mean to create a separate variable for it and use that in the object definition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant specifying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Gerrit0 Well, it turns out it is already specified just that way: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doh! So it is, diff is great until it isn't. Looks good to me. |
||
}; | ||
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); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, "every possible number" doesn't include NaN? I think I'm okay with this... will sleep on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was thinking about that one too. Maybe allowing
NaN
is the better solution though. Otherwise I would wonder why the plugin resets it to0
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think disallowing
NaN
is a good idea. It is such a common source of bugs that I'd rather just disallow it entirely. If someone really wants an obviously bad value, they can use-Infinity
or something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gerrit0 Yeah, that's probably the better solution for now. That way you can be sure to have "a number" as a value.