-
Notifications
You must be signed in to change notification settings - Fork 8
fix: numeric constraints and range values are numeric #31
Conversation
* livescript is terse, but at least the numeric cast operator is a big plus * expr-value casts to numeric (do we expect dates or types other than string and numeric here?) * convert-question for type "range" casts min, max, step to numeric * no extensive testing done yet with different ranges and constraints * existing tests passing, no new tests added (coming next) * tested: numeric question with appearance slider > XLSForm > Central > Collect works * tested: numeric question with valid range > XLSForm > Central > Collect works
* Constraints work even if the values are strings * Add tests for range parameters given as string getting converted to int
@@ -220,7 +220,7 @@ convert-question = (question, context, prefix = []) -> | |||
# range parameters. | |||
if question.type is \range | |||
select-range = (delete question.selectRange) | |||
question.parameters = { start: select-range?.min, end: select-range?.max, step: (delete question.selectStep) } | |||
question.parameters = { start: +select-range?.min, end: +select-range?.max, step: +(delete question.selectStep) } |
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.
The explicit cast to numeric is the main and only source code change of this PR.
@@ -545,4 +545,7 @@ describe 'parameters' -> | |||
for appearance in [ 'Slider', 'Vertical Slider', 'Picker' ] | |||
result = { type: \inputNumeric, appearance, selectRange: { min: 13, max: 42 }, selectStep: 1.5 } |> convert-simple | |||
expect(result.parameters).toBe('start=13 end=42 step=1.5') | |||
|
|||
# Slider parameters are quoted in XForm but must be numeric in XLSForm |
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.
This new test shows the intended added behaviour: string values get cast to numeric.
spec/src/convert-question-spec.ls
Outdated
@@ -228,7 +228,7 @@ describe \constraint -> | |||
|
|||
test 'build number range constraint generation (max)' -> | |||
result = { type: \inputNumber, range: { max: 3, maxInclusive: true } } |> convert-simple | |||
expect(result.constraint).toBe('(. <= 3)') | |||
expect(result.constraint).toBe('(. <= 3)') |
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.
That extra whitespace is a dud, sorry.
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.
This was simpler than it looked on my phone. Remove the extra spaces before merging?
Of course - there's always space for improvement. |
update: