* Deal with NNNpN versions as N.NN.N (eg, 103p1 => 1.03.1),
* Some more sane checks -- refuse old-style versions when it's higer than 380 * Added tests for these * Move sanity check to tests (where it will do the same since it runs every day) svn: r11397
This commit is contained in:
parent
b987dc265d
commit
b5fb8569cc
|
@ -5,6 +5,16 @@
|
|||
|
||||
(require version/utils)
|
||||
|
||||
;; sanity check
|
||||
(unless (and (< (string->number (car (regexp-match #rx"^[0-9]+" (version)))) 49)
|
||||
(integer? (version->integer (version))))
|
||||
;; When this happens, we got to numbers that can be confused with old version
|
||||
;; numbers, and the version/utils code should be modified. With the current
|
||||
;; rate of changes, this should happen in more 150 years. Either programming
|
||||
;; is probably done with a direct brain link, or this software has nobody to
|
||||
;; fix it because everybody went back to the trees.
|
||||
(error 'version/utils.ss "this file should be updated"))
|
||||
|
||||
(test #t valid-version? (version))
|
||||
(for-each (lambda (v+i) (test (cadr v+i) version->integer (car v+i)))
|
||||
'(;; legacy version scheme
|
||||
|
@ -15,6 +25,9 @@
|
|||
["123.4" 123004000]
|
||||
["49" 49000000] ; oldest legacy-version supported
|
||||
["103" 103000000]
|
||||
["103p1" 103001000] ; pN used as sub-sub-version
|
||||
["380" #f] ; old style, but these versions never existed
|
||||
["400" #f]
|
||||
;; new version scheme
|
||||
["4.0" 400000000]
|
||||
["4" #f] ; must have one decimal digit
|
||||
|
@ -47,6 +60,7 @@
|
|||
["foo" #f]
|
||||
["x.y" #f]
|
||||
["0" #f]
|
||||
["00" #f]
|
||||
))
|
||||
|
||||
(report-errs)
|
||||
|
|
|
@ -41,33 +41,23 @@
|
|||
|
||||
;; returns an integer representing the version (XXYYZZZWWW) or #f if invalid
|
||||
;; works for pre v4 versions too
|
||||
(define (version->integer v)
|
||||
(cond
|
||||
[(regexp-match-positions #rx"^(?:0|[1-9][0-9]*)" v) ; takes all digits
|
||||
=> (lambda (m)
|
||||
(let* (;; translate to a new-style version
|
||||
[n (string->number (substring v 0 (cdar m)))]
|
||||
[v (if (< n 49)
|
||||
v
|
||||
(let-values ([(q r) (quotient/remainder n 100)])
|
||||
;; put numbers and possible .N leftover
|
||||
(format "~a.~a~a" q r (substring v (cdar m)))))])
|
||||
(and (valid-version? v)
|
||||
(let ([l (version->list v)])
|
||||
(let loop ([v (car l)]
|
||||
[l (cdr l)]
|
||||
[f '(100 1000 1000)])
|
||||
(if (null? l)
|
||||
v
|
||||
(loop (+ (* v (car f)) (car l)) (cdr l) (cdr f))))))))]
|
||||
[else #f]))
|
||||
|
||||
;; general sanity check, performed once when loaded
|
||||
(unless (and (< (string->number (car (regexp-match #rx"^[0-9]+" (version)))) 49)
|
||||
(integer? (version->integer (version))))
|
||||
;; When this happens, we got to numbers that can be confused with old version
|
||||
;; numbers, and the above code should be modified. With the current rate of
|
||||
;; changes, this should happen in more 150 years. Either programming is
|
||||
;; probably done with a direct brain link, or this software has nobody to fix
|
||||
;; it because everybody went back to the trees.
|
||||
(error 'version/utils.ss "this file should be updated"))
|
||||
(define (version->integer ver)
|
||||
(define m
|
||||
(regexp-match-positions #rx"^(?:0|[1-9][0-9]*)" ver)) ; takes all digits
|
||||
;; translate old versions to new-style versions
|
||||
(define n (and m (string->number (substring ver 0 (cdar m)))))
|
||||
(define v
|
||||
(cond [(not n) #f]
|
||||
;; new versions
|
||||
[(< n 49) ver]
|
||||
;; old versions (earliest useful is 49, changed at 3.99)
|
||||
[(<= 49 n 379)
|
||||
(let-values ([(q r) (quotient/remainder n 100)])
|
||||
;; put numbers and a possible .N leftover (done for pN too)
|
||||
(format "~a.~a~a" q r
|
||||
(regexp-replace #rx"^p" (substring ver (cdar m)) ".")))]
|
||||
;; bad strings
|
||||
[else #f]))
|
||||
(and (valid-version? v)
|
||||
(foldl (lambda (ver mul acc) (+ ver (* mul acc))) 0
|
||||
(version->list v) '(0 100 1000 1000))))
|
||||
|
|
Loading…
Reference in New Issue
Block a user