Files
mercury/tests/hard_coded/from_int_uint64.m
Julien Fischer ee2804ad7d Add a test of int -> uint64 conversion.
tests/hard_coded/Mmakefile:
tests/hard_coded/from_int_uint64.{m,exp*}:
     As above.
2021-06-30 22:58:48 +10:00

66 lines
1.6 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
%---------------------------------------------------------------------------%
% Test conversion of Mercury ints to signed 64-bit integers.
% The .exp file is for systems where int is 64-bit.
% The .exp2 file is for systems where int is 32-bit.
:- module from_int_uint64.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module uint64.
:- import_module list.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
list.foldl(do_test, numbers, !IO).
:- pred do_test(string::in, io::di, io::uo) is det.
do_test(IntStr, !IO) :-
io.format("from_int(%s) = ", [s(IntStr)], !IO),
( if
string.to_int(IntStr, Int),
uint64.from_int(Int, UInt64)
then
io.format("%u\n", [u64(UInt64)], !IO)
else
io.write_string("<<out-of-range>>\n", !IO)
).
:- func numbers = list(string).
numbers = [
"-9223372036854775808",
"-2147483648",
"-32768",
"-128",
"0",
"1",
"2",
"8",
"10",
"16",
"127",
"32767",
"2147483647",
"9223372036854775807"
].
%---------------------------------------------------------------------------%
:- end_module from_int_uint64.
%---------------------------------------------------------------------------%