Skip to content

Commit

Permalink
Add double quoted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Oct 18, 2024
1 parent 2325289 commit 8f9986a
Showing 1 changed file with 114 additions and 0 deletions.
114 changes: 114 additions & 0 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,116 +1080,230 @@ async fn variable_expansion() {
.run()
.await;

TestBuilder::new()
.command(r#"echo "${FOO:-5}""#)
.assert_stdout("5\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && echo ${FOO:-5}"#)
.assert_stdout("1\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && echo "${FOO:-5}""#)
.assert_stdout("1\n")
.run()
.await;

TestBuilder::new()
.command(r#"echo ${FOO:-${BAR:-5}}"#)
.assert_stdout("5\n")
.run()
.await;

TestBuilder::new()
.command(r#"echo "${FOO:-${BAR:-5}}""#)
.assert_stdout("5\n")
.run()
.await;

TestBuilder::new()
.command("BAR=2 && echo ${FOO:-${BAR:-5}}")
.assert_stdout("2\n")
.run()
.await;

TestBuilder::new()
.command(r#"BAR=2 && echo "${FOO:-${BAR:-5}}""#)
.assert_stdout("2\n")
.run()
.await;

TestBuilder::new()
.command("echo ${BAR:-THE VALUE CAN CONTAIN SPACES}")
.assert_stdout("THE VALUE CAN CONTAIN SPACES\n")
.run()
.await;

TestBuilder::new()
.command(r#"echo "${BAR:-THE VALUE CAN CONTAIN SPACES}""#)
.assert_stdout("THE VALUE CAN CONTAIN SPACES\n")
.run()
.await;

// ASSIGN DEFAULT EXPANSION
TestBuilder::new()
.command("echo ${FOO:=5} && echo $FOO")
.assert_stdout("5\n5\n")
.run()
.await;

TestBuilder::new()
.command(r#"echo "${FOO:=5}" && echo "$FOO""#)
.assert_stdout("5\n5\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && echo ${FOO:=5} && echo $FOO"#)
.assert_stdout("1\n1\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && echo "${FOO:=5}" && echo "$FOO""#)
.assert_stdout("1\n1\n")
.run()
.await;

TestBuilder::new()
.command(r#"echo ${FOO:=${BAR:=5}} && echo $FOO && echo $BAR"#)
.assert_stdout("5\n5\n5\n")
.run()
.await;

TestBuilder::new()
.command(r#"echo "${FOO:=${BAR:=5}}" && echo "$FOO" && echo "$BAR""#)
.assert_stdout("5\n5\n5\n")
.run()
.await;

// SUBSTRING VARIABLE EXPANSION
TestBuilder::new()
.command(r#"FOO=12345 && echo ${FOO:1:3}"#)
.assert_stdout("234\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo "${FOO:1:3}""#)
.assert_stdout("234\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo ${FOO:1}"#)
.assert_stdout("2345\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo "${FOO:1}""#)
.assert_stdout("2345\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo ${FOO:1:-1}"#)
.assert_stdout("234\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo "${FOO:1:-1}""#)
.assert_stdout("234\n")
.run()
.await;

// ALTERNATE VALUE EXPANSION
TestBuilder::new()
.command(r#"FOO=1 && echo ${FOO:+5}"#)
.assert_stdout("5\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && echo "${FOO:+5}""#)
.assert_stdout("5\n")
.run()
.await;

TestBuilder::new()
.command(r#"echo ${FOO:+5}"#)
.assert_stdout("\n")
.run()
.await;

TestBuilder::new()
.command(r#"echo "${FOO:+5}""#)
.assert_stdout("\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && echo ${FOO:+${BAR:+5}}"#)
.assert_stdout("\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && echo "${FOO:+${BAR:+5}}""#)
.assert_stdout("\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && BAR=2 && echo ${FOO:+${BAR:+5}}"#)
.assert_stdout("5\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=1 && BAR=2 && echo "${FOO:+${BAR:+5}}""#)
.assert_stdout("5\n")
.run()
.await;

TestBuilder::new()
.command("FOO=12345 && echo ${FOO:2:$((2+2))}")
.assert_stdout("345\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo "${FOO:2:$((2+2))}""#)
.assert_stdout("345\n")
.run()
.await;

TestBuilder::new()
.command("FOO=12345 && echo ${FOO: -2:-1}")
.assert_stdout("4\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo "${FOO: -2:-1}""#)
.assert_stdout("4\n")
.run()
.await;

TestBuilder::new()
.command("FOO=12345 && echo ${FOO: -2}")
.assert_stdout("45\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo "${FOO: -2}""#)
.assert_stdout("45\n")
.run()
.await;

TestBuilder::new()
.command("FOO=12345 && echo ${FOO: -4: 2}")
.assert_stdout("23\n")
.run()
.await;

TestBuilder::new()
.command(r#"FOO=12345 && echo "${FOO: -4: 2}""#)
.assert_stdout("23\n")
.run()
.await;
}

#[cfg(test)]
Expand Down

0 comments on commit 8f9986a

Please sign in to comment.