gtr.js 4.8 KB

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