ltr.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. var tap = require('tap');
  2. var test = tap.test;
  3. var semver = require('../semver.js');
  4. var ltr = semver.ltr;
  5. test('\nltr tests', function(t) {
  6. // [range, version, loose]
  7. // Version should be less than range
  8. [
  9. ['~1.2.2', '1.2.1'],
  10. ['~0.6.1-1', '0.6.1-0'],
  11. ['1.0.0 - 2.0.0', '0.0.1'],
  12. ['1.0.0-beta.2', '1.0.0-beta.1'],
  13. ['1.0.0', '0.0.0'],
  14. ['>=2.0.0', '1.1.1'],
  15. ['>=2.0.0', '1.2.9'],
  16. ['>2.0.0', '2.0.0'],
  17. ['0.1.20 || 1.2.4', '0.1.5'],
  18. ['2.x.x', '1.0.0'],
  19. ['1.2.x', '1.1.0'],
  20. ['1.2.x || 2.x', '1.0.0'],
  21. ['2.*.*', '1.0.1'],
  22. ['1.2.*', '1.1.3'],
  23. ['1.2.* || 2.*', '1.1.9999'],
  24. ['2', '1.0.0'],
  25. ['2.3', '2.2.2'],
  26. ['~2.4', '2.3.0'], // >=2.4.0 <2.5.0
  27. ['~2.4', '2.3.5'],
  28. ['~>3.2.1', '3.2.0'], // >=3.2.1 <3.3.0
  29. ['~1', '0.2.3'], // >=1.0.0 <2.0.0
  30. ['~>1', '0.2.4'],
  31. ['~> 1', '0.2.3'],
  32. ['~1.0', '0.1.2'], // >=1.0.0 <1.1.0
  33. ['~ 1.0', '0.1.0'],
  34. ['>1.2', '1.2.0'],
  35. ['> 1.2', '1.2.1'],
  36. ['1', '0.0.0beta', true],
  37. ['~v0.5.4-pre', '0.5.4-alpha'],
  38. ['~v0.5.4-pre', '0.5.4-alpha'],
  39. ['=0.7.x', '0.6.0'],
  40. ['=0.7.x', '0.6.0-asdf'],
  41. ['>=0.7.x', '0.6.0'],
  42. ['~1.2.2', '1.2.1'],
  43. ['1.0.0 - 2.0.0', '0.2.3'],
  44. ['1.0.0', '0.0.1'],
  45. ['>=2.0.0', '1.0.0'],
  46. ['>=2.0.0', '1.9999.9999'],
  47. ['>=2.0.0', '1.2.9'],
  48. ['>2.0.0', '2.0.0'],
  49. ['>2.0.0', '1.2.9'],
  50. ['2.x.x', '1.1.3'],
  51. ['1.2.x', '1.1.3'],
  52. ['1.2.x || 2.x', '1.1.3'],
  53. ['2.*.*', '1.1.3'],
  54. ['1.2.*', '1.1.3'],
  55. ['1.2.* || 2.*', '1.1.3'],
  56. ['2', '1.9999.9999'],
  57. ['2.3', '2.2.1'],
  58. ['~2.4', '2.3.0'], // >=2.4.0 <2.5.0
  59. ['~>3.2.1', '2.3.2'], // >=3.2.1 <3.3.0
  60. ['~1', '0.2.3'], // >=1.0.0 <2.0.0
  61. ['~>1', '0.2.3'],
  62. ['~1.0', '0.0.0'], // >=1.0.0 <1.1.0
  63. ['>1', '1.0.0'],
  64. ['2', '1.0.0beta', true],
  65. ['>1', '1.0.0beta', true],
  66. ['> 1', '1.0.0beta', true],
  67. ['=0.7.x', '0.6.2'],
  68. ['=0.7.x', '0.7.0-asdf'],
  69. ['^1', '1.0.0-0'],
  70. ['>=0.7.x', '0.7.0-asdf'],
  71. ['1', '1.0.0beta', true],
  72. ['>=0.7.x', '0.6.2'],
  73. ['>1.2.3', '1.3.0-alpha']
  74. ].forEach(function(tuple) {
  75. var range = tuple[0];
  76. var version = tuple[1];
  77. var loose = tuple[2] || false;
  78. var msg = 'ltr(' + version + ', ' + range + ', ' + loose + ')';
  79. t.ok(ltr(version, range, loose), msg);
  80. });
  81. t.end();
  82. });
  83. test('\nnegative ltr tests', function(t) {
  84. // [range, version, loose]
  85. // Version should NOT be less than range
  86. [
  87. ['~ 1.0', '1.1.0'],
  88. ['~0.6.1-1', '0.6.1-1'],
  89. ['1.0.0 - 2.0.0', '1.2.3'],
  90. ['1.0.0 - 2.0.0', '2.9.9'],
  91. ['1.0.0', '1.0.0'],
  92. ['>=*', '0.2.4'],
  93. ['', '1.0.0', true],
  94. ['*', '1.2.3'],
  95. ['>=1.0.0', '1.0.0'],
  96. ['>=1.0.0', '1.0.1'],
  97. ['>=1.0.0', '1.1.0'],
  98. ['>1.0.0', '1.0.1'],
  99. ['>1.0.0', '1.1.0'],
  100. ['<=2.0.0', '2.0.0'],
  101. ['<=2.0.0', '1.9999.9999'],
  102. ['<=2.0.0', '0.2.9'],
  103. ['<2.0.0', '1.9999.9999'],
  104. ['<2.0.0', '0.2.9'],
  105. ['>= 1.0.0', '1.0.0'],
  106. ['>= 1.0.0', '1.0.1'],
  107. ['>= 1.0.0', '1.1.0'],
  108. ['> 1.0.0', '1.0.1'],
  109. ['> 1.0.0', '1.1.0'],
  110. ['<= 2.0.0', '2.0.0'],
  111. ['<= 2.0.0', '1.9999.9999'],
  112. ['<= 2.0.0', '0.2.9'],
  113. ['< 2.0.0', '1.9999.9999'],
  114. ['<\t2.0.0', '0.2.9'],
  115. ['>=0.1.97', 'v0.1.97'],
  116. ['>=0.1.97', '0.1.97'],
  117. ['0.1.20 || 1.2.4', '1.2.4'],
  118. ['0.1.20 || >1.2.4', '1.2.4'],
  119. ['0.1.20 || 1.2.4', '1.2.3'],
  120. ['0.1.20 || 1.2.4', '0.1.20'],
  121. ['>=0.2.3 || <0.0.1', '0.0.0'],
  122. ['>=0.2.3 || <0.0.1', '0.2.3'],
  123. ['>=0.2.3 || <0.0.1', '0.2.4'],
  124. ['||', '1.3.4'],
  125. ['2.x.x', '2.1.3'],
  126. ['1.2.x', '1.2.3'],
  127. ['1.2.x || 2.x', '2.1.3'],
  128. ['1.2.x || 2.x', '1.2.3'],
  129. ['x', '1.2.3'],
  130. ['2.*.*', '2.1.3'],
  131. ['1.2.*', '1.2.3'],
  132. ['1.2.* || 2.*', '2.1.3'],
  133. ['1.2.* || 2.*', '1.2.3'],
  134. ['1.2.* || 2.*', '1.2.3'],
  135. ['*', '1.2.3'],
  136. ['2', '2.1.2'],
  137. ['2.3', '2.3.1'],
  138. ['~2.4', '2.4.0'], // >=2.4.0 <2.5.0
  139. ['~2.4', '2.4.5'],
  140. ['~>3.2.1', '3.2.2'], // >=3.2.1 <3.3.0
  141. ['~1', '1.2.3'], // >=1.0.0 <2.0.0
  142. ['~>1', '1.2.3'],
  143. ['~> 1', '1.2.3'],
  144. ['~1.0', '1.0.2'], // >=1.0.0 <1.1.0
  145. ['~ 1.0', '1.0.2'],
  146. ['>=1', '1.0.0'],
  147. ['>= 1', '1.0.0'],
  148. ['<1.2', '1.1.1'],
  149. ['< 1.2', '1.1.1'],
  150. ['~v0.5.4-pre', '0.5.5'],
  151. ['~v0.5.4-pre', '0.5.4'],
  152. ['=0.7.x', '0.7.2'],
  153. ['>=0.7.x', '0.7.2'],
  154. ['<=0.7.x', '0.6.2'],
  155. ['>0.2.3 >0.2.4 <=0.2.5', '0.2.5'],
  156. ['>=0.2.3 <=0.2.4', '0.2.4'],
  157. ['1.0.0 - 2.0.0', '2.0.0'],
  158. ['^3.0.0', '4.0.0'],
  159. ['^1.0.0 || ~2.0.1', '2.0.0'],
  160. ['^0.1.0 || ~3.0.1 || 5.0.0', '3.2.0'],
  161. ['^0.1.0 || ~3.0.1 || 5.0.0', '1.0.0beta', true],
  162. ['^0.1.0 || ~3.0.1 || 5.0.0', '5.0.0-0', true],
  163. ['^0.1.0 || ~3.0.1 || >4 <=5.0.0', '3.5.0'],
  164. ['^1.0.0alpha', '1.0.0beta', true],
  165. ['~1.0.0alpha', '1.0.0beta', true],
  166. ['^1.0.0-alpha', '1.0.0beta', true],
  167. ['~1.0.0-alpha', '1.0.0beta', true],
  168. ['^1.0.0-alpha', '1.0.0-beta'],
  169. ['~1.0.0-alpha', '1.0.0-beta'],
  170. ['=0.1.0', '1.0.0']
  171. ].forEach(function(tuple) {
  172. var range = tuple[0];
  173. var version = tuple[1];
  174. var loose = tuple[2] || false;
  175. var msg = '!ltr(' + version + ', ' + range + ', ' + loose + ')';
  176. t.notOk(ltr(version, range, loose), msg);
  177. });
  178. t.end();
  179. });