hare

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

stou_test.ha (743B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 @test fn stou() void = {
      5 	assert(stou64("") as invalid == 0: invalid);
      6 	assert(stou64("abc") as invalid == 0: invalid);
      7 	assert(stou64("1a") as invalid == 1: invalid);
      8 
      9 	assert(stou64("18446744073709551616") is overflow);
     10 	assert(stou64("184467440737095516150") is overflow);
     11 	assert(stou64("-1") is overflow);
     12 
     13 	assert(stou64("0") as u64 == 0);
     14 	assert(stou64("1") as u64 == 1);
     15 	assert(stou64("18446744073709551615") as u64 == 18446744073709551615);
     16 };
     17 
     18 @test fn stoub() void = {
     19 	assert(stou64b("7f", 16) as u64 == 0x7f);
     20 	assert(stou64b("7F", 16) as u64 == 0x7f);
     21 	assert(stou64b("37", 8) as u64 == 0o37);
     22 	assert(stou64b("110101", 2) as u64 == 0b110101);
     23 };