| 1 | #include "cpp/pylib.h"
|
| 2 |
|
| 3 | #include "mycpp/runtime.h"
|
| 4 | #include "vendor/greatest.h"
|
| 5 |
|
| 6 | TEST os_path_test() {
|
| 7 | // TODO: use gc_mylib here, with NewStr(), StackRoots, etc.
|
| 8 | BigStr* s = nullptr;
|
| 9 |
|
| 10 | s = os_path::rstrip_slashes(StrFromC(""));
|
| 11 | ASSERT(str_equals(s, StrFromC("")));
|
| 12 |
|
| 13 | s = os_path::rstrip_slashes(StrFromC("foo"));
|
| 14 | ASSERT(str_equals(s, StrFromC("foo")));
|
| 15 |
|
| 16 | s = os_path::rstrip_slashes(StrFromC("foo/"));
|
| 17 | ASSERT(str_equals(s, StrFromC("foo")));
|
| 18 |
|
| 19 | s = os_path::rstrip_slashes(StrFromC("/foo/"));
|
| 20 | ASSERT(str_equals(s, StrFromC("/foo")));
|
| 21 |
|
| 22 | // special case of not stripping
|
| 23 | s = os_path::rstrip_slashes(StrFromC("///"));
|
| 24 | ASSERT(str_equals(s, StrFromC("///")));
|
| 25 |
|
| 26 | ASSERT(path_stat::exists(StrFromC("/")));
|
| 27 | ASSERT(!path_stat::exists(StrFromC("/nonexistent_ZZZ")));
|
| 28 |
|
| 29 | PASS();
|
| 30 | }
|
| 31 |
|
| 32 | TEST isdir_test() {
|
| 33 | ASSERT(path_stat::isdir(StrFromC(".")));
|
| 34 | ASSERT(path_stat::isdir(StrFromC("/")));
|
| 35 | PASS();
|
| 36 | }
|
| 37 |
|
| 38 | GREATEST_MAIN_DEFS();
|
| 39 |
|
| 40 | int main(int argc, char** argv) {
|
| 41 | gHeap.Init();
|
| 42 |
|
| 43 | GREATEST_MAIN_BEGIN();
|
| 44 |
|
| 45 | RUN_TEST(os_path_test);
|
| 46 | RUN_TEST(isdir_test);
|
| 47 |
|
| 48 | gHeap.CleanProcessExit();
|
| 49 |
|
| 50 | GREATEST_MAIN_END();
|
| 51 | return 0;
|
| 52 | }
|