module Main where

import           Test.Hspec
import           Hackonad.LineParser

main :: IO ()
main = hspec $ do
  describe "Hackonad" $ do
    context "Input line" $ do
      it "Empty line" $ do
        parseInputLine "" `shouldBe` ("", [])
      it "Plain command name" $ do
        parseInputLine "ls" `shouldBe` ("ls", [])
      it "Common args" $ do
        parseInputLine "ls -l ~" `shouldBe` ("ls", ["-l", "~"])
    context "Parse input" $ do
      it "Arg contans a space" $ do
        parseCommandLine "ls One\\ Two" `shouldBe`
          [
            Command (Raw "ls") [
              Raw "One Two"
            ]
          ]
      it "separated with semicolon" $ do
        parseCommandLine "mkdir 1; cd 1" `shouldBe`
          [
            Command (Raw "mkdir") [
              Raw "1"
            ],
            Command (Raw "cd") [
              Raw "1"
            ]
         ]
      it "Nested $(command) block" $ do
        parseCommandLine "echo hello1-$(echo hello2-$(echo hello3-$(echo hello4)))" `shouldBe`
          [
            Command (Raw "echo") [
              Arg [
                Raw "hello1-",
                Command (Raw "echo") [
                  Arg [
                    Raw "hello2-",
                    Command (Raw "echo") [
                      Arg [
                        Raw "hello3-",
                        Command (Raw "echo") [
                          Raw "hello4"
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ]
          ]
