From 8f93d49f375a06ac1bbd38e6864c9190bfa1792c Mon Sep 17 00:00:00 2001 From: Waqas Tahir Date: Mon, 10 Feb 2025 19:49:28 +0500 Subject: [PATCH] tested pointers with runtime methods --- lang/tests/src/comptime/pointers.ch | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lang/tests/src/comptime/pointers.ch b/lang/tests/src/comptime/pointers.ch index 565bcf7b..974e596e 100644 --- a/lang/tests/src/comptime/pointers.ch +++ b/lang/tests/src/comptime/pointers.ch @@ -1,29 +1,25 @@ import "./test.ch" -@comptime -func give_comptime_char_by_offset(str : *char, offset : int) : char { +func give_char_by_offset(str : *char, offset : int) : char { return *(str + offset); } -@comptime -func give_comptime_char_by_ptr_offset(str : *char, offset : int) : char { +func give_char_by_ptr_offset(str : *char, offset : int) : char { var x = str as *char x += offset return *x; } -@comptime -func test_inc_dec_work_comptime_ptr1() : char { +func test_inc_dec_work_ptr1() : char { const str = "hello world" - const ptr = str as *char; + var ptr = str as *char; ptr++ return *ptr } -@comptime -func test_inc_dec_work_comptime_ptr2() : char { +func test_inc_dec_work_ptr2() : char { const str = "hello world" - const ptr = str as *char; + var ptr = str as *char; ptr++ ptr-- return *ptr @@ -32,21 +28,21 @@ func test_inc_dec_work_comptime_ptr2() : char { func test_pointers_in_comptime() { test("comptime pointers work - 1", () => { - return give_comptime_char_by_offset("hello", 0) == 'h'; + return comptime { give_char_by_offset("hello", 0) } == give_char_by_offset("hello", 0) }) test("comptime pointers work - 2", () => { - return give_comptime_char_by_ptr_offset("hello", 0) == 'h' + return comptime { give_char_by_ptr_offset("hello", 0) } == give_char_by_ptr_offset("hello", 0) }) test("comptime pointers work - 3", () => { - return give_comptime_char_by_ptr_offset("hello", 1) == 'e' + return comptime { give_char_by_ptr_offset("hello", 1) } == give_char_by_ptr_offset("hello", 1) }) test("comptime pointers work - 4", () => { - return give_comptime_char_by_ptr_offset("hello", 4) == 'o' + return comptime { give_char_by_ptr_offset("hello", 4) } == give_char_by_ptr_offset("hello", 4) }) test("comptime pointers work with increment decrement - 1", () => { - return test_inc_dec_work_comptime_ptr1() == 'e' + return comptime { test_inc_dec_work_ptr1() } == test_inc_dec_work_ptr1() }) test("comptime pointers work with increment decrement - 2", () => { - return test_inc_dec_work_comptime_ptr2() == 'h'; + return comptime { test_inc_dec_work_ptr2() } == test_inc_dec_work_ptr2() }) } \ No newline at end of file