diff --git a/tests/streq.porth b/tests/streq.porth new file mode 100644 index 00000000..3e8608b1 --- /dev/null +++ b/tests/streq.porth @@ -0,0 +1,33 @@ +include "std.porth" + +macro debug_streq + "\"" puts + over dup strlen swap puts + "\" == \"" puts + dup dup strlen swap puts + "\" is " puts + streq print +end + +macro str_as_ptr swap drop end + + +"hello\0" str_as_ptr +"hello\0" str_as_ptr +debug_streq + +"hello\0" str_as_ptr +"world\0" str_as_ptr +debug_streq + +"hello\0" str_as_ptr +"\0" str_as_ptr +debug_streq + +"\0" str_as_ptr +"world\0" str_as_ptr +debug_streq + +"\0" str_as_ptr +"\0" str_as_ptr +debug_streq diff --git a/tests/streq.txt b/tests/streq.txt new file mode 100644 index 00000000..4cff3dc6 --- /dev/null +++ b/tests/streq.txt @@ -0,0 +1,13 @@ +:i argc 0 +:b stdin 0 + +:i returncode 0 +:b stdout 100 +"hello" == "hello" is 1 +"hello" == "world" is 0 +"hello" == "" is 0 +"" == "world" is 0 +"" == "" is 1 + +:b stderr 0 + diff --git a/tests/strlen.porth b/tests/strlen.porth new file mode 100644 index 00000000..a3b9b9ba --- /dev/null +++ b/tests/strlen.porth @@ -0,0 +1,14 @@ +include "std.porth" + +macro debug_strlen + "strlen(\"" puts + dup dup strlen swap puts + "\") == " puts + strlen print +end + +macro str_as_ptr swap drop end + + +"\0" str_as_ptr debug_strlen +"hello\0" str_as_ptr debug_strlen diff --git a/tests/strlen.txt b/tests/strlen.txt new file mode 100644 index 00000000..9e7f8a2e --- /dev/null +++ b/tests/strlen.txt @@ -0,0 +1,10 @@ +:i argc 0 +:b stdin 0 + +:i returncode 0 +:b stdout 37 +strlen("") == 0 +strlen("hello") == 5 + +:b stderr 0 +