commit: 30dd6d7f1a15dc8e10f514d92421ae1c041cd28c
parent 730f9471a08eb080b7972d07562fa6173d14c84e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 24 Aug 2024 05:42:23 +0200
cmd/cut: fix -high support
Diffstat:
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/cmd/cut.c b/cmd/cut.c
@@ -76,8 +76,12 @@ parse_list(char *s)
return -1;
}
- ssize_t min = parse_list_num(&s);
- if(min < 0) return -1;
+ ssize_t min = 1;
+ if(*s != '-')
+ {
+ min = parse_list_num(&s);
+ if(min < 0) return -1;
+ }
// min-- as cut(1) is 1-indexed and max needs to be at least min+1
ssize_t max = min--;
diff --git a/test-cmd/cut.sh b/test-cmd/cut.sh
@@ -4,7 +4,7 @@
WD="$(dirname "$0")/../"
target="${WD}/cmd/cut"
-plans=9
+plans=12
. "${WD}/test-cmd/tap.sh"
. "${WD}/test-cmd/init_env.sh"
@@ -12,6 +12,8 @@ t 'bytes:2-3,10-20,4,12' "-b 2-3,10-20,4,12 ${WD}/test-cmd/inputs/alnum" '1239AB
'
t 'bytes:11-' "-b 11- ${WD}/test-cmd/inputs/alnum" 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
'
+t 'bytes:-10' "-b -10 ${WD}/test-cmd/inputs/alnum" '0123456789
+'
t --exit=1 'bytes:,' "-b , ${WD}/test-cmd/inputs/alnum" 'cut: Error: empty list element
'
# Example taken from POSIX cut(1)
@@ -20,6 +22,8 @@ t --input='abcdefghi' 'chars:6,2,4-7,1' '-c 6,2,4-7,1' 'abdefg
t 'chars:11-' "-c 11- ${WD}/test-cmd/inputs/alnum" 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
'
+t 'chars:-10' "-c -10 ${WD}/test-cmd/inputs/alnum" '0123456789
+'
t --input='aéb' 'widechar' '-c2' 'é
'
@@ -41,3 +45,7 @@ t --input="$fields" f2- '-f2-' '2 3 4
b c
'
+t --input="$fields" f-2 '-f-2' '1 2
+
+a b
+'