diff options
author | Steve Bennett <steveb@workware.net.au> | 2019-10-17 22:04:49 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2019-10-18 07:59:35 +1000 |
commit | 058d07b597ce088b86e7e8a070bcfa07509f26e1 (patch) | |
tree | e7e6af728d0eecbf8b9c39fbe8c9f9bfa8cdf8e5 /tests | |
parent | ca4fa3865a730857b385e6e34af67db3471e0089 (diff) | |
download | jimtcl-058d07b597ce088b86e7e8a070bcfa07509f26e1.zip jimtcl-058d07b597ce088b86e7e8a070bcfa07509f26e1.tar.gz jimtcl-058d07b597ce088b86e7e8a070bcfa07509f26e1.tar.bz2 |
file: Better support for trailing slashes in pathnames
e.g. file tail /abc/def/ => def
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/file.test | 151 | ||||
-rw-r--r-- | tests/filejoin.test | 84 |
2 files changed, 151 insertions, 84 deletions
diff --git a/tests/file.test b/tests/file.test new file mode 100644 index 0000000..10211cd --- /dev/null +++ b/tests/file.test @@ -0,0 +1,151 @@ +source [file dirname [info script]]/testing.tcl + +needs cmd file + +test join-1.1 "One name" { + file join abc +} {abc} + +test join-1.2 "One name with trailing slash" { + file join abc/ +} {abc} + +test join-1.3 "One name with leading slash" { + file join /abc +} {/abc} + +test join-1.4 "One name with leading and trailing slash" { + file join /abc/ +} {/abc} + +test join-1.5 "Two names" { + file join abc def +} {abc/def} + +test join-1.6 "Two names with dir trailing slash" { + file join abc/ def +} {abc/def} + +test join-1.7 "Two names with dir leading slash" { + file join /abc def +} {/abc/def} + +test join-1.8 "Two names with dir leading and trailing slash" { + file join /abc/ def +} {/abc/def} + +test join-1.9 "Two names with file trailing slash" { + file join abc def/ +} {abc/def} + +test join-1.10 "Two names with file leading slash" { + file join abc /def +} {/def} + +test join-1.11 "Two names with file leading and trailing slash" { + file join abc /def/ +} {/def} + +test join-1.12 "Two names with double slashes" { + file join abc/ /def +} {/def} + +test join-1.13 "Join to root" { + file join / abc +} {/abc} + +test join-1.14 "Join to root" { + set dir [file join / .] + # Either / or /. is OK here + expr {$dir in {/ /.}} +} 1 + +test join-1.15 "Join to root" { + file join / / +} {/} + +test join-1.16 "Join to root" { + file join /abc / +} {/} + +test join-1.17 "With trailing slash" { + file join /abc/def/ ghi/jkl +} {/abc/def/ghi/jkl} + +test join-2.1 "Dir is empty string" { + file join "" def +} {def} + +test join-2.2 "File is empty string" { + file join abc "" +} {abc} + +test join-2.3 "Path too long" jim { + set components [string repeat {abcdefghi } 500] + list [catch [concat file join $components] msg] $msg +} {1 {Path too long}} + +test tail-1.1 "One component" { + file tail abc +} {abc} + +test tail-1.2 "Two components" { + file tail abc/def +} {def} + +test tail-1.3 "Absolute one component" { + file tail /abc +} {abc} + +test tail-1.4 "Trailing slash" { + file tail abc/ +} {abc} + +test dirname-1.1 "One component" { + file dirname abc +} {.} + +test dirname-1.2 "Two components" { + file dirname abc/def +} {abc} + +test dirname-1.3 "Absolute one component" { + file dirname /abc +} {/} + +test dirname-1.4 "Trailing slash" { + file dirname abc/ +} {.} + +# These tests are courtesy of picol + +test file.12.1 "picol test" {file dirname /foo/bar/grill.txt} /foo/bar +test file.12.2 "picol test" {file dirname /foo/bar/baz/} /foo/bar +test file.12.3 "picol test" {file dirname /foo/bar/baz///} /foo/bar +test file.12.4 "picol test" {file dirname /foo/bar/baz///qux} /foo/bar/baz +test file.12.5 "picol test" {file dirname foo/bar/grill.txt} foo/bar +test file.12.6 "picol test" {file dirname foo/bar/baz/} foo/bar +test file.12.7 "picol test" {file dirname {}} . +test file.12.8 "picol test" {file dirname /} / +test file.12.9 "picol test" {file dirname ///} / + +test file.13.1 "picol test" {file tail /foo/bar/grill.txt} grill.txt +test file.13.2 "picol test" {file tail /foo/bar/baz/} baz +test file.13.3 "picol test" {file tail /foo/bar/baz///} baz +test file.13.4 "picol test" {file dirname /foo/bar/baz///qux} /foo/bar/baz +test file.13.5 "picol test" {file tail foo/bar/grill.txt} grill.txt +test file.13.6 "picol test" {file tail foo/bar/baz/} baz +test file.13.7 "picol test" {file tail {}} {} +test file.13.8 "picol test" {file tail /} {} +test file.13.9 "picol test" {file tail ///} {} + +test file.14 "picol test" {file join foo} foo +test file.15 "picol test" {file join foo bar} foo/bar +test file.16 "picol test" {file join foo /bar} /bar + +if {$tcl_platform(platform) eq {windows}} { + test file.17 "picol test" {file join foo C:/bar grill} C:/bar/grill +} + + +testreport diff --git a/tests/filejoin.test b/tests/filejoin.test deleted file mode 100644 index 7245938..0000000 --- a/tests/filejoin.test +++ /dev/null @@ -1,84 +0,0 @@ -source [file dirname [info script]]/testing.tcl - -needs cmd file - -test join-1.1 "One name" { - file join abc -} {abc} - -test join-1.2 "One name with trailing slash" { - file join abc/ -} {abc} - -test join-1.3 "One name with leading slash" { - file join /abc -} {/abc} - -test join-1.4 "One name with leading and trailing slash" { - file join /abc/ -} {/abc} - -test join-1.5 "Two names" { - file join abc def -} {abc/def} - -test join-1.6 "Two names with dir trailing slash" { - file join abc/ def -} {abc/def} - -test join-1.7 "Two names with dir leading slash" { - file join /abc def -} {/abc/def} - -test join-1.8 "Two names with dir leading and trailing slash" { - file join /abc/ def -} {/abc/def} - -test join-1.9 "Two names with file trailing slash" { - file join abc def/ -} {abc/def} - -test join-1.10 "Two names with file leading slash" { - file join abc /def -} {/def} - -test join-1.11 "Two names with file leading and trailing slash" { - file join abc /def/ -} {/def} - -test join-1.12 "Two names with double slashes" { - file join abc/ /def -} {/def} - -test join-1.13 "Join to root" { - file join / abc -} {/abc} - -test join-1.14 "Join to root" { - set dir [file join / .] - # Either / or /. is OK here - expr {$dir in {/ /.}} -} 1 - -test join-1.15 "Join to root" { - file join / / -} {/} - -test join-1.16 "Join to root" { - file join /abc / -} {/} - -test join-2.1 "Dir is empty string" { - file join "" def -} {def} - -test join-2.2 "File is empty string" { - file join abc "" -} {abc} - -test join-2.3 "Path too long" jim { - set components [string repeat {abcdefghi } 500] - list [catch [concat file join $components] msg] $msg -} {1 {Path too long}} - -testreport |