Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for split_by_ascii_whitespace #428

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -27,9 +29,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