@@ -126,3 +126,53 @@ test('cache', (t) => {
126
126
t . equal ( r2 . set [ 0 ] [ cached ] , true ) // Will be true, showing it's cached.
127
127
t . end ( )
128
128
} )
129
+
130
+ test ( 'Build metadata is allowed and ignored for X-ranges and partials' , t => {
131
+ const buildCases = [
132
+ '1.x.x+build >2.x.x+build' ,
133
+ '>=1.x.x+build <2.x.x+build' ,
134
+ '1.x.x+build || 2.x.x+build' ,
135
+ '1.x.x+build.123' ,
136
+ '1.x.x+meta-data' ,
137
+ '1.x.x+build.123 >2.x.x+meta-data' ,
138
+ '1.x.x+build <2.x.x+meta' ,
139
+ '>1.x.x+build <=2.x.x+meta' ,
140
+ ' 1.x.x+build >2.x.x+build ' ,
141
+ ]
142
+ t . plan ( buildCases . length )
143
+ buildCases . forEach ( range => {
144
+ t . doesNotThrow ( ( ) => new Range ( range ) , `${ range } should not throw` )
145
+ } )
146
+ } )
147
+
148
+ test ( 'Build metadata with prerelease in X-ranges/partials throws' , t => {
149
+ const cases = [
150
+ '1.x.x-alpha+build' ,
151
+ '1.x-alpha+build' ,
152
+ '1-alpha+build' ,
153
+ '>1.x.x-alpha+build' ,
154
+ '>=1.x.x-alpha+build <2.x.x+build' ,
155
+ '1.x.x-alpha+build || 2.x.x+build' ,
156
+ ]
157
+ t . plan ( cases . length )
158
+ cases . forEach ( range => {
159
+ t . throws ( ( ) => new Range ( range ) , TypeError , `${ range } should throw TypeError` )
160
+ } )
161
+ } )
162
+
163
+ test ( 'Prerelease is NOT allowed with X-ranges or partials' , t => {
164
+ const prereleaseCases = [
165
+ '1.x-alpha' ,
166
+ '1-alpha' ,
167
+ '1.x.x-alpha' ,
168
+ '>1.x-alpha' ,
169
+ '>1-alpha' ,
170
+ '>1.x.x-alpha' ,
171
+ '1.x.x-alpha <2.x.x-alpha' ,
172
+ '>1.x.x-alpha <=2.x-alpha' ,
173
+ ]
174
+ t . plan ( prereleaseCases . length )
175
+ prereleaseCases . forEach ( range => {
176
+ t . throws ( ( ) => new Range ( range ) , TypeError , `${ range } should throw TypeError` )
177
+ } )
178
+ } )
0 commit comments