@@ -6,7 +6,7 @@ import { compareVersion } from '../versionCompare'
66// the contract is -1/0/1, but we only care about the sign.
77const sign = ( n : number | null ) => ( n === null ? null : Math . sign ( n ) )
88
9- describe ( 'compareVersion — npm (semver)' , ( ) => {
9+ describe ( 'compareVersion — npm/cargo (semver)' , ( ) => {
1010 it . each ( [
1111 [ '1.2.3' , '1.2.4' , - 1 ] ,
1212 [ '1.2.4' , '1.2.3' , 1 ] ,
@@ -20,11 +20,21 @@ describe('compareVersion — npm (semver)', () => {
2020 expect ( sign ( compareVersion ( 'npm' , a , b ) ) ) . toBe ( expected )
2121 } )
2222
23- it ( 'returns null for unparseable npm versions' , ( ) => {
23+ it . each ( [
24+ [ '0.1.0' , '0.2.0' , - 1 ] ,
25+ [ '1.0.0' , '1.0.0' , 0 ] ,
26+ [ '2.0.0' , '1.9.9' , 1 ] ,
27+ [ '0.3.0-alpha.1' , '0.3.0' , - 1 ] ,
28+ ] ) ( 'compareVersion("cargo", %s, %s) sign = %s' , ( a , b , expected ) => {
29+ expect ( sign ( compareVersion ( 'cargo' , a , b ) ) ) . toBe ( expected )
30+ } )
31+
32+ it ( 'returns null for unparseable semver versions' , ( ) => {
2433 expect ( compareVersion ( 'npm' , 'not-a-version-at-all' , '1.0.0' ) ) . toBeNull ( )
34+ expect ( compareVersion ( 'cargo' , 'not-a-version-at-all' , '1.0.0' ) ) . toBeNull ( )
2535 } )
2636
27- it ( 'returns null for short / lossy npm versions instead of coercing' , ( ) => {
37+ it ( 'returns null for short / lossy versions instead of coercing' , ( ) => {
2838 // Under-flag over mis-flag: semver.coerce would map "1.2" → "1.2.0" and
2939 // "1.2-junk-3" → "1.2.3", which can flip has_critical_vulnerability on
3040 // a malformed introduced/fixed boundary. We prefer null (no match).
@@ -76,7 +86,6 @@ describe('compareVersion — maven (ComparableVersion-style)', () => {
7686describe ( 'compareVersion — unsupported ecosystems' , ( ) => {
7787 it ( 'returns null for ecosystems we have no comparator for' , ( ) => {
7888 expect ( compareVersion ( 'PyPI' , '1.0.0' , '2.0.0' ) ) . toBeNull ( )
79- expect ( compareVersion ( 'crates.io' , '0.1' , '0.2' ) ) . toBeNull ( )
8089 } )
8190
8291 it ( 'rejects titlecase "Maven" — production storage is always lowercase' , ( ) => {
0 commit comments