SemVerTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php
  2. namespace vierbergenlars\SemVer\Tests\Internal;
  3. use PHPUnit\Framework\TestCase;
  4. use vierbergenlars\SemVer\Internal as SemVer;
  5. class SemVerTest extends TestCase
  6. {
  7. public function testComparison()
  8. {
  9. $compare = array(
  10. array("0.0.0", "0.0.0-foo"),
  11. array("0.0.1", "0.0.0"),
  12. array("1.0.0", "0.9.9"),
  13. array("0.10.0", "0.9.0"),
  14. array("0.99.0", "0.10.0"),
  15. array("2.0.0", "1.2.3"),
  16. array("v0.0.0", "0.0.0-foo", true),
  17. array("v0.0.1", "0.0.0", true),
  18. array("v1.0.0", "0.9.9", true),
  19. array("v0.10.0", "0.9.0", true),
  20. array("v0.99.0", "0.10.0", true),
  21. array("v2.0.0", "1.2.3", true),
  22. array("0.0.0", "v0.0.0-foo", true),
  23. array("0.0.1", "v0.0.0", true),
  24. array("1.0.0", "v0.9.9", true),
  25. array("0.10.0", "v0.9.0", true),
  26. array("0.99.0", "v0.10.0", true),
  27. array("2.0.0", "v1.2.3", true),
  28. array("1.2.3", "1.2.3-asdf"),
  29. array("1.2.3", "1.2.3-4"),
  30. array("1.2.3", "1.2.3-4-foo"),
  31. array("1.2.3-5-foo", "1.2.3-5"),
  32. array("1.2.3-5", "1.2.3-4"),
  33. array("1.2.3-5-foo", "1.2.3-5-Foo"),
  34. //array('1.2.3-0','1.2.3'),
  35. array('3.0.0', '2.7.2+asdf'),
  36. array('1.2.3-a.10', '1.2.3-a.5'),
  37. array('1.2.3-a.b', '1.2.3-a.5'),
  38. array('1.2.3-a.b', '1.2.3-a'),
  39. array('1.2.3-a.b.c.10.d.5', '1.2.3-a.b.c.5.d.100')
  40. );
  41. foreach ($compare as $set) {
  42. $a = $set[0];
  43. $b = $set[1];
  44. $loose = isset($set[2]) && $set[2];
  45. $this->assertTrue(SemVer\G::gt($a, $b, $loose), "%s > gt('" . $a . "', '" . $b . "')");
  46. $this->assertTrue(SemVer\G::lt($b, $a, $loose), "%s > lt('" . $b . "', '" . $a . "')");
  47. $this->assertFalse(SemVer\G::gt($b, $a, $loose), "%s > !gt('" . $b . "', '" . $a . "')");
  48. $this->assertFalse(SemVer\G::lt($a, $b, $loose), "%s > !lt('" . $a . "', '" . $b . "')");
  49. $this->assertTrue(SemVer\G::eq($a, $a, $loose), "%s > eq('" . $a . "', '" . $a . "')");
  50. $this->assertTrue(SemVer\G::eq($b, $b, $loose), "%s > eq('" . $b . "', '" . $b . "')");
  51. $this->assertTrue(SemVer\G::neq($a, $b, $loose), "%s > neq('" . $a . "', '" . $b . "')");
  52. $this->assertTrue(SemVer\G::cmp($b, "==", $b, $loose), "%s > cmp('" . $b . "' == '" . $b . "')");
  53. $this->assertTrue(SemVer\G::cmp($a, ">=", $b, $loose), "%s > cmp('" . $a . "' >= '" . $b . "')");
  54. $this->assertTrue(SemVer\G::cmp($b, "<=", $a, $loose), "%s > cmp('" . $b . "' <= '" . $a . "')");
  55. $this->assertTrue(SemVer\G::cmp($a, "!=", $b, $loose), "%s > cmp('" . $a . "' != '" . $b . "')");
  56. }
  57. }
  58. public function testEquality()
  59. {
  60. $compare = array(
  61. array("1.2.3", "v1.2.3", true),
  62. array("1.2.3", "=1.2.3", true),
  63. array("1.2.3", "v 1.2.3", true),
  64. array("1.2.3", "= 1.2.3", true),
  65. array("1.2.3", " v1.2.3", true),
  66. array("1.2.3", " =1.2.3", true),
  67. array("1.2.3", " v 1.2.3", true),
  68. array("1.2.3", " = 1.2.3", true),
  69. array("1.2.3-0", "v1.2.3-0", true),
  70. array("1.2.3-0", "=1.2.3-0", true),
  71. array("1.2.3-0", "v 1.2.3-0", true),
  72. array("1.2.3-0", "= 1.2.3-0", true),
  73. array("1.2.3-0", " v1.2.3-0", true),
  74. array("1.2.3-0", " =1.2.3-0", true),
  75. array("1.2.3-0", " v 1.2.3-0", true),
  76. array("1.2.3-0", " = 1.2.3-0", true),
  77. array("1.2.3-01", "v1.2.3-1", true),
  78. array("1.2.3-01", "=1.2.3-1", true),
  79. array("1.2.3-01", "v 1.2.3-1", true),
  80. array("1.2.3-01", "= 1.2.3-1", true),
  81. array("1.2.3-01", " v1.2.3-1", true),
  82. array("1.2.3-01", " =1.2.3-1", true),
  83. array("1.2.3-01", " v 1.2.3-1", true),
  84. array("1.2.3-01", " = 1.2.3-1", true),
  85. array("1.2.3-beta", "v1.2.3-beta", true),
  86. array("1.2.3-beta", "=1.2.3-beta", true),
  87. array("1.2.3-beta", "v 1.2.3-beta", true),
  88. array("1.2.3-beta", "= 1.2.3-beta", true),
  89. array("1.2.3-beta", " v1.2.3-beta", true),
  90. array("1.2.3-beta", " =1.2.3-beta", true),
  91. array("1.2.3-beta", " v 1.2.3-beta", true),
  92. array("1.2.3-beta", " = 1.2.3-beta", true),
  93. array("1.2.3-beta+build", " = 1.2.3-beta+otherbuild", true),
  94. array("1.2.3+build", " = 1.2.3+otherbuild", true),
  95. array("1.2.3-beta+build", "1.2.3-beta+otherbuild", true),
  96. array("1.2.3+build", "1.2.3+otherbuild"),
  97. array("1.2.3+build", '1.2.3+otherbuild'),
  98. array(" v1.2.3+build", "1.2.3+otherbuild")
  99. );
  100. foreach ($compare as $set) {
  101. $a = $set[0];
  102. $b = $set[1];
  103. $loose = isset($set[2]) && $set[2];
  104. try {
  105. $this->assertTrue(SemVer\G::eq($a, $b, $loose), "%s > eq('" . $a . "', '" . $b . "')");
  106. $this->assertFalse(SemVer\G::neq($a, $b, $loose), "%s > !neq('" . $a . "', '" . $b . "')");
  107. $this->assertTrue(SemVer\G::cmp($a, "==", $b, $loose), "%s > cmp(" . $a . "==" . $b . ")");
  108. $this->assertFalse(SemVer\G::cmp($a, "!=", $b, $loose), "%s > !cmp(" . $a . "!=" . $b . ")");
  109. $this->assertFalse(SemVer\G::cmp($a, "===", $b, $loose), "%s > !cmp(" . $a . "===" . $b . ")");
  110. $this->assertTrue(SemVer\G::cmp($a, "!==", $b, $loose), "%s > cmp(" . $a . "!==" . $b . ")");
  111. $this->assertFalse(SemVer\G::gt($a, $b, $loose), "%s > !gt('" . $a . "', '" . $b . "')");
  112. $this->assertTrue(SemVer\G::gte($a, $b, $loose), "%s > gte('" . $a . "', '" . $b . "')");
  113. $this->assertFalse(SemVer\G::lt($a, $b, $loose), "%s > !lt('" . $a . "', '" . $b . "')");
  114. $this->assertTrue(SemVer\G::lte($a, $b, $loose), "%s > lte('" . $a . "', '" . $b . "')");
  115. } catch (\Exception $e) {
  116. $this->fail("Exception while comparing $set[0] and $set[1]");
  117. }
  118. }
  119. }
  120. public function testRange()
  121. {
  122. $compare = array(
  123. array("1.0.0 - 2.0.0", "1.2.3"),
  124. array("1.0.0", "1.0.0"),
  125. array(">=*", "0.2.4"),
  126. array("", "1.0.0"),
  127. array("*", "1.2.3"),
  128. array('*', 'v1.2.3-foo', true),
  129. array(">=1.0.0", "1.0.0"),
  130. array(">=1.0.0", "1.0.1"),
  131. array(">=1.0.0", "1.1.0"),
  132. array(">1.0.0", "1.0.1"),
  133. array(">1.0.0", "1.1.0"),
  134. array("<=2.0.0", "2.0.0"),
  135. array("<=2.0.0", "1.9999.9999"),
  136. array("<=2.0.0", "0.2.9"),
  137. array("<2.0.0", "1.9999.9999"),
  138. array("<2.0.0", "0.2.9"),
  139. array(">= 1.0.0", "1.0.0"),
  140. array(">= 1.0.0", "1.0.1"),
  141. array(">= 1.0.0", "1.1.0"),
  142. array("> 1.0.0", "1.0.1"),
  143. array("> 1.0.0", "1.1.0"),
  144. array("<= 2.0.0", "2.0.0"),
  145. array("<= 2.0.0", "1.9999.9999"),
  146. array("<= 2.0.0", "0.2.9"),
  147. array("< 2.0.0", "1.9999.9999"),
  148. array("<\t2.0.0", "0.2.9"),
  149. array(">=0.1.97", "v0.1.97", true),
  150. array(">=0.1.97", "0.1.97"),
  151. array("0.1.20 || 1.2.4", "1.2.4"),
  152. array(">=0.2.3 || <0.0.1", "0.0.0"),
  153. array(">=0.2.3 || <0.0.1", "0.2.3"),
  154. array(">=0.2.3 || <0.0.1", "0.2.4"),
  155. array("||", "1.3.4"),
  156. array("2.x.x", "2.1.3"),
  157. array("1.2.x", "1.2.3"),
  158. array("1.2.x || 2.x", "2.1.3"),
  159. array("1.2.x || 2.x", "1.2.3"),
  160. array("x", "1.2.3"),
  161. array("2.*.*", "2.1.3"),
  162. array("1.2.*", "1.2.3"),
  163. array("1.2.* || 2.*", "2.1.3"),
  164. array("1.2.* || 2.*", "1.2.3"),
  165. array("*", "1.2.3"),
  166. array("2", "2.1.2"),
  167. array("2.3", "2.3.1"),
  168. array("~2.4", "2.4.0"), // >=2.4.0 <2.5.0
  169. array("~2.4", "2.4.5"),
  170. array("~>3.2.1", "3.2.2"), // >=3.2.1 <3.3.0
  171. array("~1", "1.2.3"), // >=1.0.0 <2.0.0
  172. array("~>1", "1.2.3"),
  173. array("~> 1", "1.2.3"),
  174. array("~1.0", "1.0.2"), // >=1.0.0 <1.1.0
  175. array("~ 1.0", "1.0.2"),
  176. array("~1.0.3", "1.0.12"),
  177. array(">=1", "1.0.0"),
  178. array(">= 1", "1.0.0"),
  179. array("<1.2", "1.1.1"),
  180. array("< 1.2", "1.1.1"),
  181. array("1", "1.0.0beta", true),
  182. array("~v0.5.4-pre", "0.5.5"),
  183. array("~v0.5.4-pre", "0.5.4"),
  184. array('=0.7.x', '0.7.2'),
  185. array('>=0.7.x', '0.7.2'),
  186. array('=0.7.x', '0.7.0-asdf'),
  187. array('>=0.7.x', '0.7.0-asdf'),
  188. array('<=0.7.x', '0.6.2'),
  189. array('~1.2.1 >=1.2.3', '1.2.3'),
  190. array('~1.2.1 =1.2.3', '1.2.3'),
  191. array('~1.2.1 1.2.3', '1.2.3'),
  192. array('~1.2.1 >=1.2.3 1.2.3', '1.2.3'),
  193. array('~1.2.1 1.2.3 >=1.2.3', '1.2.3'),
  194. array('~1.2.1 1.2.3', '1.2.3'),
  195. array('>=1.2.1 1.2.3', '1.2.3'),
  196. array('1.2.3 >=1.2.1', '1.2.3'),
  197. array('>=1.2.3 >=1.2.1', '1.2.3'),
  198. array('>=1.2.1 >=1.2.3', '1.2.3'),
  199. array('<=1.2.3', '1.2.3-beta'),
  200. array('>1.2', '1.3.0-beta'),
  201. array('>=1.2', '1.2.8'),
  202. array('^1.2.3', '1.8.1'),
  203. array('^1.2.3', '1.2.3-beta'),
  204. array('^0.1.2', '0.1.2'),
  205. array('^0.1', '0.1.2'),
  206. array('^1.2', '1.4.2'),
  207. array('^1.2 ^1', '1.4.2'),
  208. array('^1.2', '1.2.0-pre'),
  209. array('^1.2.3', '1.2.3-pre')
  210. );
  211. foreach ($compare as $set) {
  212. $loose = isset($set[2]) && $set[2];
  213. $this->assertTrue(SemVer\G::satisfies($set[1], $set[0], $loose),
  214. "%s > $set[0] should be satisfied by $set[1]");
  215. }
  216. }
  217. public function testNegativeRange()
  218. {
  219. $compare = array(
  220. array("1.0.0 - 2.0.0", "2.2.3"),
  221. array("1.0.0", "1.0.1"),
  222. array(">=1.0.0", "0.0.0"),
  223. array(">=1.0.0", "0.0.1"),
  224. array(">=1.0.0", "0.1.0"),
  225. array(">1.0.0", "0.0.1"),
  226. array(">1.0.0", "0.1.0"),
  227. array("<=2.0.0", "3.0.0"),
  228. array("<=2.0.0", "2.9999.9999"),
  229. array("<=2.0.0", "2.2.9"),
  230. array("<2.0.0", "2.9999.9999"),
  231. array("<2.0.0", "2.2.9"),
  232. array(">=0.1.97", "v0.1.93", true),
  233. array(">=0.1.97", "0.1.93"),
  234. array("0.1.20 || 1.2.4", "1.2.3"),
  235. array(">=0.2.3 || <0.0.1", "0.0.3"),
  236. array(">=0.2.3 || <0.0.1", "0.2.2"),
  237. array("2.x.x", "1.1.3"),
  238. array("2.x.x", "3.1.3"),
  239. array("1.2.x", "1.3.3"),
  240. array("1.2.x || 2.x", "3.1.3"),
  241. array("1.2.x || 2.x", "1.1.3"),
  242. array("2.*.*", "1.1.3"),
  243. array("2.*.*", "3.1.3"),
  244. array("1.2.*", "1.3.3"),
  245. array("1.2.* || 2.*", "3.1.3"),
  246. array("1.2.* || 2.*", "1.1.3"),
  247. array("2", "1.1.2"),
  248. array("2.3", "2.4.1"),
  249. array("~2.4", "2.5.0"), // >=2.4.0 <2.5.0
  250. array("~2.4", "2.3.9"),
  251. array("~>3.2.1", "3.3.2"), // >=3.2.1 <3.3.0
  252. array("~>3.2.1", "3.2.0"), // >=3.2.1 <3.3.0
  253. array("~1", "0.2.3"), // >=1.0.0 <2.0.0
  254. array("~>1", "2.2.3"),
  255. array("~1.0", "1.1.0"), // >=1.0.0 <1.1.0
  256. array("<1", "1.0.0"),
  257. array(">=1.2", "1.1.1"),
  258. array("1", "2.0.0beta", true),
  259. array("~v0.5.4-beta", "0.5.4-alpha"),
  260. array('<1', '1.0.0beta', true),
  261. array('< 1', '1.0.0beta', true),
  262. array('=0.7.x', '0.8.2'),
  263. array('>=0.7.x', '0.6.2'),
  264. array('<=0.7.x', '0.7.2'),
  265. array('<1.2.3', '1.2.3-beta'),
  266. array('=1.2.3', '1.2.3-beta'),
  267. array('>1.2', '1.2.8'),
  268. array('^1.2.3', '2.0.0-alpha'),
  269. array('^1.2.3', '1.2.2'),
  270. array('^1.2', '1.1.9'),
  271. // Invalid ranges are never satisfied
  272. array('blerg', '1.2.3'),
  273. array('git+https://user:password0123@github.com/foo', '123.0.0', true),
  274. array('^1.2.3', '2.0.0-pre')
  275. );
  276. foreach ($compare as $set) {
  277. $loose = isset($set[2]) && $set[2];
  278. $this->assertFalse(SemVer\G::satisfies($set[1], $set[0], $loose),
  279. "%s > $set[0] should not be satisfied by $set[1]");
  280. }
  281. }
  282. public function testIncrementVersions()
  283. {
  284. $compare = array(
  285. array("1.2.3", "major", "2.0.0"),
  286. array("1.2.3", "minor", "1.3.0"),
  287. array("1.2.3", "patch", "1.2.4"),
  288. array("1.2.3tag", "major", "2.0.0", true),
  289. array("1.2.3-tag", "major", "2.0.0"),
  290. array("1.2.3", "fake", null),
  291. array("fake", "major", null),
  292. array("1.2.3", "prerelease", "1.2.3-0"),
  293. array("1.2.3-0", "prerelease", "1.2.3-1"),
  294. array("1.2.3-alpha.0.beta", "prerelease", "1.2.3-alpha.1.beta"),
  295. array("1.2.3-alpha.1.beta", "prerelease", "1.2.3-alpha.2.beta"),
  296. array("1.2.3-alpha.2.beta", "prerelease", "1.2.3-alpha.3.beta"),
  297. array("1.2.3-alpha.10.0.beta", "prerelease", "1.2.3-alpha.10.1.beta"),
  298. array("1.2.3-alpha.10.1.beta", "prerelease", "1.2.3-alpha.10.2.beta"),
  299. array("1.2.3-alpha.10.2.beta", "prerelease", "1.2.3-alpha.10.3.beta"),
  300. array("1.2.3-alpha.10.beta.0", "prerelease", "1.2.3-alpha.10.beta.1"),
  301. array("1.2.3-alpha.10.beta.1", "prerelease", "1.2.3-alpha.10.beta.2"),
  302. array("1.2.3-alpha.10.beta.2", "prerelease", "1.2.3-alpha.10.beta.3"),
  303. array("1.2.3-alpha.9.beta", "prerelease", "1.2.3-alpha.10.beta"),
  304. array("1.2.3-alpha.10.beta", "prerelease", "1.2.3-alpha.11.beta"),
  305. array("1.2.3-alpha.12.beta", "prerelease", "1.2.3-alpha.13.beta")
  306. );
  307. foreach ($compare as $set) {
  308. $s = $set[0];
  309. $loose = isset($set[3]) && $set[3];
  310. $found = SemVer\G::inc($set[0], $set[1], $loose);
  311. $this->assertEquals($found, $set[2]);
  312. }
  313. }
  314. public function testValidRange()
  315. {
  316. $compare = array(
  317. array("1.0.0 - 2.0.0", ">=1.0.0 <=2.0.0"),
  318. array("1.0.0", "1.0.0"),
  319. array(">=*", ">=0.0.0-0"),
  320. array("", "*"),
  321. array("*", "*"),
  322. array(">=1.0.0", ">=1.0.0"),
  323. array(">1.0.0", ">1.0.0"),
  324. array("<=2.0.0", "<=2.0.0"),
  325. array("1", ">=1.0.0-0 <2.0.0-0"),
  326. array("<=2.0.0", "<=2.0.0"),
  327. array("<2.0.0", "<2.0.0-0"),
  328. array(">= 1.0.0", ">=1.0.0"),
  329. array(">= 1.0.0", ">=1.0.0"),
  330. array(">= 1.0.0", ">=1.0.0"),
  331. array("> 1.0.0", ">1.0.0"),
  332. array("> 1.0.0", ">1.0.0"),
  333. array("<= 2.0.0", "<=2.0.0"),
  334. array("<= 2.0.0", "<=2.0.0"),
  335. array("<= 2.0.0", "<=2.0.0"),
  336. array("< 2.0.0", "<2.0.0-0"),
  337. array("< 2.0.0", "<2.0.0-0"),
  338. array(">=0.1.97", ">=0.1.97"),
  339. array(">=0.1.97", ">=0.1.97"),
  340. array("0.1.20 || 1.2.4", "0.1.20||1.2.4"),
  341. array(">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1-0"),
  342. array(">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1-0"),
  343. array(">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1-0"),
  344. array("||", "||"),
  345. array("2.x.x", ">=2.0.0-0 <3.0.0-0"),
  346. array("1.2.x", ">=1.2.0-0 <1.3.0-0"),
  347. array("1.2.x || 2.x", ">=1.2.0-0 <1.3.0-0||>=2.0.0-0 <3.0.0-0"),
  348. array("x", "*"),
  349. array("2.*.*", '>=2.0.0-0 <3.0.0-0'),
  350. array("1.2.*", '>=1.2.0-0 <1.3.0-0'),
  351. array("1.2.* || 2.*", '>=1.2.0-0 <1.3.0-0||>=2.0.0-0 <3.0.0-0'),
  352. array("*", "*"),
  353. array("2", ">=2.0.0-0 <3.0.0-0"),
  354. array("2.3", ">=2.3.0-0 <2.4.0-0"),
  355. array("~2.4", ">=2.4.0-0 <2.5.0-0"),
  356. array("~>3.2.1", ">=3.2.1-0 <3.3.0-0"),
  357. array("~1", ">=1.0.0-0 <2.0.0-0"),
  358. array("~>1", ">=1.0.0-0 <2.0.0-0"),
  359. array("~> 1", ">=1.0.0-0 <2.0.0-0"),
  360. array("~1.0", ">=1.0.0-0 <1.1.0-0"),
  361. array("~ 1.0", ">=1.0.0-0 <1.1.0-0"),
  362. array("^0", ">=0.0.0-0 <1.0.0-0"),
  363. array("^ 1", ">=1.0.0-0 <2.0.0-0"),
  364. array("^0.1", ">=0.1.0-0 <0.2.0-0"),
  365. array("^1.0", ">=1.0.0-0 <2.0.0-0"),
  366. array("^1.2", ">=1.2.0-0 <2.0.0-0"),
  367. array("^0.0.1", "=0.0.1"),
  368. array("^0.0.1-beta", "=0.0.1-beta"),
  369. array("^0.1.2", ">=0.1.2-0 <0.2.0-0"),
  370. array("^1.2.3", ">=1.2.3-0 <2.0.0-0"),
  371. array("^1.2.3-beta.4", ">=1.2.3-beta.4 <2.0.0-0"),
  372. array("<1", "<1.0.0-0"),
  373. array("< 1", "<1.0.0-0"),
  374. array(">=1", ">=1.0.0-0"),
  375. array(">= 1", ">=1.0.0-0"),
  376. array("<1.2", "<1.2.0-0"),
  377. array("< 1.2", "<1.2.0-0"),
  378. array("1", ">=1.0.0-0 <2.0.0-0"),
  379. array(">01.02.03", ">1.2.3", true),
  380. array(">01.02.03", null),
  381. array("~1.2.3beta", ">=1.2.3-beta <1.3.0-0", true),
  382. array("~1.2.3beta", null),
  383. array("^ 1.2 ^ 1", ">=1.2.0-0 <2.0.0-0 >=1.0.0-0 <2.0.0-0")
  384. );
  385. foreach ($compare as $set) {
  386. $loose = isset($set[2]) && $set[2];
  387. $this->assertEquals(SemVer\G::validRange($set[0], $loose), $set[1]);
  388. }
  389. }
  390. public function testStrictVsLoose()
  391. {
  392. $compare = array(
  393. array('=1.2.3', '1.2.3'),
  394. array('01.02.03', '1.2.3'),
  395. array('1.2.3-beta.01', '1.2.3-beta.1'),
  396. array(' =1.2.3', '1.2.3'),
  397. array('1.2.3foo', '1.2.3-foo')
  398. );
  399. foreach ($compare as $set) {
  400. $ex = false;
  401. try {
  402. new SemVer\SemVer($set[0]);
  403. } catch (\Exception $e) {
  404. $ex = true;
  405. }
  406. $this->assertTrue($ex,
  407. "%s > Creating version with loose version $set[0], without loose flag set should throw exception.");
  408. $vers = new SemVer\SemVer($set[0], true);
  409. $this->assertEquals($vers->version->valueOf(), $set[1],
  410. "%s > (new version($set[0], true))->getVersion() == $set[1]");
  411. $this->assertTrue(SemVer\G::eq($set[0], $set[1], true), "%s > eq($set[0], $set[1], true)");
  412. $ex = false;
  413. try {
  414. SemVer\G::eq($set[0], $set[1]);
  415. } catch (\Exception $e) {
  416. $ex = true;
  417. }
  418. $this->assertTrue($ex, "%s > eq($set[0], $set[1]) should throw");
  419. }
  420. }
  421. }