Changeset 39840 in project


Ignore:
Timestamp:
04/05/21 07:50:57 (4 months ago)
Author:
Kon Lovett
Message:

add srfi-69 hash & version=?... & srfi-128 comparator

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

Legend:

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

    r39834 r39840  
    77 (author "Kon Lovett")
    88 (license "BSD")
    9  (dependencies srfi-1 (string-utils "2.5.0"))
     9 (dependencies srfi-1 srfi-128 (string-utils "2.5.0"))
    1010 (test-dependencies test)
    1111 (components
  • release/5/semantic-version/trunk/semantic-version.scm

    r39839 r39840  
    1313  version-valid?
    1414  version-compare
     15  version<? version=? version>? version<=? version>=?
     16  version-hash
     17  version-comparator
    1518  version-parse
    1619  version-string
    1720  version-parts
    1821  version-puncs
    19   version-inc!
    20   version-dec!
    21   version-inc
    22   version-dec)
     22  version-inc! version-dec!
     23  version-inc version-dec)
    2324
    2425(import scheme
     
    2829  (only (chicken string) ->string string-compare3)
    2930  (only (srfi 1) make-list list-copy drop-while map! reverse! every)
     31  (only (srfi 69) equal?-hash)
     32  (only (srfi 128) make-comparator)
    3033  string-utils)
    3134
     
    130133            cmp ) ) ) ) ) )
    131134
     135(define (version<? ver1 ver2 #!key (tail-zero? #f))
     136  (negative? (version-compare ver1 ver2 #:tail-zero? tail-zero?)) )
     137
     138(define (version=? ver1 ver2 #!key (tail-zero? #f))
     139  (zero? (version-compare ver1 ver2 #:tail-zero? tail-zero?)) )
     140
     141(define (version>? ver1 ver2 #!key (tail-zero? #f))
     142  (positive? (version-compare ver1 ver2 #:tail-zero? tail-zero?)) )
     143
     144(define (version<=? ver1 ver2 #!key (tail-zero? #f))
     145  (<= (version-compare ver1 ver2 #:tail-zero? tail-zero?) 0) )
     146
     147(define (version>=? ver1 ver2 #!key (tail-zero? #f))
     148  (>= (version-compare ver1 ver2 #:tail-zero? tail-zero?) 0) )
     149
     150;srfi-69
     151(define-constant hash-default-bound 536870912)
     152
     153(define (version-hash ver #!optional (bnd hash-default-bound))
     154  (equal?-hash ver bnd) )
     155
     156(define (version-comparator)
     157  (make-comparator version-valid? version=? version<? version-hash) )
     158
    132159(define (version-parse str)
    133160  (define (str/num x) (or (string->number x) x))
  • release/5/semantic-version/trunk/tests/semantic-version-test.scm

    r39839 r39840  
    3434(test-assert (zero? (version-compare (make-version 1 2 3) (make-version 1 2 3 0))))
    3535
     36;;
     37
     38(import (srfi 128))
     39
     40(let ((cmptr (version-comparator)))
     41  (test-assert (comparator-test-type cmptr (make-version "a" 2 "c")))
     42  (glossf "Hash: ~A" (comparator-hash cmptr (make-version "a" 2 "c")))
     43  (test-assert (<? cmptr (make-version 1 2 3) (make-version 1 11 3)))
     44  (test-assert (=? cmptr (make-version 1 2 3) (make-version 1 2 3)))
     45  (test-assert (>=? cmptr (make-version 1 11 3) (make-version 1 2 3))) )
     46
    3647;;;
    3748
Note: See TracChangeset for help on using the changeset viewer.