ghc-mod/test/ShellParseSpec.hs

35 lines
1.3 KiB
Haskell
Raw Normal View History

module ShellParseSpec where
2015-12-20 03:05:43 +00:00
import GHCMod.Options.ShellParse
2015-12-20 03:05:43 +00:00
import Test.Hspec
spec :: Spec
spec =
describe "parseCmdLine" $ do
it "splits arguments" $ do
2015-12-20 03:05:43 +00:00
parseCmdLine "test command line" `shouldBe` ["test", "command", "line"]
parseCmdLine "ascii-escape test command line" `shouldBe` ["test", "command", "line"]
it "honors quoted segments if turned on" $
parseCmdLine "ascii-escape test command line \STXwith quoted segment\ETX"
`shouldBe` ["test", "command", "line", "with quoted segment"]
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"]
parseCmdLine "ascii-escape test command"
`shouldBe` ["test", "command"]
it "ingores leading spaces" $ do
parseCmdLine " test command"
`shouldBe` ["test", "command"]
parseCmdLine " ascii-escape test command"
`shouldBe` ["test", "command"]
it "parses empty string as no argument" $ do
parseCmdLine ""
`shouldBe` [""]
parseCmdLine "ascii-escape "
`shouldBe` [""]