2024-03-19 11:34:19 +01:00
|
|
|
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
|
|
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
|
|
obtain one at https://mozilla.org/MPL/2.0/. -}
|
|
|
|
|
|
|
|
module SlackBuilder.LatestVersionCheckSpec
|
|
|
|
( spec
|
|
|
|
) where
|
|
|
|
|
|
|
|
import SlackBuilder.LatestVersionCheck
|
|
|
|
import Test.Hspec (Spec, describe, it, shouldBe)
|
|
|
|
|
|
|
|
spec :: Spec
|
|
|
|
spec = do
|
2024-03-21 17:52:37 +01:00
|
|
|
describe "match" $ do
|
2024-03-24 13:20:22 +01:00
|
|
|
it "matches an exact tag prefixed with v" $
|
2024-03-21 17:52:37 +01:00
|
|
|
let expected = Just "2.6.0"
|
|
|
|
actual = match "(v)2.6.0" "v2.6.0"
|
|
|
|
in actual `shouldBe` expected
|
|
|
|
|
2024-03-24 13:20:22 +01:00
|
|
|
it "matches a glob pattern prefixed with v" $
|
2024-03-21 17:52:37 +01:00
|
|
|
let expected = Just "2.6.0"
|
|
|
|
actual = match "(v)*" "v2.6.0"
|
|
|
|
in actual `shouldBe` expected
|
|
|
|
|
2024-03-24 13:20:22 +01:00
|
|
|
it "matches digits" $
|
|
|
|
let expected = Just "2.6.0"
|
|
|
|
actual = match "(v)2.6.\\d" "v2.6.0"
|
|
|
|
in actual `shouldBe` expected
|
|
|
|
|
2024-09-13 21:58:13 +02:00
|
|
|
it "matches digits and dots" $
|
2024-03-21 17:52:37 +01:00
|
|
|
let expected = Just "2.6.0"
|
2024-03-24 13:20:22 +01:00
|
|
|
actual = match "(v)\\." "v2.6.0"
|
|
|
|
in actual `shouldBe` expected
|
|
|
|
|
|
|
|
it "rejects unexpected suffix" $
|
|
|
|
let expected = Nothing
|
|
|
|
actual = match "(v)\\." "v2.6.0-rc1"
|
|
|
|
in actual `shouldBe` expected
|
|
|
|
|
|
|
|
it "rejects remaining umatched characters" $
|
|
|
|
let expected = Nothing
|
|
|
|
actual = match "2.6.0-rc1" "2.6.0"
|
2024-03-21 17:52:37 +01:00
|
|
|
in actual `shouldBe` expected
|
2024-09-10 11:33:31 +02:00
|
|
|
|
|
|
|
it "consumes the last token matching nothing" $
|
|
|
|
let expected = Just "abc"
|
|
|
|
actual = match "abc\\d\\d" "abc"
|
|
|
|
in actual `shouldBe` expected
|
2024-09-13 21:58:13 +02:00
|
|
|
|
|
|
|
it "matches at least one digit" $
|
|
|
|
let expected = Nothing
|
|
|
|
actual = match "1.\\D.3" "1..3"
|
|
|
|
in actual `shouldBe` expected
|