Skip to content

Commit 97c635b

Browse files
committedOct 23, 2014
Merge pull request #288 from mexx/dash-in-prerelease
support dashes in pre releases
2 parents 8580b36 + d1c81ee commit 97c635b

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed
 

‎src/Paket.Core/SemVer.fs

+13-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type PreRelease =
1111
Number : int option }
1212

1313
static member TryParse str =
14-
let m = Regex("^(?<name>[a-zA-Z]+)(?<number>\d*)$").Match(str)
14+
let m = Regex("^(?<name>[a-zA-Z-]+)(?<number>\d*)$").Match(str)
1515
match m.Success, m.Groups.["name"].Value, m.Groups.["number"].Value with
1616
| true, name, "" ->
1717
Some { Origin = str
@@ -109,25 +109,24 @@ module SemVer =
109109
let Parse(version : string) =
110110
let splitted = version.Split '.'
111111
let l = splitted.Length
112-
112+
113+
let splitAtFirst (char : char) (s : string)=
114+
match s.IndexOf(char) with
115+
| -1 -> s, ""
116+
| x -> s.Substring(0, x), s.Substring(x+1)
117+
113118
let patch, preRelease =
114119
match l with
115120
| 0 -> 0, ""
116121
| 1 ->
117-
let splitted' = splitted.[0].Split '-'
118-
0,
119-
if splitted'.Length > 1 then splitted'.[1]
120-
else ""
122+
let _, splitted' = splitted.[0] |> splitAtFirst '-'
123+
0, splitted'
121124
| 2 ->
122-
let splitted' = splitted.[1].Split '-'
123-
0,
124-
if splitted'.Length > 1 then splitted'.[1]
125-
else ""
125+
let _, splitted' = splitted.[1] |> splitAtFirst '-'
126+
0, splitted'
126127
| _ ->
127-
let splitted' = splitted.[2].Split '-'
128-
Int32.Parse splitted'.[0],
129-
if splitted'.Length > 1 then splitted'.[1]
130-
else ""
128+
let p, splitted' = splitted.[2] |> splitAtFirst '-'
129+
Int32.Parse p, splitted'
131130
{ Major =
132131
if l > 0 then Int32.Parse (splitted.[0].Split('-').[0])
133132
else 0

‎tests/Paket.Tests/SemVerSpecs.fs

+13-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,20 @@ let ``trailing zeros are equal``() =
6060
let ``can parse strange versions``() =
6161
(SemVer.Parse "2.1-alpha10").ToString() |> shouldEqual "2.1-alpha10"
6262
(SemVer.Parse "2-alpha100").ToString() |> shouldEqual "2-alpha100"
63+
(SemVer.Parse "2.1-alpha-1").ToString() |> shouldEqual "2.1-alpha-1"
64+
(SemVer.Parse "2-alpha-100").ToString() |> shouldEqual "2-alpha-100"
6365

6466
[<Test>]
6567
let ``can parse FSHarp.Data versions``() =
6668
(SemVer.Parse "2.1.0-beta3").ToString() |> shouldEqual "2.1.0-beta3"
67-
69+
70+
[<Test>]
71+
let ``can parse prerelease versions with dash``() =
72+
let semVer = SemVer.Parse("2.1.0-beta-3")
73+
semVer.Major |> shouldEqual 2
74+
semVer.Minor |> shouldEqual 1
75+
semVer.Patch |> shouldEqual 0
76+
semVer.PreRelease |> shouldEqual (Some { Origin = "beta-3"
77+
Name = "beta-3"
78+
Number = None })
79+
semVer.Build |> shouldEqual ""

0 commit comments

Comments
 (0)
Please sign in to comment.