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 = renderDownloadWithVersion (DownloadTemplate components) version =
URI.mkURI $ foldr f "" components URI.mkURI $ foldr f "" components
where where
f (StaticPlaceholder staticPlaceholder) accumulator = accumulator <> staticPlaceholder f (StaticPlaceholder staticPlaceholder) = (staticPlaceholder <>)
f VersionPlaceholder accumulator = accumulator <> version f VersionPlaceholder = (version <>)
-- | Function used to get the latest version of a source. -- | Function used to get the latest version of a source.
data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate

View File

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

View File

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