Fix renderDownloadWithVersion concatenation order

This commit is contained in:
Eugen Wissner 2023-09-22 07:47:46 +02:00
parent 840290491f
commit ec704e267b
3 changed files with 18 additions and 4 deletions

View File

@ -68,8 +68,8 @@ renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI
renderDownloadWithVersion (DownloadTemplate components) version =
URI.mkURI $ foldr f "" components
where
f (StaticPlaceholder staticPlaceholder) accumulator = accumulator <> staticPlaceholder
f VersionPlaceholder accumulator = accumulator <> version
f (StaticPlaceholder staticPlaceholder) = (staticPlaceholder <>)
f VersionPlaceholder = (version <>)
-- | Function used to get the latest version of a source.
data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate

View File

@ -16,7 +16,6 @@ category: Build
extra-source-files: CHANGELOG.md
common dependencies
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
build-depends:
base ^>= 4.16.4.0,
cryptonite >= 0.30,
@ -47,6 +46,8 @@ library slackbuilder-internal
tomland ^>= 1.3.3,
transformers ^>= 0.5.6
ghc-options: -Wall
executable slackbuilder
import: dependencies
main-is: Main.hs
@ -67,6 +68,8 @@ executable slackbuilder
vector ^>= 0.13.0
hs-source-dirs: app
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
test-suite slackbuilder-test
import: dependencies
type: exitcode-stdio-1.0
@ -78,3 +81,5 @@ test-suite slackbuilder-test
build-depends:
hspec >= 2.10.9 && < 2.12,
slackbuilder-internal
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall

View File

@ -2,13 +2,14 @@ module SlackBuilder.PackageSpec
( spec
) where
import Data.List.NonEmpty (NonEmpty(..))
import SlackBuilder.Package
import Test.Hspec (Spec, describe, it, shouldBe)
import Text.URI.QQ (uri)
spec :: Spec
spec = do
describe "renderDownloadWithVersion" $
describe "renderDownloadWithVersion" $ do
it "renders text as URL" $
let given = DownloadTemplate
$ pure
@ -16,3 +17,11 @@ spec = do
actual = renderDownloadWithVersion given "1.2"
expected = Just [uri|https://example.com|]
in actual `shouldBe` expected
it "renders the components in order" $
let given = DownloadTemplate
$ StaticPlaceholder "https://example.com/"
:| [VersionPlaceholder, StaticPlaceholder "/segment"]
actual = renderDownloadWithVersion given "1.2"
expected = Just [uri|https://example.com/1.2/segment|]
in actual `shouldBe` expected