yagcdn/frontend/tests/ParseTest.elm

154 lines
4.6 KiB
Elm
Raw Normal View History

2019-07-27 16:24:13 +02:00
module ParseTest exposing
2019-08-12 19:09:54 +02:00
( emptyBranchGitHub
, emptyRepoGitHub
, emptyUserGitHub
, invalidHostInUrlBitbucket
2019-07-27 16:24:13 +02:00
, invalidHostInUrlGitHub
2019-07-28 17:32:50 +02:00
, invalidHostInUrlGitLab
2019-07-27 16:24:13 +02:00
, invalidUrlBitbucket
, invalidUrlGitHub
2019-07-28 17:32:50 +02:00
, invalidUrlGitLab
2019-07-27 16:24:13 +02:00
, validHttpUrlBitbucket
, validHttpUrlGitHub
2019-07-28 17:32:50 +02:00
, validHttpUrlGitLab
2019-07-27 16:24:13 +02:00
, validHttpsUrlBitbucket
, validHttpsUrlGitHub
2019-07-28 17:32:50 +02:00
, validHttpsUrlGitLab
2019-07-27 16:24:13 +02:00
, validUrlWithoutProtocolBitbucket
, validUrlWithoutProtocolGitHub
2019-07-28 17:32:50 +02:00
, validUrlWithoutProtocolGitLab
2019-07-27 16:24:13 +02:00
)
import Data exposing (Provider(..), Url)
import Expect
import Parse exposing (parseUrl)
import Test exposing (Test, test)
expectedUrl : Provider -> Url
expectedUrl prov =
{ prov = prov, user = "user", repo = "repo", gitref = "master", file = "README.md" }
expectedGitHubUrl : Url
expectedGitHubUrl =
expectedUrl GitHub
expectedBitbucketUrl : Url
expectedBitbucketUrl =
expectedUrl Bitbucket
2019-07-28 17:32:50 +02:00
expectedGitLabUrl : Url
expectedGitLabUrl =
expectedUrl GitLab
2019-07-27 16:24:13 +02:00
validHttpsUrlGitHub : Test
validHttpsUrlGitHub =
test "Parsing Valid HTTPS URL for GitHub"
(\_ -> Expect.equal (Just expectedGitHubUrl) (parseUrl "https://GiThUb.CoM/user/repo/blob/master/README.md"))
validHttpUrlGitHub : Test
validHttpUrlGitHub =
test "Parsing Valid HTTP URL for GitHub"
(\_ -> Expect.equal (Just expectedGitHubUrl) (parseUrl "http://GiThUb.CoM/user/repo/blob/master/README.md"))
validUrlWithoutProtocolGitHub : Test
validUrlWithoutProtocolGitHub =
test "Parsing Valid URL without Protocol for GitHub"
(\_ -> Expect.equal (Just expectedGitHubUrl) (parseUrl "GiThUb.CoM/user/repo/blob/master/README.md"))
invalidUrlGitHub : Test
invalidUrlGitHub =
test "Parsing Invalid URL for GitHub"
(\_ -> Expect.equal Nothing (parseUrl "https://GiThUb.CoM/user"))
2019-08-12 19:09:54 +02:00
emptyUserGitHub : Test
emptyUserGitHub =
test "Parsing Empty User URL for GitHub"
(\_ -> Expect.equal Nothing (parseUrl "https://GiThUb.CoM//repo/blob/master/README.md"))
emptyRepoGitHub : Test
emptyRepoGitHub =
test "Parsing Empty Repo URL for GitHub"
(\_ -> Expect.equal Nothing (parseUrl "https://GiThUb.CoM/user//blob/master/README.md"))
emptyBranchGitHub : Test
emptyBranchGitHub =
test "Parsing Empty Branch URL for GitHub"
(\_ -> Expect.equal Nothing (parseUrl "https://GiThUb.CoM/user/repo/blob//README.md"))
2019-07-27 16:24:13 +02:00
invalidHostInUrlGitHub : Test
invalidHostInUrlGitHub =
test "Parsing Invalid Host in URL for GitHub"
(\_ -> Expect.equal Nothing (parseUrl "https://example.com/user/repo/blob/master/README.md"))
validHttpsUrlBitbucket : Test
validHttpsUrlBitbucket =
test "Parsing Valid HTTPS URL for Bitbucket"
(\_ -> Expect.equal (Just expectedBitbucketUrl) (parseUrl "https://bItBuCkEt.OrG/user/repo/src/master/README.md"))
validHttpUrlBitbucket : Test
validHttpUrlBitbucket =
test "Parsing Valid HTTP URL for Bitbucket"
(\_ -> Expect.equal (Just expectedBitbucketUrl) (parseUrl "http://BiTbUcKeT.oRg/user/repo/src/master/README.md"))
validUrlWithoutProtocolBitbucket : Test
validUrlWithoutProtocolBitbucket =
test "Parsing Valid URL without Protocol for Bitbucket"
(\_ -> Expect.equal (Just expectedBitbucketUrl) (parseUrl "bitbucket.org/user/repo/src/master/README.md"))
invalidUrlBitbucket : Test
invalidUrlBitbucket =
test "Parsing Invalid URL for Bitbucket"
(\_ -> Expect.equal Nothing (parseUrl "https://bitBucket.ORG/user"))
invalidHostInUrlBitbucket : Test
invalidHostInUrlBitbucket =
test "Parsing Invalid Host in URL for Bitbucket"
(\_ -> Expect.equal Nothing (parseUrl "https://example.com/user/repo/blob/src/README.md"))
2019-07-28 17:32:50 +02:00
validHttpsUrlGitLab : Test
validHttpsUrlGitLab =
test "Parsing Valid HTTPS URL for GitLab"
(\_ -> Expect.equal (Just expectedGitLabUrl) (parseUrl "https://GITLAB.CoM/user/repo/blob/master/README.md"))
validHttpUrlGitLab : Test
validHttpUrlGitLab =
test "Parsing Valid HTTP URL for GitLab"
(\_ -> Expect.equal (Just expectedGitLabUrl) (parseUrl "http://gItLaB.CoM/user/repo/blob/master/README.md"))
validUrlWithoutProtocolGitLab : Test
validUrlWithoutProtocolGitLab =
test "Parsing Valid URL without Protocol for GitLab"
(\_ -> Expect.equal (Just expectedGitLabUrl) (parseUrl "GiTlAb.CoM/user/repo/blob/master/README.md"))
invalidUrlGitLab : Test
invalidUrlGitLab =
test "Parsing Invalid URL for GitLab"
(\_ -> Expect.equal Nothing (parseUrl "https://gitLab.CoM/user"))
invalidHostInUrlGitLab : Test
invalidHostInUrlGitLab =
test "Parsing Invalid Host in URL for GitLab"
(\_ -> Expect.equal Nothing (parseUrl "https://example.com/user/repo/blob/master/README.md"))