semver.scm 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. ;;; guile-semver --- Semantic Version tooling for guile
  2. ;;; Copyright © 2017 Jelle Dirk Licht <jlicht@fsfe.org>
  3. ;;;
  4. ;;; This file is part of guile-semver.
  5. ;;;
  6. ;;; guile-semver is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or
  9. ;;; (at your option) any later version.
  10. ;;;
  11. ;;; guile-semver is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;;; General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with guile-semver. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-semver)
  19. #:use-module (semver parser)
  20. #:use-module (semver)
  21. #:use-module (semver parser-range)
  22. #:use-module (semver matcher)
  23. #:use-module (semver comparator)
  24. #:use-module (semver structs)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-64))
  27. (test-begin "invalid semver")
  28. (every (lambda (spec)
  29. (let ((msg (string-append
  30. "Invalid semver should not parse: "
  31. (object->string spec))))
  32. (test-assert msg (equal? (parse-semver spec) #f))))
  33. '(""
  34. "=1.2.3"
  35. "v0.9.2"
  36. "a.b.0"
  37. ;; "7.4.1-"
  38. "4.3.-"
  39. ;; "4.3.3-023.adsf"
  40. ;; "5.0.7+"
  41. ;; "2.2.3+build-alsobuild"
  42. ))
  43. (test-end "invalid semver")
  44. (test-begin "valid semver")
  45. (every (lambda (spec)
  46. (let ((msg (string-append
  47. "Valid semver should parse: "
  48. (object->string spec))))
  49. (test-assert msg (valid? spec))))
  50. '("1.2.3"
  51. "0.9.2"
  52. "9.8.7"
  53. "0.8.7-pre"
  54. "0.8.0-beta.3"
  55. "0.8.7-pre-release-identifier-is-long"
  56. "8.2.1-pre.with.0.working"
  57. "8.2.1-pre.with.7.working"
  58. "2.8.4+32"
  59. "2.8.4+git.build.23232"
  60. "0.8.0-beta.3+ci.generated"
  61. ))
  62. (test-end "valid semver")
  63. (test-begin "inc semver")
  64. (every (lambda (spec)
  65. (let ((msg (string-append
  66. "Incremented semver" " should e: "
  67. (object->string spec))))
  68. (test-assert msg (parse-semver spec))))
  69. '("1.2.3"
  70. "0.9.2"
  71. "9.8.7"
  72. "0.8.7-pre"
  73. "0.8.0-beta.3"
  74. "0.8.7-pre-release-identifier-is-long"
  75. "8.2.1-pre.with.0.working"
  76. "8.2.1-pre.with.7.working"
  77. "2.8.4+32"
  78. "2.8.4+git-build-23232"))
  79. (test-end "inc semver")
  80. (test-begin "gt")
  81. (every (lambda (spec)
  82. (let ((msg (object->string spec)))
  83. (test-assert msg (apply gt spec))))
  84. '(("1.0.1" "1.0.0")
  85. ("0.6.10" "0.6.1")))
  86. (test-end "gt")
  87. (test-begin "in range")
  88. (every (lambda (spec)
  89. (let ((msg (object->string spec)))
  90. (test-assert msg (apply satisfies (reverse spec)))))
  91. '(("=1.0.0" "1.0.0")
  92. ("~0.6.1" "0.6.1")
  93. ("1.0.0 - 2.0.0" "1.2.3")
  94. ("1.0.0" "1.0.0")
  95. (">=0.0.0" "0.2.4")
  96. ("X" "1.0.0")
  97. ("*" "1.2.3")
  98. ("*" "1.2.3")
  99. (">=1.0.0" "1.0.0")
  100. (">=1.0.0" "1.0.1")
  101. (">=1.0.0" "1.1.0")
  102. (">1.0.0" "1.0.1")
  103. (">1.0.0" "1.1.0")
  104. ("<=2.0.0" "2.0.0")
  105. ("<=2.0.0" "1.9999.9999")
  106. ("<=2.0.0" "0.2.9")
  107. ("<2.0.0" "1.9999.9999")
  108. ("<2.0.0" "0.2.9")
  109. (">= 1.0.0" "1.0.0")
  110. (">= 1.0.0" "1.0.1")
  111. (">= 1.0.0" "1.1.0")
  112. ("> 1.0.0" "1.0.1")
  113. ("> 1.0.0" "1.1.0")
  114. ("<= 2.0.0" "2.0.0")
  115. ("<= 2.0.0" "1.9999.9999")
  116. ("<= 2.0.0" "0.2.9")
  117. ("< 2.0.0" "1.9999.9999")
  118. ("<\t2.0.0" "0.2.9")
  119. (">=0.1.97" "0.1.97")
  120. (">=0.1.97" "0.1.97")
  121. ("0.1.20 || 1.2.4" "1.2.4")
  122. ("0.1.20 || >=1.2.4" "1.2.4")
  123. ("0.1.20 || <1.2.4" "1.2.3")
  124. ("0.1.20 || 1.2.4" "0.1.20")
  125. (">=0.2.3 || <0.0.1" "0.0.0")
  126. (">=0.2.3 || <0.0.1" "0.2.3")
  127. (">=0.2.3 || <0.0.1" "0.2.4")
  128. ("x || x" "1.3.4")
  129. ("2.x.x" "2.1.3")
  130. ("1.2.x" "1.2.3")
  131. ("1.2.x || 2.x" "2.1.3")
  132. ("1.2.x || 2.x" "1.2.3")
  133. ("x" "1.2.3")
  134. ("2.*.*" "2.1.3")
  135. ("1.2.*" "1.2.3")
  136. ("1.2.* || 2.*" "2.1.3")
  137. ("1.2.* || 2.*" "1.2.3")
  138. ("1.2.* || 2.*" "1.2.3")
  139. ("*" "1.2.3")
  140. ("2" "2.1.2")
  141. ("2.3" "2.3.1")
  142. ("~2.4" "2.4.0")
  143. ("~2.4" "2.4.5")
  144. (">3.2.1" "3.2.2")
  145. ("~1" "1.2.3")
  146. ("~1" "1.2.3")
  147. ("~ 1" "1.2.3")
  148. ("~1.0" "1.0.2")
  149. ("~ 1.0" "1.0.2")
  150. (">=1" "1.0.0")
  151. (">= 1" "1.0.0")
  152. ("<1.2" "1.1.1")
  153. ("< 1.2" "1.1.1")
  154. ("1" "1.0.0")
  155. ("~0.5.4" "0.5.5")
  156. ("~0.5.4" "0.5.4")
  157. ("0.7.x" "0.7.2")
  158. (">=0.7.0" "0.7.2")
  159. ("0.7.x" "0.7.0")
  160. (">=0.7.0" "0.7.0")
  161. ("<=0.7.0" "0.6.2")
  162. (">0.2.3 >0.2.4 <=0.2.5" "0.2.5")
  163. (">=0.2.3 <=0.2.4" "0.2.4")
  164. ("1.0.0 - 2.0.1" "2.0.0")
  165. ("^1" "1.0.0")
  166. ("^0.0.0" "0.0.0")
  167. ("^1.0.0 || ~2.0.1" "2.0.10")
  168. ("^0.1.0 || ^3.0 || 5.0.0" "3.1.0")
  169. ("^0.1.0 || ~3.0.1 || 5.0.0" "5.0.0")
  170. ("<1.0.0 || <3.0.1 || <5.0.0 || <6.0.0 || 9.0.0" "9.0.0")
  171. ("^1.2.x" "1.99.99")
  172. (">=1.2.0 <2.0.0" "1.99.99")
  173. ("^0.0.x" "0.0.0")
  174. ("^0.0.x" "0.0.99")
  175. ("^0.0" "0.0.0")
  176. ("^0.0" "0.0.99")
  177. ("^1.*" "1.0.0")
  178. ("^1.*" "1.99.99")))
  179. (test-end "in range")
  180. (test-begin "not in range")
  181. (every (lambda (spec)
  182. (let ((msg (object->string spec)))
  183. (test-assert msg (not (apply satisfies (reverse spec))))))
  184. '(("=1.1.0" "1.0.0")
  185. ("~1.2.2" "1.3.0")
  186. ("~0.6.1" "0.7.1")
  187. ("1.0.0 - 2.0.0" "2.0.1")
  188. ("1.0.0" "1.0.1")
  189. ("1.0.0" "2.0.0")
  190. ("<=2.0.0" "2.1.1")
  191. ("<=2.0.0" "3.2.9")
  192. ("<2.0.0" "2.0.0")
  193. ("0.1.20 || 1.2.4" "1.2.5")
  194. ("2.x.x" "3.0.0")
  195. ("1.2.x" "1.3.0")
  196. ("1.2.x || 2.x" "3.0.0")
  197. ("2.*.*" "5.0.1")
  198. ("1.2.*" "1.3.3")
  199. ("1.2.* || 2.*" "4.0.0")
  200. ("2" "3.0.0")
  201. ("2.3" "2.4.2")
  202. ("~2.4.0" "2.5.0")
  203. ("~2.4.0" "2.5.5")
  204. ("~3.2.1" "3.3.0")
  205. ("~1.0.0" "2.2.3")
  206. ("~1.0.0" "2.2.4")
  207. ("~1.0.0" "3.2.3")
  208. ("~1.0.0" "1.1.2")
  209. ("~1.0.0" "1.1.0")
  210. ("<1.2.0" "1.2.0")
  211. ("<1.2.0" "1.2.1")
  212. ("1" "2.0.0")
  213. ("~0.5.4" "0.6.0")
  214. ("~0.5.4" "0.6.1")
  215. ("0.7.x" "0.8.0")
  216. ("<0.7.0" "0.7.0")
  217. ("~1.2.2" "1.3.0")
  218. ("1.0.0 - 2.0.0" "2.2.3")
  219. ("1.0.0" "1.0.1")
  220. ("<=2.0.0" "3.0.0")
  221. ("<=2.0.0" "2.9999.9999")
  222. ("<=2.0.0" "2.2.9")
  223. ("<2.0.0" "2.9999.9999")
  224. ("<2.0.0" "2.2.9")
  225. ("2.x.x" "3.1.3")
  226. ("1.2.x" "1.3.3")
  227. ("1.2.x || 2.x" "3.1.3")
  228. ("2.*.*" "3.1.3")
  229. ("1.2.*" "1.3.3")
  230. ("1.2.* || 2.*" "3.1.3")
  231. ("2" "3.1.2")
  232. ("2.3" "2.4.1")
  233. ("~2.4.0" "2.5.0")
  234. ("~3.2.1" "3.3.2")
  235. ("~1.0.0" "2.2.3")
  236. ("~1.0.0" "2.2.3")
  237. ("~1.0.0" "1.1.0")
  238. ("<1.0.0" "1.0.0")
  239. ("1" "2.0.0")
  240. ("<1.0.0" "1.0.0")
  241. ("<1.0.0" "1.0.0")
  242. ("<1.0.0 || <3.0.1 || <5.0.0 || <6.0.0 || >9.1.0" "9.0.0")
  243. ("<1.0.0 > 10.0 || 5.0" "5.1.0")
  244. ("0.7.x" "0.8.2")))
  245. (test-end "not in range")
  246. (test-begin "increment semver")
  247. (every (lambda (spec)
  248. (let ((msg (string-append
  249. "Incremented semver does not match:"
  250. (object->string spec))))
  251. (test-assert msg (zero? (semantic-version-compare
  252. (inc-semantic-version (parse-semver (car spec)) (cadr spec))
  253. (parse-semver (caddr spec)))))))
  254. '(("0.0.0" patch "0.0.1")
  255. ("2.3.4" patch "2.3.5")
  256. ("9.5.1" minor "9.6.0")
  257. ("0.4.12+beta" minor "0.5.0")
  258. ("0.1.12+beta-xorg" major "1.0.0")
  259. ("2.3.1" major "3.0.0")
  260. ("1.2.3" premajor "2.0.0-0")
  261. ("0.1.7" premajor "1.0.0-0")
  262. ("4.5.6" preminor "4.6.0-0")
  263. ("9.8.7" preminor "9.9.0-0")
  264. ("0.5.9" prepatch "0.5.10-0")
  265. ("5.0.0" prepatch "5.0.1-0")
  266. ("1.0.0" prerelease "1.0.0-0")
  267. ("2.0.0-3" prerelease "2.0.0-4")
  268. ("3.2.1-beta" prerelease "3.2.1-beta.0")
  269. ("3.2.1-beta.13" prerelease "3.2.1-beta.14")
  270. ;; premajor
  271. ;; preminor
  272. ;; prepatch
  273. ;; prerelease
  274. ))
  275. (test-end "increment semver")