From 5482107ca88d74078a45fc2e4599ebab5df8744c Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 7 Mar 2025 00:14:41 +0100 Subject: [PATCH] Some formatting and updated test. Updated releasenotes. --- lib/std/core/string_to_real.c3 | 3 ++- releasenotes.md | 1 + test/unit/stdlib/string_to_float.c3 | 24 ++++-------------------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/std/core/string_to_real.c3 b/lib/std/core/string_to_real.c3 index 00d05d0be..f0f2daced 100644 --- a/lib/std/core/string_to_real.c3 +++ b/lib/std/core/string_to_real.c3 @@ -465,7 +465,8 @@ macro String.to_real(chars, $Type) @private while (chars.len && chars[0] == ' ') chars = chars[1..]; if (!chars.len) return NumberConversion.MALFORMED_FLOAT?; - if (chars.len != 1) { + if (chars.len != 1) + { switch (chars[0]) { case '-': diff --git a/releasenotes.md b/releasenotes.md index ea5fcbdda..b1d4520de 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -30,6 +30,7 @@ - Aliases were incorrectly considered compile time constants. - FreeBSD libc stat definitions were incorrect. - Atomic max was incorrect. +- `"+".to_float()` would panic. ### Stdlib changes - `new_*` functions in general moved to version without `new_` prefix. diff --git a/test/unit/stdlib/string_to_float.c3 b/test/unit/stdlib/string_to_float.c3 index e46bee8e7..bf650a844 100644 --- a/test/unit/stdlib/string_to_float.c3 +++ b/test/unit/stdlib/string_to_float.c3 @@ -12,16 +12,8 @@ fn void test_float() @test assert(String.to_float("-23.545")!! == -23.545f); assert(String.to_float("1.5555555555555")!! == 1.5555555555555f); assert(String.to_float("1.5555555555556666")!! == 1.5555555555556666f); - if (catch excuse = String.to_float("+")) { - assert(excuse == NumberConversion.MALFORMED_FLOAT); - } else { - assert(false); - } - if (catch excuse = String.to_float("-")) { - assert(excuse == NumberConversion.MALFORMED_FLOAT); - } else { - assert(false); - } + test::@error("+".to_float(), NumberConversion.MALFORMED_FLOAT); + test::@error("-".to_float(), NumberConversion.MALFORMED_FLOAT); } fn void test_double() @test @@ -36,14 +28,6 @@ fn void test_double() @test assert(String.to_double("-23.545")!! == -23.545); assert(String.to_double("1.5555555555555")!! == 1.5555555555555); assert(String.to_double("1.5555555555556666")!! == 1.5555555555556666); - if (catch excuse = String.to_double("+")) { - assert(excuse == NumberConversion.MALFORMED_FLOAT); - } else { - assert(false); - } - if (catch excuse = String.to_double("-")) { - assert(excuse == NumberConversion.MALFORMED_FLOAT); - } else { - assert(false); - } + test::@error("+".to_double(), NumberConversion.MALFORMED_FLOAT); + test::@error("-".to_double(), NumberConversion.MALFORMED_FLOAT); }