hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

stou.ha (849B)


      1 // License: MPL-2.0
      2 // (c) 2021 Andri Yngvason <andri@yngvason.is>
      3 // (c) 2022 Bor Grošelj Simić <bor.groseljsimic@telemach.net>
      4 // (c) 2021 Ember Sawady <ecs@d2evs.net>
      5 
      6 @test fn stou() void = {
      7 	assert(stou64("") as invalid == 0: invalid);
      8 	assert(stou64("abc") as invalid == 0: invalid);
      9 	assert(stou64("1a") as invalid == 1: invalid);
     10 	assert(stou64("-1") as invalid == 0: invalid);
     11 
     12 	assert(stou64("18446744073709551616") is overflow);
     13 	assert(stou64("184467440737095516150") is overflow);
     14 
     15 	assert(stou64("0") as u64 == 0);
     16 	assert(stou64("1") as u64 == 1);
     17 	assert(stou64("18446744073709551615") as u64 == 18446744073709551615);
     18 };
     19 
     20 @test fn stoub() void = {
     21 	assert(stou64b("7f", 16) as u64 == 0x7f);
     22 	assert(stou64b("7F", 16) as u64 == 0x7f);
     23 	assert(stou64b("37", 8) as u64 == 0o37);
     24 	assert(stou64b("110101", 2) as u64 == 0b110101);
     25 };