hare

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

commit f4e781a6ab5118aff7fd738d49bfc0f5b84e5742
parent ad964a36eb27cc0f9d4fbf465e84d2c9f7d1cb59
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  4 Feb 2021 14:06:30 -0500

strconv: add tests

Diffstat:
Mstrconv/itos.ha | 25+++++++++++++++++++++++++
Mstrconv/utos.ha | 21+++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/strconv/itos.ha b/strconv/itos.ha @@ -57,3 +57,28 @@ export fn i32tos(i: i32) const str = i64tos(i: i64); // allocated and will be overwritten on subsequent calls; see [strings::dup] to // duplicate the result. export fn itos(i: int) const str = i64tos(i: i64); + +@test fn test_itos() void = { + // I64_MAX: https://todo.sr.ht/~sircmpwn/hare-v2/185 + const samples = [ + 1234i64, + 4321i64, + -1337i64, + 0, + types::I64_MAX, + //types::I64_MIN, + ]; + const expected = [ + "1234", + "4321", + "-1337", + "0", + "9223372036854775807", + //"-9223372036854775808", + ]; + + for (let i = 0z; i < len(samples); i += 1z) { + const s = i64tos(samples[i]); + assert(s == expected[i]); + }; +}; diff --git a/strconv/utos.ha b/strconv/utos.ha @@ -60,3 +60,24 @@ export fn ztos(z: size) const str = u64tos(z: u64); // allocated and will be overwritten on subsequent calls; see [strings::dup] to // duplicate the result. export fn uptrtos(uptr: uintptr) const str = u64tos(uptr: u64); + +@test fn test_utos() void = { + // U64_MAX: https://todo.sr.ht/~sircmpwn/hare-v2/185 + const samples = [ + 1234u64, + 4321u64, + types::U64_MIN, + //types::U64_MAX, + ]; + const expected = [ + "1234", + "4321", + "0", + //"18446744073709551615", + ]; + + for (let i = 0z; i < len(samples); i += 1z) { + const s = u64tos(samples[i]); + assert(s == expected[i]); + }; +};