Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support dashes in pre releases #288

Merged
merged 1 commit into from
Oct 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/Paket.Core/SemVer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type PreRelease =
Number : int option }

static member TryParse str =
let m = Regex("^(?<name>[a-zA-Z]+)(?<number>\d*)$").Match(str)
let m = Regex("^(?<name>[a-zA-Z-]+)(?<number>\d*)$").Match(str)
match m.Success, m.Groups.["name"].Value, m.Groups.["number"].Value with
| true, name, "" ->
Some { Origin = str
Expand Down Expand Up @@ -109,25 +109,24 @@ module SemVer =
let Parse(version : string) =
let splitted = version.Split '.'
let l = splitted.Length


let splitAtFirst (char : char) (s : string)=
match s.IndexOf(char) with
| -1 -> s, ""
| x -> s.Substring(0, x), s.Substring(x+1)

let patch, preRelease =
match l with
| 0 -> 0, ""
| 1 ->
let splitted' = splitted.[0].Split '-'
0,
if splitted'.Length > 1 then splitted'.[1]
else ""
let _, splitted' = splitted.[0] |> splitAtFirst '-'
0, splitted'
| 2 ->
let splitted' = splitted.[1].Split '-'
0,
if splitted'.Length > 1 then splitted'.[1]
else ""
let _, splitted' = splitted.[1] |> splitAtFirst '-'
0, splitted'
| _ ->
let splitted' = splitted.[2].Split '-'
Int32.Parse splitted'.[0],
if splitted'.Length > 1 then splitted'.[1]
else ""
let p, splitted' = splitted.[2] |> splitAtFirst '-'
Int32.Parse p, splitted'
{ Major =
if l > 0 then Int32.Parse (splitted.[0].Split('-').[0])
else 0
Expand Down
14 changes: 13 additions & 1 deletion tests/Paket.Tests/SemVerSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,20 @@ let ``trailing zeros are equal``() =
let ``can parse strange versions``() =
(SemVer.Parse "2.1-alpha10").ToString() |> shouldEqual "2.1-alpha10"
(SemVer.Parse "2-alpha100").ToString() |> shouldEqual "2-alpha100"
(SemVer.Parse "2.1-alpha-1").ToString() |> shouldEqual "2.1-alpha-1"
(SemVer.Parse "2-alpha-100").ToString() |> shouldEqual "2-alpha-100"

[<Test>]
let ``can parse FSHarp.Data versions``() =
(SemVer.Parse "2.1.0-beta3").ToString() |> shouldEqual "2.1.0-beta3"


[<Test>]
let ``can parse prerelease versions with dash``() =
let semVer = SemVer.Parse("2.1.0-beta-3")
semVer.Major |> shouldEqual 2
semVer.Minor |> shouldEqual 1
semVer.Patch |> shouldEqual 0
semVer.PreRelease |> shouldEqual (Some { Origin = "beta-3"
Name = "beta-3"
Number = None })
semVer.Build |> shouldEqual ""