mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- String.to_integer does not correctly return in some cases where it should #2590.
This commit is contained in:
42
test/unit/stdlib/core/string_to_int.c3
Normal file
42
test/unit/stdlib/core/string_to_int.c3
Normal file
@@ -0,0 +1,42 @@
|
||||
module string_to_int;
|
||||
import std::io, std::math;
|
||||
|
||||
const N = 2560;
|
||||
macro String[] m() @const
|
||||
{
|
||||
var $strings = {};
|
||||
$foreach $i : math::iota(int[N]):
|
||||
$strings +++= @sprintf("%s", $i);
|
||||
$endforeach
|
||||
return $strings;
|
||||
}
|
||||
|
||||
macro String[] m2() @const
|
||||
{
|
||||
var $strings = {};
|
||||
$foreach $i : math::iota(int[N]):
|
||||
$strings +++= @sprintf("%s", -$i);
|
||||
$endforeach
|
||||
return $strings;
|
||||
}
|
||||
|
||||
fn void string_to_char() @test
|
||||
{
|
||||
int valid = 0;
|
||||
foreach (str : m())
|
||||
{
|
||||
char? x = str.to_integer(char);
|
||||
if (try x) valid++;
|
||||
}
|
||||
assert(valid == 256);
|
||||
}
|
||||
fn void string_to_ichar() @test
|
||||
{
|
||||
int valid = 0;
|
||||
foreach (str : m2())
|
||||
{
|
||||
ichar? x = str.to_integer(ichar);
|
||||
if (try x) valid++;
|
||||
}
|
||||
assert(valid == 129);
|
||||
}
|
||||
Reference in New Issue
Block a user