Skip to content

Commit

Permalink
Put all pointer tests into the same file (#139)
Browse files Browse the repository at this point in the history
* Put all pointer tests into the same place

* windows workarounds

* Revert "windows workarounds"

This reverts commit 1463aa6.

* better? windows u happy now?..

* lol
  • Loading branch information
Akuli authored Jan 24, 2023
1 parent 8eb58bd commit a05d691
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 39 deletions.
7 changes: 0 additions & 7 deletions tests/should_succeed/indexing_bug.jou

This file was deleted.

10 changes: 0 additions & 10 deletions tests/should_succeed/malloc.jou

This file was deleted.

13 changes: 0 additions & 13 deletions tests/should_succeed/null.jou

This file was deleted.

34 changes: 25 additions & 9 deletions tests/should_succeed/pointer.jou
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from "stdlib/io.jou" import putchar, puts
from "stdlib/io.jou" import putchar, puts, printf
from "stdlib/mem.jou" import malloc, free

def putchar_pointer(ch: int*) -> void:
Expand All @@ -16,7 +16,22 @@ def myputs2(s: byte*) -> void:
while *s != '\0':
putchar(*s++)

def foo(ptr: int*) -> void:
if ptr == NULL:
printf("Got NULL\n")
else:
printf("Got %d\n", *ptr)

def main() -> int:
# Test assigning to pointer
foo: byte* = malloc(4)
*foo = 'a'
foo[1] = 'b'
foo[2] = 'c'
foo[3] = '\0'
puts(foo) # Output: abc
free(foo)

# Output: hhii
putchar2('h')
putchar2('i')
Expand All @@ -26,16 +41,17 @@ def main() -> int:
putchar("hey"[1+1]) # Output: y
putchar('\n')

# Make sure that unsigned indexes work. The compiler must
# convert them to signed for LLVM to be happy.
# Output: i
putchar("012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789abcdefghi"[128 as byte])
putchar('\n')

myputs1("asd\n") # Output: asd
myputs2("foo\n") # Output: foo

# Test assigning to pointer
foo: byte* = malloc(4)
foo[0] = 'a'
foo[1] = 'b'
foo[2] = 'c'
foo[3] = '\0'
puts(foo) # Output: abc
free(foo)
x = 123
foo(&x) # Output: Got 123
foo(NULL) # Output: Got NULL

return 0

0 comments on commit a05d691

Please sign in to comment.