Changeset 39846 in project


Ignore:
Timestamp:
04/05/21 10:29:17 (6 weeks ago)
Author:
Kon Lovett
Message:

hash must handle 0's, replace glosses w/ tests, use std pred name, export check-version, test hash-table

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

Legend:

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

    r39844 r39846  
    1212  version-tail-zero
    1313  make-version
    14   version-valid?
     14  version? check-version
    1515  version-compare
    1616  version<? version=? version>? version<=? version>=?
     
    4848
    4949(: make-version         (#!rest ver-part --> ver))
     50(: version?             (ver --> boolean))
    5051(: version-compare      (ver ver #!optional boolean --> integer))
    5152(: version<?            (ver ver #!optional boolean --> boolean))
     
    5657(: version-hash         (ver #!rest --> integer))
    5758(: version-comparator   (--> (struct comparator)))
    58 (: version-valid?       (ver --> boolean))
    5959(: version-parse        (string --> ver))
    6060(: version-string       (ver --> string))
     
    7979(define (copy-ver v)      (make-ver (list-copy (ver-parts v)) (ver-puncs v)))
    8080
    81 (define (ver-parts? x) (and (list? x) (every ver-part? x)))
    82 (define (ver-puncs? x) (and (list? x) (every ver-punc? x)))
     81(define (ver-parts? x) (every ver-part? x))
     82(define (ver-puncs? x) (every ver-punc? x))
    8383
    8484(define (check-parts loc x)
     
    117117    (make-ver parts (default-puncs parts))) )
    118118
    119 (define (version-valid? ver)
     119(define (version? ver)
    120120  (and
    121121    (ver? ver)
     
    163163
    164164(define (version-hash ver . rest)
    165   (apply equal?-hash (ver-parts (check-version 'version-hash ver)) rest) )
     165  (define (tail-zeros ls) (if (version-tail-zero) ls (drop-tailing-zeros ls)))
     166  (apply equal?-hash (tail-zeros (ver-parts (check-version 'version-hash ver))) rest) )
    166167
    167168#;
     
    176177
    177178(define (version-comparator)
    178   (make-comparator version-valid? version=? version<? version-hash) )
     179  (make-comparator version? version=? version<? version-hash) )
    179180
    180181(define (version-parse str)
  • release/5/semantic-version/trunk/tests/semantic-version-test.scm

    r39844 r39846  
    1313
    1414(test-error (make-version 'a 2 #\c))
    15 (test-assert (version-valid? (make-version "a" 2 "c")))
     15(test-assert (version? (make-version "a" 2 "c")))
    1616
    1717;assumes 1st is always "."
    1818(test (make-version "a" 2 "c") (version-parse "a.2.c"))
    1919
    20 (test-assert (version-valid? (version-parse "a.2,c")))
     20(test-assert (version? (version-parse "a.2,c")))
    2121(test "a.2,c" (version-string (version-parse "a.2,c")))
    2222(let ((ver "a.2,c"))
    23   (glossf "~S Parts: ~S" ver (version-parts (version-parse ver)))
    24   (glossf "~S Puncs: ~S" ver (version-puncs (version-parse ver))) )
     23  (test '("a" 2 "c") (version-parts (version-parse ver)))
     24  (test '(#\. #\,) (version-puncs (version-parse ver))) )
    2525
    2626(test "inc of -# is dec" (make-version "a" 1 "c") (version-inc (make-version "a" 2 "c") 1 -1))
     
    4040(let ((cmptr (version-comparator)))
    4141  (test-assert (comparator-test-type cmptr (make-version "a" 2 "c")))
    42   (glossf "Hash: ~A" (comparator-hash cmptr (make-version "a" 2 "c")))
     42  (test-assert (integer? (comparator-hash cmptr (make-version "a" 2 "c"))))
    4343  (test-assert (<? cmptr (make-version 1 2 3) (make-version 1 11 3)))
    4444  (test-assert (=? cmptr (make-version 1 2 3) (make-version 1 2 3)))
    4545  (test-assert (>=? cmptr (make-version 1 11 3) (make-version 1 2 3))) )
     46
     47;;
     48
     49(import (srfi 69))
     50
     51(let ((ht (make-hash-table version=? version-hash 10)))
     52  (hash-table-set! ht (make-version "a" 2 "c") 'one)
     53  (hash-table-set! ht (make-version 1 2 3 0) 'two)
     54  (test 'one (hash-table-ref ht (make-version "a" 2 "c")))
     55  (test 'two (hash-table-ref ht (make-version 1 2 3 0)))
     56  (test-error "not found" (hash-table-ref ht (make-version 'a 'd))) )
    4657
    4758;;;
Note: See TracChangeset for help on using the changeset viewer.