-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4168 from johnmendonca/4039-pt2-template-name-spec
Issue #4039 - Spec for template name parsing in `stack new`
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|