From 026f5b8786fece894ab1357747627b180db5a0ee Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 7 Mar 2024 04:59:37 +0100 Subject: chore: interpolate named variables --- test/Main.hs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'test') 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}'|] -- cgit v1.2.3