From ee2804ad7d4385ef7b7fa437e2e7292ef98f21cf Mon Sep 17 00:00:00 2001 From: Julien Fischer Date: Wed, 30 Jun 2021 22:58:48 +1000 Subject: [PATCH] Add a test of int -> uint64 conversion. tests/hard_coded/Mmakefile: tests/hard_coded/from_int_uint64.{m,exp*}: As above. --- tests/hard_coded/Mmakefile | 1 + tests/hard_coded/from_int_uint64.exp | 14 ++++++ tests/hard_coded/from_int_uint64.exp2 | 14 ++++++ tests/hard_coded/from_int_uint64.m | 65 +++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 tests/hard_coded/from_int_uint64.exp create mode 100644 tests/hard_coded/from_int_uint64.exp2 create mode 100644 tests/hard_coded/from_int_uint64.m diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile index 765a6b9e3..ca85af8d4 100644 --- a/tests/hard_coded/Mmakefile +++ b/tests/hard_coded/Mmakefile @@ -160,6 +160,7 @@ ORDINARY_PROGS = \ from_int_int8 \ from_int_uint16 \ from_int_uint32 \ + from_int_uint64 \ from_int_uint8 \ func_and_pred \ func_ctor_ambig \ diff --git a/tests/hard_coded/from_int_uint64.exp b/tests/hard_coded/from_int_uint64.exp new file mode 100644 index 000000000..d87d73ddf --- /dev/null +++ b/tests/hard_coded/from_int_uint64.exp @@ -0,0 +1,14 @@ +from_int(-9223372036854775808) = <> +from_int(-2147483648) = <> +from_int(-32768) = <> +from_int(-128) = <> +from_int(0) = 0 +from_int(1) = 1 +from_int(2) = 2 +from_int(8) = 8 +from_int(10) = 10 +from_int(16) = 16 +from_int(127) = 127 +from_int(32767) = 32767 +from_int(2147483647) = 2147483647 +from_int(9223372036854775807) = 9223372036854775807 diff --git a/tests/hard_coded/from_int_uint64.exp2 b/tests/hard_coded/from_int_uint64.exp2 new file mode 100644 index 000000000..3045bb271 --- /dev/null +++ b/tests/hard_coded/from_int_uint64.exp2 @@ -0,0 +1,14 @@ +from_int(-9223372036854775808) = <> +from_int(-2147483648) = <> +from_int(-32768) = <> +from_int(-128) = <> +from_int(0) = 0 +from_int(1) = 1 +from_int(2) = 2 +from_int(8) = 8 +from_int(10) = 10 +from_int(16) = 16 +from_int(127) = 127 +from_int(32767) = 32767 +from_int(2147483647) = 2147483647 +from_int(9223372036854775807) = <> diff --git a/tests/hard_coded/from_int_uint64.m b/tests/hard_coded/from_int_uint64.m new file mode 100644 index 000000000..c426df466 --- /dev/null +++ b/tests/hard_coded/from_int_uint64.m @@ -0,0 +1,65 @@ +%---------------------------------------------------------------------------% +% 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("<>\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. +%---------------------------------------------------------------------------%