aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorElie De Brauwer <eliedebrauwer@gmail.com>2012-02-12 14:14:58 +0100
committerElie De Brauwer <eliedebrauwer@gmail.com>2012-02-12 14:14:58 +0100
commit528e3ba874f0d89f5a4d1f8ce8c04adbaa2ec1e4 (patch)
tree456c2a52361df5944bbe58a9a3121852e9d6e2a0 /scripts
parent2bd3a5df73723ef3aa274aab2d18de0ad9b31e25 (diff)
downloadtoybox-528e3ba874f0d89f5a4d1f8ce8c04adbaa2ec1e4.tar.gz
Add test for basename, fix issue where suffix is wrongfully applied if it appears in the middle of the filename
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/test/basename.test23
1 files changed, 23 insertions, 0 deletions
diff --git a/scripts/test/basename.test b/scripts/test/basename.test
new file mode 100755
index 00000000..e0288ce1
--- /dev/null
+++ b/scripts/test/basename.test
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+# Removal of extra /'s
+testing "basename /-only" "basename ///////" "/\n" "" ""
+testing "basename trailing /" "basename a//////" "a\n" "" ""
+testing "basename combined" "basename /////a///b///c///d/////" "d\n" "" ""
+
+# Standard suffix behavior.
+testing "basename suffix" "basename a/b/c/d.suffix .suffix" "d\n" "" ""
+
+# A suffix cannot be the entire result.
+testing "basename suffix=result" "basename .txt .txt" ".txt\n" "" ""
+
+# Deal with suffix appearing in the filename
+testing "basename reappering suffix 1" "basename a.txt.txt .txt" "a.txt\n" "" ""
+testing "basename reappering suffix 2" "basename a.txt.old .txt" "a.txt.old\n" "" ""
+
+# A suffix should be a real suffix, only a the end.
+testing "basename invalid suffix" "basename isthisasuffix? suffix" "isthisasuffix?\n" "" "" \ No newline at end of file