Skip to content

Commit

Permalink
Merge pull request #4168 from johnmendonca/4039-pt2-template-name-spec
Browse files Browse the repository at this point in the history
Issue #4039 - Spec for template name parsing in `stack new`
  • Loading branch information
mihaimaruseac committed Jul 29, 2018
2 parents d3577c4 + 19bcca9 commit f110618
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/test/Stack/Types/TemplateNameSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{-# LANGUAGE OverloadedStrings #-}

module Stack.Types.TemplateNameSpec where

import Stack.Types.TemplateName
import Path.Internal
import System.Info (os)
import Test.Hspec

spec :: Spec
spec =
describe "TemplateName" $ do
describe "parseTemplateNameFromString" $ do
let pathOf s = either error templatePath (parseTemplateNameFromString s)

it "parses out the TemplatePath" $ do
pathOf "github:user/name" `shouldBe` (RepoPath $ RepoTemplatePath Github "user" "name.hsfiles")
pathOf "bitbucket:user/name" `shouldBe` (RepoPath $ RepoTemplatePath Bitbucket "user" "name.hsfiles")
pathOf "gitlab:user/name" `shouldBe` (RepoPath $ RepoTemplatePath Gitlab "user" "name.hsfiles")

pathOf "http://www.com/file" `shouldBe` UrlPath "http://www.com/file"
pathOf "https://www.com/file" `shouldBe` UrlPath "https://www.com/file"

pathOf "name" `shouldBe` (RelPath $ Path "name.hsfiles")
pathOf "name.hsfile" `shouldBe` (RelPath $ Path "name.hsfile.hsfiles")
pathOf "name.hsfiles" `shouldBe` (RelPath $ Path "name.hsfiles")
pathOf "" `shouldBe` (RelPath $ Path ".hsfiles")

if os == "mingw32"
then do
pathOf "//home/file" `shouldBe` (AbsPath $ Path "\\\\home\\file.hsfiles")
pathOf "/home/file" `shouldBe` (RelPath $ Path "\\home\\file.hsfiles")
pathOf "/home/file.hsfiles" `shouldBe` (RelPath $ Path "\\home\\file.hsfiles")

pathOf "c:\\home\\file" `shouldBe` (AbsPath $ Path "C:\\home\\file.hsfiles")
pathOf "with/slash" `shouldBe` (RelPath $ Path "with\\slash.hsfiles")

let colonAction =
do
return $! pathOf "with:colon"
colonAction `shouldThrow` anyErrorCall

else do
pathOf "//home/file" `shouldBe` (AbsPath $ Path "/home/file.hsfiles")
pathOf "/home/file" `shouldBe` (AbsPath $ Path "/home/file.hsfiles")
pathOf "/home/file.hsfiles" `shouldBe` (AbsPath $ Path "/home/file.hsfiles")

pathOf "c:\\home\\file" `shouldBe` (RelPath $ Path "c:\\home\\file.hsfiles")
pathOf "with/slash" `shouldBe` (RelPath $ Path "with/slash.hsfiles")
pathOf "with:colon" `shouldBe` (RelPath $ Path "with:colon.hsfiles")

0 comments on commit f110618

Please sign in to comment.