Skip to content

Commit

Permalink
Remove query parameters from repo name parsed from binary Cartfile en…
Browse files Browse the repository at this point in the history
…try (#222)

* Remove query parameters from binary Cartfile entry

* Add test for gitRepoNameFromCartfileEntry

Co-authored-by: Tommaso Piazza <196761+tmspzz@users.noreply.github.com>
  • Loading branch information
ffittschen and tmspzz committed Apr 29, 2020
1 parent 6f4a08c commit 4584974
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ gitRepoNameFromCartfileEntry (CartfileEntry GitHub (Location l) _) =
gitRepoNameFromCartfileEntry (CartfileEntry Git (Location l) _) =
ProjectName . T.unpack . T.replace ".git" "" . last . splitWithSeparator '/' . T.pack $ l
gitRepoNameFromCartfileEntry (CartfileEntry Binary (Location l) _) =
ProjectName . T.unpack . T.replace ".json" "" . last . splitWithSeparator '/' . T.pack $ l
ProjectName . T.unpack . head . T.splitOn ".json" . last . splitWithSeparator '/' . T.pack $ l



Expand Down
15 changes: 15 additions & 0 deletions tests/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Data.Either ( rights )
import Data.List ( intercalate
, nub
, intersect
, isInfixOf
)
import Data.Yaml ( decodeEither'
, encode
Expand Down Expand Up @@ -148,6 +149,17 @@ prop_filterRomeFileEntriesByPlatforms_min :: [RomefileEntry] -> [RomefileEntry]
prop_filterRomeFileEntriesByPlatforms_min base filteringValues =
(length $ base `filterRomeFileEntriesByPlatforms` filteringValues) <= length base

binaryURLPathWithParameters :: Gen String
binaryURLPathWithParameters = do
firstPart <- arbitrary
secondPart <- arbitrary
lastPart <- arbitrary `suchThat` (\a -> not $ "/" `isInfixOf` a || ".json" `isInfixOf` a)
return $ "https://" ++ firstPart ++ "/" ++ secondPart ++ "/" ++ "binary.json?some_paramter=test&" ++ lastPart

prop_gitRepoNameFromCartfileEntry_alaways_binary :: String -> Bool
prop_gitRepoNameFromCartfileEntry_alaways_binary url =
gitRepoNameFromCartfileEntry (CartfileEntry Binary (Location url) (Version "")) == ProjectName "binary"

main :: IO ()
main = do

Expand Down Expand Up @@ -189,3 +201,6 @@ main = do

putStrLn "prop_filterRomeFileEntriesByPlatforms_filters"
quickCheck (withMaxSuccess 1000 prop_filterRomeFileEntriesByPlatforms_filters)

putStrLn "prop_gitRepoNameFromCartfileEntry_alaways_binary"
quickCheck (withMaxSuccess 1000 $ forAll binaryURLPathWithParameters prop_gitRepoNameFromCartfileEntry_alaways_binary)

0 comments on commit 4584974

Please sign in to comment.