Skip to content

Commit

Permalink
Add tests for split_by_ascii_whitespace (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Dec 6, 2023
1 parent c086866 commit e8255f0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/should_succeed/ascii_test.jou
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import "stdlib/ascii.jou"
import "stdlib/io.jou"
import "stdlib/mem.jou"
import "stdlib/str.jou"

def main() -> int:
Expand Down Expand Up @@ -35,9 +37,20 @@ def main() -> int:
assert not is_ascii_whitespace('.')
assert not is_ascii_whitespace('\0')

s: byte[100]
strcpy(s, " hello world \r\n \t ")
s: byte[100] = " hello world \r\n \t "
trim_ascii_whitespace(s)
assert strcmp(s, "hello world") == 0

s = " hello world \r\n \t "
words = split_by_ascii_whitespace(s)
# Output: hello
# Output: world
for w = words; *w != NULL; w++:
puts(*w)
# Output: hello
# Output: world
for i = 0; words[i] != NULL; i++:
puts(words[i])
free(words)

return 0

0 comments on commit e8255f0

Please sign in to comment.