Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/runtime/shell/builtin/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ impl Seq {
idx += 1;
continue;
}
if arg.starts_with(b"-s") && arg.len() > 2 {
Self::state_mut(interp, cmd).separator = bun_ptr::RawSlice::new(&arg[2..]);
if let Some(bytes) = arg
.strip_prefix(b"-s")
.or_else(|| arg.strip_prefix(b"--separator="))
{
Self::state_mut(interp, cmd).separator = bun_ptr::RawSlice::new(bytes);
idx += 1;
continue;
}
Expand All @@ -75,8 +78,11 @@ impl Seq {
idx += 1;
continue;
}
if arg.starts_with(b"-t") && arg.len() > 2 {
Self::state_mut(interp, cmd).terminator = bun_ptr::RawSlice::new(&arg[2..]);
if let Some(bytes) = arg
.strip_prefix(b"-t")
.or_else(|| arg.strip_prefix(b"--terminator="))
{
Self::state_mut(interp, cmd).terminator = bun_ptr::RawSlice::new(bytes);
idx += 1;
continue;
}
Expand Down
48 changes: 48 additions & 0 deletions test/js/bun/shell/commands/seq.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ describe("seq", async () => {
.stderr("")
.runAsTest("--separator works");

TestBuilder.command`seq --separator=, 0 5`
.exitCode(0)
.stdout("0,1,2,3,4,5,")
.stderr("")
.runAsTest("--separator=value works");

TestBuilder.command`seq --separator= 0 5`
.exitCode(0)
.stdout("012345")
.stderr("")
.runAsTest("--separator= sets an empty separator");

TestBuilder.command`seq --separator=a=b 0 2`
.exitCode(0)
.stdout("0a=b1a=b2a=b")
.stderr("")
.runAsTest("--separator=value splits at the first = only");

TestBuilder.command`seq --separator, 0 5`
.exitCode(1)
.stdout("")
.stderr("seq: invalid argument\n")
.runAsTest("--separator needs = before an attached value");

TestBuilder.command`seq -t, 0 5`.exitCode(0).stdout("0\n1\n2\n3\n4\n5\n,").stderr("").runAsTest("-t works inline");

TestBuilder.command`seq -t , 0 5`.exitCode(0).stdout("0\n1\n2\n3\n4\n5\n,").stderr("").runAsTest("-t works separate");
Expand All @@ -76,12 +100,36 @@ describe("seq", async () => {
.stderr("")
.runAsTest("--terminator works");

TestBuilder.command`seq --terminator=, 0 5`
.exitCode(0)
.stdout("0\n1\n2\n3\n4\n5\n,")
.stderr("")
.runAsTest("--terminator=value works");

TestBuilder.command`seq --terminator= 0 2`
.exitCode(0)
.stdout("0\n1\n2\n")
.stderr("")
.runAsTest("--terminator= sets an empty terminator");

TestBuilder.command`seq --terminator, 0 5`
.exitCode(1)
.stdout("")
.stderr("seq: invalid argument\n")
.runAsTest("--terminator needs = before an attached value");

TestBuilder.command`seq -s. -t, 0 5`
.exitCode(0)
.stdout("0.1.2.3.4.5.,")
.stderr("")
.runAsTest("-s and -t work together");

TestBuilder.command`seq --separator=. --terminator=, 0 5`
.exitCode(0)
.stdout("0.1.2.3.4.5.,")
.stderr("")
.runAsTest("--separator=value and --terminator=value work together");

TestBuilder.command`seq 0`.exitCode(0).stdout("1\n0\n").stderr("").runAsTest("seq 0");

TestBuilder.command`seq 1`.exitCode(0).stdout("1\n").stderr("").runAsTest("seq 1");
Expand Down
Loading