ChatGPT wrote some unit tests and found a small bug.
When asked to fix the bug, it came up with a different regex, which would completely change what's valid and what's not, so that's totally wrong: /^\s*(-)?([0-9]+)(?:[,.]([0-9]{1,2}))?\s*$/ When asked to fix it in another way, without changing the regex, it suggested stripping the sign completely, which is even more wrong. So I fixed it myself :)
This commit is contained in:
parent
06d4591e8a
commit
b052292a22
2 changed files with 117 additions and 0 deletions
|
@ -81,6 +81,8 @@ sub parse_string($class, $str) {
|
|||
= $str =~ /^\s*(?:\+|(-)?)([0-9]+)?(?:[,.]([0-9]{1,2}))?\s*$/
|
||||
or return undef;
|
||||
|
||||
defined $int or defined $cents or return undef;
|
||||
|
||||
$int //= 0;
|
||||
$cents //= 0;
|
||||
$cents *= 10 if length($cents) == 1; # 4.2 -> 4.20
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue