src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/mods/path/path_test.elvts (about) 1 //each:eval use path 2 3 // All the functions in path: are either simple wrappers of Go functions or 4 // compatibility aliases of their os: counterparts. 5 // 6 // As a result, the tests are just simple "smoke tests" to ensure that they 7 // exist and map to the correct function. 8 9 ///////////// 10 # functions # 11 ///////////// 12 13 ~> use str 14 var abs = (path:abs a/b/c.png) 15 path:is-abs $abs 16 str:has-suffix $abs (path:join a b c.png) 17 ▶ $true 18 ▶ $true 19 ~> path:base a/b/d.png 20 ▶ d.png 21 ~> path:clean ././x 22 ▶ x 23 ~> path:ext a/b/e.png 24 ▶ .png 25 ~> path:ext a/b/s 26 ▶ '' 27 ~> path:is-abs a/b/s 28 ▶ $false 29 30 ///////////////// 31 # Unix-specific # 32 ///////////////// 33 34 //only-on unix 35 ~> put $path:dev-null 36 ▶ /dev/null 37 ~> put $path:dev-tty 38 ▶ /dev/tty 39 ~> put $path:list-separator 40 ▶ : 41 ~> put $path:separator 42 ▶ / 43 ~> path:join a b c 44 ▶ a/b/c 45 ~> path:clean a/b/.././c 46 ▶ a/c 47 ~> path:dir a/b/d.png 48 ▶ a/b 49 50 //////////////////// 51 # Windows-specific # 52 //////////////////// 53 54 //only-on windows 55 ~> put $path:dev-null 56 ▶ NUL 57 ~> put $path:dev-tty 58 ▶ CON 59 ~> put $path:list-separator 60 ▶ ';' 61 ~> put $path:separator 62 ▶ \ 63 ~> path:join a b c 64 ▶ a\b\c 65 ~> path:clean a/b/.././c 66 ▶ a\c 67 ~> path:dir a/b/d.png 68 ▶ a\b 69 70 ///////////////////////// 71 # compatibility aliases # 72 ///////////////////////// 73 74 //in-temp-dir-with-d-f 75 ~> use file 76 use re 77 use os 78 ~> path:eval-symlinks d 79 ▶ d 80 ~> path:is-dir d 81 ▶ $true 82 ~> path:is-regular d/f 83 ▶ $true 84 ~> var x = (path:temp-dir) 85 re:match '^.*'(re:quote $path:separator)'elvish-.*$' $x 86 os:remove $x 87 ▶ $true 88 ~> var f = (path:temp-file) 89 re:match '^.*'(re:quote $path:separator)'elvish-.*$' $f[name] 90 file:close $f 91 os:remove $f[name] 92 ▶ $true