fix: use parsed integer num instead of rawNum in repeat helper loop - #128
Conversation
nishantwrp
left a comment
There was a problem hiding this comment.
please add a unit test that fails without this change as well
|
Hey @sh1vam31, just a friendly reminder on the requested test: a case where the input is a non-numeric string (e.g., |
Adds the regression test requested in review. Both cases fail against the unfixed helper and pass with it. parseInt and the loop's own coercion disagree on anything that is not a clean integer string: - "3abc": parseInt gives 3, Number gives NaN, so comparing against the raw string ran zero iterations and produced nothing at all - "3.7": parseInt gives 3, Number gives 3.7, so the raw comparison ran one iteration too many Note that "abc" cannot cover this, which was suggested earlier in the review thread. parseInt returns NaN for it, so the helper throws before reaching the loop and never exercises the difference. That path is already covered by the existing "should throw on non-numeric input".
|
@sh1vam31 I've pushed the requested test to your branch, plus a merge of master since your branch predated the helper test file - your commit is untouched. @nishantwrp the |
|
Thank you so much @alondmnt for adding the regression tests and merging master. The test cases with |
Fixes #124
In src/helpers/repeat.ts, the repeat helper was using
rawNum(a raw string) instead ofnum(the parsed integer) in the for loop condition.After fix :

Problem