commit: d25112bfeffcb4d0a2fbc3f3fb2bb6ca6e21fcc4
parent a684ae14e6f69ad53bd11f5a4ff84a816bccf047
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 14 Mar 2024 19:31:08 +0100
cmd/seq: Only use custom separator between numbers
Diffstat:
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/cmd/seq.c b/cmd/seq.c
@@ -19,17 +19,21 @@ seq(long i, unsigned long step, long last)
{
if(i == last)
{
- printf("%li%s", i, separator);
+ printf("%li\n", i);
}
else if(i < last)
{
- for(; i <= last; i += step)
+ for(; i < last; i += step)
printf("%li%s", i, separator);
+
+ if(i <= last) printf("%li\n", i);
}
else if(i > last)
{
- for(; i >= last; i -= step)
+ for(; i > last; i -= step)
printf("%li%s", i, separator);
+
+ if(i >= last) printf("%li\n", i);
}
}
diff --git a/test-cmd/seq b/test-cmd/seq
@@ -43,6 +43,11 @@ three_body() {
atf_check -o "inline:-10\n-12\n-14\n" -- ../cmd/seq -- -10 2 -15
}
+atf_test_case sep
+sep_body() {
+ atf_check -o "inline:1-2-3\n" ../cmd/seq -s - 3
+}
+
atf_test_case noarg
noarg_body() {
atf_check -s exit:1 -e 'inline:usage: seq [-w] [-s separator] [first [step]] last\n' ../cmd/seq
@@ -69,6 +74,8 @@ atf_init_test_cases() {
atf_add_test_case two
atf_add_test_case three
+ atf_add_test_case sep
+
atf_add_test_case noarg
atf_add_test_case badflag
#atf_add_test_case limits