Skip to content
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

Add test cases for issues #10544 & #10545 #10546

Merged
merged 4 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/numeric.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ let parse_float s =
let rec loop sp i =
if i = String.length s then (if sp = 0 then s else String.sub s sp (i - sp)) else
match String.unsafe_get s i with
| ' ' when sp = i -> loop (sp + 1) (i + 1)
| ' ' | '\t' when sp = i -> loop (sp + 1) (i + 1)
| '0'..'9' | '-' | '+' | 'e' | 'E' | '.' -> loop sp (i + 1)
| _ -> String.sub s sp (i - sp)
in
Expand Down
2 changes: 1 addition & 1 deletion std/lua/_std/Std.hx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import lua.NativeStringTools;
public static function parseFloat(x:String):Float {
if (x == null || x == "")
return Math.NaN;
var digitMatch = NativeStringTools.match(x, "^ *[%.%-+]?[0-9]%d*");
var digitMatch = NativeStringTools.match(x, "^%s*[%.%-+]?[0-9]%d*");
if (digitMatch == null) {
return Math.NaN;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/src/unitstd/Std.unit.hx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ Std.parseInt(' -0x10') == -16;
#end
#end

#if !neko
Std.parseInt("+123") == 123;
Std.parseInt("-0xa0") == -160;
#end

// parseFloat
Std.parseFloat("0") == 0.;
Std.parseFloat(" 5.3") == 5.3;
Expand All @@ -118,6 +123,7 @@ Std.parseFloat("2.426670815e-12") == 2.426670815e-12;
Std.parseFloat("2.426670815E-12") == 2.426670815e-12;
// Std.parseInt("0x C") == 0;
// Std.parseInt("0x+A") == 0;
Std.parseFloat(" \t42.2") == 42.2;

// random
var x = Std.random(2);
Expand Down