File tree Expand file tree Collapse file tree 2 files changed +39
-11
lines changed Expand file tree Collapse file tree 2 files changed +39
-11
lines changed Original file line number Diff line number Diff line change @@ -95,11 +95,32 @@ def create_semver_matcher(constraint_str):
95
95
else :
96
96
return VersionRange (constraint , (major (constraint ) + 1 ,), True )
97
97
98
- # '~' matching (only allowed to bump the last present number by one)
98
+ # '~' matching, bumps minor version unless only major specified or leading 0.0.
99
+ # https://pkgdocs.julialang.org/v1/compatibility/#Tilde-specifiers
99
100
if comparison_symbol == "~" :
100
- return VersionRange (
101
- constraint , constraint [:- 1 ] + (constraint [- 1 ] + 1 ,), exclusive = False
102
- )
101
+ if len (constraint ) == 1 :
102
+ # only major specified
103
+ # ~x -> [x-x+1)
104
+ return VersionRange (constraint , (constraint [0 ] + 1 ,), exclusive = True )
105
+ elif len (constraint ) == 2 :
106
+ # ~x.y -> [x.y-x.y+1)
107
+ return VersionRange (
108
+ constraint ,
109
+ (
110
+ major (constraint ),
111
+ minor (constraint ) + 1 ,
112
+ ),
113
+ exclusive = True ,
114
+ )
115
+ else :
116
+ # 3 parts, different depending on if starts with 0.0
117
+ if major (constraint ) == 0 and minor (constraint ) == 0 :
118
+ # ~0.0.3 = [0.0.3-0.0.4)
119
+ upper = (0 , 0 , patch (constraint ) + 1 )
120
+ else :
121
+ # ~0.2.3 = [0.2.3-0.3)
122
+ upper = (major (constraint ), minor (constraint ) + 1 )
123
+ return VersionRange (constraint , upper , exclusive = True )
103
124
104
125
# Use semver package's comparisons for everything else:
105
126
Original file line number Diff line number Diff line change @@ -29,13 +29,14 @@ def test_major_minor_patch():
29
29
("^0.0.3" , "[0.0.3-0.0.4)" ),
30
30
("^0.0" , "[0.0-0.1)" ),
31
31
("^0" , "[0-1)" ),
32
- # This one seems wrong: `~1.2.3 = [1.2.3, 1.2.4)`
33
- # but ~ is special in Julia from
34
- # https://docs.julialang.org/en/latest/stdlib/Pkg/#Tilde-specifiers-1
35
- ("~1.2.3" , "[1.2.3-1.2.4]" ),
36
- ("~1.3.5" , "[1.3.5-1.3.6]" ),
37
- ("~1.2" , "[1.2-1.3]" ),
38
- ("~1" , "[1-2]" ),
32
+ # https://pkgdocs.julialang.org/v1/compatibility/#Tilde-specifiers
33
+ ("~1.2.3" , "[1.2.3-1.3)" ),
34
+ ("~1.3.5" , "[1.3.5-1.4)" ),
35
+ ("~1.2" , "[1.2-1.3)" ),
36
+ ("~1" , "[1-2)" ),
37
+ ("~0.0.3" , "[0.0.3-0.0.4)" ),
38
+ ("~0.0" , "[0.0-0.1)" ),
39
+ ("~0" , "[0-1)" ),
39
40
],
40
41
)
41
42
def test_simple_matches (test_input , expected ):
@@ -65,6 +66,9 @@ def test_range_matches(test_input, expected):
65
66
("1.2.3" , "1.2.3" ),
66
67
("~1.2.3" , "1.2.4" ),
67
68
("~1.2.3" , "1.2.3" ),
69
+ ("~1.2" , "1.2.10" ),
70
+ ("~1" , "1.99" ),
71
+ ("~0.0.3" , "0.0.3" ),
68
72
("1.2" , "1.2.0" ),
69
73
("1.2" , "1.9.9" ),
70
74
("0.2.3" , "0.2.3" ),
@@ -86,6 +90,9 @@ def test_match_particular_version_expected_true(test_input, expected):
86
90
("1.2.3" , "2.0.0" ),
87
91
("1.2.3" , "1.2.2" ),
88
92
("~1.2.3" , "1.3" ),
93
+ ("~1.2" , "1.3" ),
94
+ ("~1" , "2" ),
95
+ ("~0.0.3" , "0.0.4" ),
89
96
("1.2" , "2.0.0" ),
90
97
("1.2" , "1.1.9" ),
91
98
("0.2.3" , "0.3.0" ),
You can’t perform that action at this time.
0 commit comments