aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-07 04:59:37 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-07 04:59:37 +0100
commit026f5b8786fece894ab1357747627b180db5a0ee (patch)
treeb1df27cc66770af0bf107f89471681d0481877ad /test
parent805d47c4b5db311601f499732e9492341cdd270c (diff)
chore: interpolate named variables
Diffstat (limited to 'test')
-rw-r--r--test/Main.hs26
1 files changed, 12 insertions, 14 deletions
diff --git a/test/Main.hs b/test/Main.hs
index ad69469..9bde55e 100644
--- a/test/Main.hs
+++ b/test/Main.hs
@@ -31,27 +31,25 @@ main = hspec do
|]
describe "arguments" do
it "passes `Int`" do
- (`shouldBe` "1") =<< [sh|echo -n %|] (1 :: Int)
+ (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo -n '#{x}'|]
it "passes `Text`" do
- (`shouldBe` "foobar") =<< [sh|echo -n %|] (T.pack "foobar")
- (`shouldBe` "foobar") =<< [sh|echo -n %|] (LT.pack "foobar")
+ (`shouldBe` "foobar") =<< let x = T.pack "foobar" in [sh|echo -n '#{x}'|]
+ (`shouldBe` "foobar") =<< let x = LT.pack "foobar" in [sh|echo -n '#{x}'|]
it "passes `ByteString`" do
- (`shouldBe` "foobar") =<< [sh|echo -n %|] (B.pack "foobar")
- (`shouldBe` "foobar") =<< [sh|echo -n %|] (LB.pack "foobar")
+ (`shouldBe` "foobar") =<< let x = B.pack "foobar" in [sh|echo -n '#{x}'|]
+ (`shouldBe` "foobar") =<< let x = LB.pack "foobar" in [sh|echo -n '#{x}'|]
+ it "interpolates expressions" do
+ (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo -n '#{show x}'|]
describe "quoting" do
it "preserves arguments" do
(`shouldBe` "foo\\ bar")
- =<< [sh|printf %%q %|] "foo bar"
+ =<< let x = "foo bar" in [sh|printf %q '#{x}'|]
it "preserves special characters" do
(`shouldBe` "foo\\ bar")
- =<< [sh|foo=foo; bar=bar; ( printf %%q % )|] "$foo $bar"
+ =<< let x = "$foo $bar" in [sh|foo=foo; bar=bar; ( printf %q #{x} )|]
it "escapes special characters" do
(`shouldBe` "\\$foo\\ \\$bar")
- =<< [sh|printf %%q '%'|] "$foo $bar"
+ =<< let x = "$foo $bar" in [sh|foo=foo; bar=bar; ( printf %q '#{x}' )|]
it "preserves empty arguments" do
- (`shouldBe` "''") =<< [sh|printf %%q %|] ""
- (`shouldBe` "''") =<< [sh|printf %%q '%'|] ""
- describe "parsing" do
- it "parses garbled arguments" do
- (`shouldBe` "% foo") =<< [sh|echo -n '% ' %|] "foo"
- (`shouldBe` " foo") =<< [sh|echo -n ' ' %|] "foo"
+ (`shouldBe` "''") =<< let x = "" in [sh|printf %q #{x}|]
+ (`shouldBe` "''") =<< let x = "" in [sh|printf %q '#{x}'|]