Skip to content

Commit

Permalink
some test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
hojberg committed Aug 7, 2023
1 parent 6721e5f commit 421d85a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Code/BranchRef.elm
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ branchSlugFromString raw =
Nothing


{-| Don't use outside of testing
{-| ⚠️ Don't use outside of testing
-}
unsafeBranchSlugFromString : String -> BranchSlug
unsafeBranchSlugFromString raw =
Expand All @@ -204,6 +204,30 @@ branchSlugToString (BranchSlug s) =
s


{-| ⚠️ Don't use outside of testing
-}
unsafeFromString : String -> BranchRef
unsafeFromString raw =
let
parts =
String.split "/" raw
in
case parts of
[ "releases", "drafts", v ] ->
ReleaseDraftBranchRef (Version.unsafeFromString v)

[ "releases", v ] ->
ReleaseBranchRef (Version.unsafeFromString v)

[ h, s ] ->
ContributorBranchRef
(UserHandle.unsafeFromString h)
(unsafeBranchSlugFromString s)

_ ->
ProjectBranchRef (unsafeBranchSlugFromString raw)


{-| Requirements
- May only contain alphanumeric characters, underscores, and hyphens.
Expand Down
14 changes: 14 additions & 0 deletions src/Code/Version.elm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Code.Version exposing
, toList
, toString
, toUrlString
, unsafeFromString
, version
, view
)
Expand Down Expand Up @@ -75,6 +76,19 @@ fromString s =
|> MaybeE.join


{-| ⚠️ Don't use outside of testing--defaults to 1.0.0
-}
unsafeFromString : String -> Version
unsafeFromString s =
s
|> String.split "."
|> List.map String.toInt
|> MaybeE.combine
|> Maybe.map fromList
|> MaybeE.join
|> Maybe.withDefault (version 1 0 0)


fromUrlString : String -> Maybe Version
fromUrlString s =
s
Expand Down

0 comments on commit 421d85a

Please sign in to comment.