2015-12-20 05:26:49 +00:00
|
|
|
module ShellParseSpec where
|
2015-12-20 03:05:43 +00:00
|
|
|
|
|
|
|
|
2017-05-28 02:22:56 +00:00
|
|
|
import GhcMod.Exe.Options.ShellParse
|
2015-12-20 03:05:43 +00:00
|
|
|
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec =
|
|
|
|
describe "parseCmdLine" $ do
|
2015-12-30 17:46:06 +00:00
|
|
|
it "splits arguments" $ do
|
2015-12-20 03:05:43 +00:00
|
|
|
parseCmdLine "test command line" `shouldBe` ["test", "command", "line"]
|
2015-12-30 18:11:39 +00:00
|
|
|
parseCmdLine "ascii-escape test command line" `shouldBe` ["test", "command", "line"]
|
2015-12-30 17:46:06 +00:00
|
|
|
it "honors quoted segments if turned on" $
|
2015-12-30 18:11:39 +00:00
|
|
|
parseCmdLine "ascii-escape test command line \STXwith quoted segment\ETX"
|
2015-12-26 23:42:45 +00:00
|
|
|
`shouldBe` ["test", "command", "line", "with quoted segment"]
|
2015-12-30 17:46:06 +00:00
|
|
|
it "doesn't honor quoted segments if turned off" $
|
|
|
|
parseCmdLine "test command line \STXwith quoted segment\ETX"
|
|
|
|
`shouldBe` words "test command line \STXwith quoted segment\ETX"
|
|
|
|
it "squashes multiple spaces" $ do
|
2015-12-20 03:05:43 +00:00
|
|
|
parseCmdLine "test command"
|
|
|
|
`shouldBe` ["test", "command"]
|
2015-12-30 18:11:39 +00:00
|
|
|
parseCmdLine "ascii-escape test command"
|
|
|
|
`shouldBe` ["test", "command"]
|
|
|
|
it "ingores leading spaces" $ do
|
|
|
|
parseCmdLine " test command"
|
|
|
|
`shouldBe` ["test", "command"]
|
|
|
|
parseCmdLine " ascii-escape test command"
|
2015-12-30 17:46:06 +00:00
|
|
|
`shouldBe` ["test", "command"]
|
2015-12-30 18:18:57 +00:00
|
|
|
it "parses empty string as no argument" $ do
|
|
|
|
parseCmdLine ""
|
|
|
|
`shouldBe` [""]
|
|
|
|
parseCmdLine "ascii-escape "
|
|
|
|
`shouldBe` [""]
|