Changeset 40364 in project


Ignore:
Timestamp:
08/21/21 17:40:52 (5 weeks ago)
Author:
Kon Lovett
Message:

add strict= & test, add test for trailing 0s w/ hash

Location:
release/5/semantic-version/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/5/semantic-version/trunk/semantic-version.compare.scm

    r40352 r40364  
    2121  version<? version=? version>? version<=? version>=?
    2222  version-hash
    23   ;version*<? version*=? version*>? version*<=? version*>=?
    24   #;version*-hash)
     23  version-strict=?)
    2524
    2625(import scheme
     
    4746(: version>=?           (ver ver #!optional boolean --> boolean))
    4847(: version-hash         (ver #!rest --> integer))
     48(: version-strict=?     (ver ver #!optional boolean --> boolean))
    4949
    5050;;
     
    6060(define (drop-tailing-zeros ls) (reverse! (drop-while number-zero? (reverse ls))))
    6161
     62(define (tail-zeros ls tail-zero?) (if tail-zero? ls (drop-tailing-zeros ls)))
     63
    6264;;
    6365
    6466(define (version-compare ver1 ver2 #!optional (tail-zero? (version-tail-zero)))
    65   ;
    66   (define (tail-zeros ls) (if tail-zero? ls (drop-tailing-zeros ls)))
    67   ;
    68   (let loop ((p1 (tail-zeros (ver-parts (check-version 'version-compare ver1 'ver1))))
    69              (p2 (tail-zeros (ver-parts (check-version 'version-compare ver2 'ver2)))))
     67  (let loop (
     68    (p1 (tail-zeros (ver-parts (check-version 'version-compare ver1 'ver1)) tail-zero?))
     69    (p2 (tail-zeros (ver-parts (check-version 'version-compare ver2 'ver2)) tail-zero?)))
    7070    (cond
    7171      ((and (null? p1) (null? p2))  0)
     
    7878      ((number? (car p1))           -1)
    7979      ((number? (car p2))           1)
    80       ((string-compare3 ( canon-compare-elm (car p1)) ( canon-compare-elm (car p2))) =>
     80      ((string-compare3 (canon-compare-elm (car p1)) (canon-compare-elm (car p2))) =>
    8181        (lambda (cmp)
    8282          (if (zero? cmp) (loop (cdr p1) (cdr p2))
     
    9999
    100100(define (version-hash ver . rest)
    101   (define (tail-zeros ls) (if (version-tail-zero) ls (drop-tailing-zeros ls)))
    102   (apply equal?-hash (tail-zeros (ver-parts (check-version 'version-hash ver))) rest) )
     101  (apply equal?-hash (tail-zeros (ver-parts (check-version 'version-hash ver)) (version-tail-zero)) rest) )
    103102
    104 #;
    105 (define (version*=? ver1 ver2 #!optional (tail-zero? (version-tail-zero)))
     103(define (version-strict=? ver1 ver2 #!optional (tail-zero? (version-tail-zero)))
    106104  (and
    107     (zero? (version-compare ver1 ver2 tail-zero?))
    108     (equal? (ver-puncs1 ver) (ver-puncs ver2))) )
    109 
    110 #;
    111 (define (version*-hash ver . rest)
    112   (equal?-hash (check-version 'version-hash* ver) rest) )
     105    (version=? ver1 ver2 tail-zero?)
     106    (equal? (ver-puncs ver1) (ver-puncs ver2))) )
    113107
    114108) ;module semantic-version.compare
  • release/5/semantic-version/trunk/semantic-version.egg

    r40352 r40364  
    33
    44((synopsis "Semantic Version Utilities")
    5  (version "0.0.4")
     5 (version "0.0.5")
    66 (category data)
    77 (author "Kon Lovett")
  • release/5/semantic-version/trunk/tests/semantic-version-test.scm

    r40352 r40364  
    6464  (test-assert (>=? cmptr (version 1 11 3) (version 1 2 3))) )
    6565
     66(let ((ver1 (string->version "1.2.1")) (ver2 (string->version "1.2;1")))
     67  (test-assert (version=? ver1 ver2))
     68  (test-assert "1.2.1 <> 1.2;1" (not (version-strict=? ver1 ver2))) )
     69
    6670;;
    6771
     
    7175  (test 'one (hash-table-ref ht (version "a" 2 "c")))
    7276  (test 'two (hash-table-ref ht (version 1 2 3 0)))
    73   (test-error "not found" (hash-table-ref ht (version 'a 'd))) )
     77  (test-error "not found" (hash-table-ref ht (version 'a 'd)))
     78  (let ((ver (string->version "1.2;1.0.0")))
     79    (test-assert "version-tail-zero influences hash"
     80      (not (= (version-hash ver) (parameterize ((version-tail-zero #t)) (version-hash ver))))) ) )
    7481
    7582;;;
Note: See TracChangeset for help on using the changeset viewer.