Skip to content

Commit 3f000a5

Browse files
committed
Added helper function for finding a compatible semantic version range for a given semantic version.
1 parent be9ca93 commit 3f000a5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/SemanticVersionRange.gren

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module SemanticVersionRange exposing
55
, lowerBound
66
, upperBound
77
, intersect
8+
, compatibleWith
89
, fromExact
910
, fromString
1011
, jsonDecoder
@@ -103,6 +104,14 @@ intersect left right =
103104
SemanticVersionRange { lower = lowerRight, upper = upperRight }
104105

105106

107+
compatibleWith : SemanticVersion -> SemanticVersionRange
108+
compatibleWith ver =
109+
SemanticVersionRange
110+
{ lower = { major = ver.major, minor = ver.minor, patch = 0 }
111+
, upper = { major = ver.major + 1, minor = 0, patch = 0 }
112+
}
113+
114+
106115
fromExact : SemanticVersion -> SemanticVersionRange
107116
fromExact ({ major, minor, patch } as lower) =
108117
SemanticVersionRange

tests/src/Test/SemanticVersionRange.gren

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ tests =
6767
]
6868
(rangeFrom 1 5 0)
6969
]
70+
, describe "compatibleWith"
71+
[ test "1.2.4" <| \{} ->
72+
Range.compatibleWith { major = 1, minor = 2, patch = 4 }
73+
|> Expect.equal (rangeFrom 1 2 0)
74+
]
7075
]
7176

7277

0 commit comments

Comments
 (0)