From 19830ecaf39eede047daa7e4d40ad42794931ea7 Mon Sep 17 00:00:00 2001 From: Manuel Saelices Date: Sat, 21 Sep 2024 00:08:57 +0200 Subject: [PATCH] [stdlib] Test for the pointers difference Signed-off-by: Manuel Saelices --- stdlib/test/memory/test_unsafepointer.mojo | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stdlib/test/memory/test_unsafepointer.mojo b/stdlib/test/memory/test_unsafepointer.mojo index 48147d9a6f..e8b2cafac6 100644 --- a/stdlib/test/memory/test_unsafepointer.mojo +++ b/stdlib/test/memory/test_unsafepointer.mojo @@ -282,6 +282,14 @@ def test_load_and_store_simd(): assert_equal(ptr2[i], i // 4 * 4) +def test_difference(): + var ptr = UnsafePointer[Int].alloc(5) + var ptr2 = ptr + 2 + assert_equal(ptr2 - ptr, 2) + assert_equal(ptr - ptr2, -2) + ptr.free() + + def main(): test_address_of() @@ -297,6 +305,7 @@ def main(): test_unsafepointer_string() test_eq() test_comparisons() + test_difference() test_unsafepointer_address_space() test_indexing()