|
| 1 | +import { isVersion, toAnyPatchVersion, isSupportedSpecVersion, constants } from '../../src'; |
| 2 | + |
| 3 | +describe('isVersion', () => { |
| 4 | + it('matches exact versions', () => { |
| 5 | + expect(isVersion('0.7.0', '0.7.0')).toBe(true); |
| 6 | + expect(isVersion('0.7', '0.7')).toBe(true); |
| 7 | + expect(isVersion('1.2.3', '1.2.3')).toBe(true); |
| 8 | + expect(isVersion('0.7', '0.8')).toBe(false); |
| 9 | + expect(isVersion('0.7.0', '0.7.1')).toBe(false); |
| 10 | + expect(isVersion('0.7.0', '0.8.0')).toBe(false); |
| 11 | + expect(isVersion('1.0.0', '2.0.0')).toBe(false); |
| 12 | + }); |
| 13 | + |
| 14 | + it('handles wildcard in major version', () => { |
| 15 | + expect(isVersion('*.7.0', '0.7.0')).toBe(true); |
| 16 | + expect(isVersion('*.7.0', '1.7.0')).toBe(true); |
| 17 | + expect(isVersion('*.7.0', '2.7.0')).toBe(true); |
| 18 | + expect(isVersion('*.7.0', '0.8.0')).toBe(false); |
| 19 | + }); |
| 20 | + |
| 21 | + it('handles wildcard in minor version', () => { |
| 22 | + expect(isVersion('0.*.0', '0.7.0')).toBe(true); |
| 23 | + expect(isVersion('0.*.0', '0.8.0')).toBe(true); |
| 24 | + expect(isVersion('0.*.0', '0.9.0')).toBe(true); |
| 25 | + expect(isVersion('0.*.0', '1.7.0')).toBe(false); |
| 26 | + }); |
| 27 | + |
| 28 | + it('handles wildcard in patch version', () => { |
| 29 | + expect(isVersion('0.7.*', '0.7.0')).toBe(true); |
| 30 | + expect(isVersion('0.7.*', '0.7.1')).toBe(true); |
| 31 | + expect(isVersion('0.7', '0.7.1')).toBe(true); |
| 32 | + expect(isVersion('0.7.*', '0.7.2')).toBe(true); |
| 33 | + expect(isVersion('0.8.*', '0.8.1-rc2')).toBe(true); |
| 34 | + expect(isVersion('0.8.*', '0.8')).toBe(true); |
| 35 | + expect(isVersion('0.8', '0.8.1')).toBe(true); |
| 36 | + expect(isVersion('0.7.*', '0.8.1-rc3')).toBe(false); |
| 37 | + expect(isVersion('0.7.*', '0.8.0')).toBe(false); |
| 38 | + expect(isVersion('0.7', '0.8.1')).toBe(false); |
| 39 | + }); |
| 40 | + |
| 41 | + it('handles multiple wildcards', () => { |
| 42 | + expect(isVersion('*.*.0', '0.7.0')).toBe(true); |
| 43 | + expect(isVersion('*.*.0', '1.8.0')).toBe(true); |
| 44 | + expect(isVersion('*.*.0', '0.7.1')).toBe(false); |
| 45 | + expect(isVersion('0.*.*', '0.7.0')).toBe(true); |
| 46 | + expect(isVersion('0.*.*', '0.8.1')).toBe(true); |
| 47 | + expect(isVersion('0.*.*', '1.7.0')).toBe(false); |
| 48 | + expect(isVersion('*.*.*', '0.7.0')).toBe(true); |
| 49 | + expect(isVersion('*.*.*', '1.8.2')).toBe(true); |
| 50 | + expect(isVersion('*.*.*', '2.3.4')).toBe(true); |
| 51 | + expect(isVersion('', '2.3.4')).toBe(false); |
| 52 | + expect(isVersion('*', '2.3.4')).toBe(true); |
| 53 | + expect(isVersion('*.3', '2.3.4')).toBe(true); |
| 54 | + expect(isVersion('*.2', '2.3.4')).toBe(false); |
| 55 | + expect(isVersion('*.3.5', '2.3.4')).toBe(false); |
| 56 | + expect(isVersion('*.3.4', '2.3.4')).toBe(true); |
| 57 | + }); |
| 58 | +}); |
| 59 | + |
| 60 | +describe('toAnyPatchVersion', () => { |
| 61 | + it('converts version strings to wildcard patch versions', () => { |
| 62 | + expect(toAnyPatchVersion('0.7.0')).toBe('0.7.*'); |
| 63 | + expect(toAnyPatchVersion('1.2.3')).toBe('1.2.*'); |
| 64 | + expect(toAnyPatchVersion('0.8')).toBe('0.8.*'); |
| 65 | + expect(toAnyPatchVersion('2.0')).toBe('2.0.*'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('handles invalid or empty version strings', () => { |
| 69 | + expect(toAnyPatchVersion('')).toBe(''); |
| 70 | + expect(toAnyPatchVersion('invalid')).toBe('invalid'); |
| 71 | + expect(toAnyPatchVersion('0')).toBe('0.*'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('handles already wildcarded versions', () => { |
| 75 | + expect(toAnyPatchVersion('0.7.*')).toBe('0.7.*'); |
| 76 | + expect(toAnyPatchVersion('1.*')).toBe('1.*'); |
| 77 | + expect(toAnyPatchVersion('*')).toBe('*'); |
| 78 | + }); |
| 79 | +}); |
| 80 | + |
| 81 | +describe('isSupportedSpecVersion', () => { |
| 82 | + it('returns true for supported spec versions', () => { |
| 83 | + expect(isSupportedSpecVersion('0.7')).toBe(true); |
| 84 | + expect(isSupportedSpecVersion('0.8')).toBe(true); |
| 85 | + expect(isSupportedSpecVersion('1.0')).toBe(true); |
| 86 | + }); |
| 87 | + |
| 88 | + it('returns false for unsupported spec versions', () => { |
| 89 | + expect(isSupportedSpecVersion('0.6')).toBe(false); |
| 90 | + expect(isSupportedSpecVersion('2.0')).toBe(false); |
| 91 | + expect(isSupportedSpecVersion('')).toBe(false); |
| 92 | + expect(isSupportedSpecVersion('invalid')).toBe(false); |
| 93 | + }); |
| 94 | + |
| 95 | + it('handles wildcard and partial versions', () => { |
| 96 | + expect(isSupportedSpecVersion('*')).toBe(false); |
| 97 | + expect(isSupportedSpecVersion('0.*')).toBe(false); |
| 98 | + expect(isSupportedSpecVersion('*.8')).toBe(false); |
| 99 | + }); |
| 100 | + |
| 101 | + describe('isSupportedSpecVersion', () => { |
| 102 | + it('returns true for exact supported version', () => { |
| 103 | + expect(isSupportedSpecVersion(constants.SupportedRpcVersion.v0_7_1)).toBe(true); |
| 104 | + }); |
| 105 | + |
| 106 | + it('returns false for unsupported version', () => { |
| 107 | + expect(isSupportedSpecVersion('9.9.9')).toBe(false); |
| 108 | + }); |
| 109 | + |
| 110 | + it('returns true for supported version with allowAnyPatchVersion=true', () => { |
| 111 | + expect(isSupportedSpecVersion('0.7.1', { allowAnyPatchVersion: true })).toBe(true); |
| 112 | + }); |
| 113 | + |
| 114 | + it('returns false for supported version with allowAnyPatchVersion=false and mismatched patch', () => { |
| 115 | + expect(isSupportedSpecVersion('0.7.444', { allowAnyPatchVersion: false })).toBe(false); |
| 116 | + }); |
| 117 | + |
| 118 | + it('returns true for supported version with wildcard in SupportedRpcVersion', () => { |
| 119 | + // Simulate a SupportedRpcVersion with a wildcard |
| 120 | + expect(isSupportedSpecVersion('0.7.123', { allowAnyPatchVersion: true })).toBe(true); |
| 121 | + }); |
| 122 | + |
| 123 | + it('returns false for empty version', () => { |
| 124 | + expect(isSupportedSpecVersion('')).toBe(false); |
| 125 | + }); |
| 126 | + |
| 127 | + it('returns false for malformed version', () => { |
| 128 | + expect(isSupportedSpecVersion('abc.def.ghi')).toBe(false); |
| 129 | + }); |
| 130 | + |
| 131 | + it('returns true for supported version with allowAnyPatchVersion explicitly set to true', () => { |
| 132 | + expect(isSupportedSpecVersion('0.7.2', { allowAnyPatchVersion: true })).toBe(true); |
| 133 | + }); |
| 134 | + |
| 135 | + it('returns false for supported version with allowAnyPatchVersion explicitly set to false', () => { |
| 136 | + expect(isSupportedSpecVersion('0.7.2', { allowAnyPatchVersion: false })).toBe(false); |
| 137 | + }); |
| 138 | + |
| 139 | + it('returns true for supported version when options is omitted (defaults to false)', () => { |
| 140 | + expect(isSupportedSpecVersion('0.7.1')).toBe(true); |
| 141 | + expect(isSupportedSpecVersion('0.7.0')).toBe(false); |
| 142 | + }); |
| 143 | + |
| 144 | + it('returns false for unsupported version regardless of options', () => { |
| 145 | + expect(isSupportedSpecVersion('1.2.3', { allowAnyPatchVersion: true })).toBe(false); |
| 146 | + expect(isSupportedSpecVersion('1.2.3', { allowAnyPatchVersion: false })).toBe(false); |
| 147 | + }); |
| 148 | + }); |
| 149 | +}); |
0 commit comments