Changeset 39848 in project


Ignore:
Timestamp:
04/05/21 19:25:18 (6 weeks ago)
Author:
Kon Lovett
Message:

only string internally, add version-depth query, test punct invariance

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

Legend:

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

    r39845 r39848  
    99
    1010Semantic-Version handling.
     11
     12== Usage
     13
     14<enscript highlight="scheme">
     15(import semantic-version)
     16</enscript>
    1117
    1218=== version-punctuation
     
    1723default.
    1824
     25; STR : {{string}} ; default is "._- +;:,"
     26
    1927=== version-tail-zero
    2028
     
    2735<procedure>(make-version ELM...) --> version</procedure>
    2836
    29 Returns a new version with the specified elements and the default punctuation.
    30 
    31 ; ELM : {{(or number string symbol)}} ; version element.
     37Returns a new version with the specified elements, ELM..., and the default
     38punctuation (see {{version-punctuation}}).
     39
     40; ELM : {{(or number string symbol)}} ; version element. but {{symbol}} printname used.
    3241
    3342=== version-compare
     
    3645
    3746Returns a negative, zero, or positive integer representing the relative order
    38 of VER1 and VER2.
     47of VER1 and VER2. Compares {{number}} & {{string}} elements ''natively'', but
     48in a comparison between a {{number}} & a {{string}} element, the {{string}}
     49always takes precedence. Thus {{"1.a.2" < "a.1.2"}}.
    3950
    4051; VER1 : {{version}} ; version 1 to compare.
    4152; VER2 : {{version}} ; version 2 to compare.
    4253; TAIL-ZERO? : {{boolean}} ; ignore trailing 0's?
     54
     55Orders versions in the same manner as the ''chicken-install'' tool.
    4356
    4457=== version<?
     
    4861=== version>=?
    4962
    50 <procedure>(version<? VER VER [TAIL-ZERO?]) --> boolean</procedure>
    51 <procedure>(version=? VER VER [TAIL-ZERO?]) --> boolean</procedure>
    52 <procedure>(version>? VER VER [TAIL-ZERO?]) --> boolean</procedure>
    53 <procedure>(version<=? VER VER [TAIL-ZERO?]) --> boolean</procedure>
    54 <procedure>(version>=? VER VER [TAIL-ZERO?]) --> boolean</procedure>
     63<procedure>(version<? VER1 VER2 [TAIL-ZERO?]) --> boolean</procedure>
     64<procedure>(version=? VER1 VER2 [TAIL-ZERO?]) --> boolean</procedure>
     65<procedure>(version>? VER1 VER2 [TAIL-ZERO?]) --> boolean</procedure>
     66<procedure>(version<=? VER1 VER2 [TAIL-ZERO?]) --> boolean</procedure>
     67<procedure>(version>=? VER1 VER2 [TAIL-ZERO?]) --> boolean</procedure>
    5568
    5669See {{version-compare}}.
     
    6073<procedure>(version-hash VER [BND RND]) --> integer</procedure>
    6174
     75A SRFI 69 compliant hash function for the {{version}} type.
     76
    6277; VER : {{version}} ; version to hash.
    63 ; BND : {{integer}} ; see SRFI 69.
    64 ; RND : {{integer}} ; see SRFI 69.
     78; BND : {{integer}} ; bounds (limit), see SRFI 69.
     79; RND : {{integer}} ; randomization (salt), see SRFI 69.
    6580
    6681=== version-comparator
     
    6883<procedure>(version-comparator) --> comparator</procedure>
    6984
     85Returns a SRFI 128 {{comparator}} for the {{version}} type.
     86
    7087=== version-valid?
    7188
    72 <procedure>(version-valid? VER) --> boolean</procedure>
     89<procedure>(version? OBJ) --> boolean</procedure>
     90
     91; OBJ : {{*}} ; object to test.
     92
     93=== version-parse
     94
     95<procedure>(version-parse STR) --> version</procedure>
     96
     97Return the parsed form of the STR. The source separator (punctuation) is
     98preserved, and restored by {{version-string}}.
     99
     100; STR : {{string}} ; version string.
     101
     102=== version-string
     103
     104<procedure>(version-string VER) --> string</procedure>
     105
     106Return the string form of the VER.
    73107
    74108; VER : {{version}} ; version to hash.
    75109
    76 === version-parse
    77 
    78 <procedure>(version-parse STR) --> version</procedure>
    79 
    80 Return the parsed form of the STR.
    81 
    82 ; STR : {{string}} ; version string.
    83 
    84 === version-string
    85 
    86 <procedure>(version-string VER) --> string</procedure>
    87 
    88 Return the string form of the VER.
    89 
    90 ; VER : {{version}} ; version to hash.
     110=== version-depth
     111
     112<procedure>(version-depth VER) --> integer</procedure>
     113
     114Return the number of elements in the version.
     115
     116; VER : {{version}} ; version to query.
    91117
    92118=== version-parts
     
    96122Returns list of version elements.
    97123
    98 ; VER : {{version}} ; version.
     124; VER : {{version}} ; version to query.
    99125
    100126=== version-puncs
     
    104130Returns list of separator characters.
    105131
    106 ; VER : {{version}} ; version.
     132; VER : {{version}} ; version to query.
    107133
    108134=== version-inc!
     
    116142; AMOUNT : {{number}} ; amount to adjust.
    117143
     144Currently only {{number}} elements may be targets.
     145
    118146=== version-dec!
    119147
     
    126154; AMOUNT : {{number}} ; amount to adjust.
    127155
     156Currently only {{number}} elements may be targets.
     157
    128158=== version-inc
    129159
     
    136166; AMOUNT : {{number}} ; amount to adjust.
    137167
     168Currently only {{number}} elements may be targets.
     169
    138170=== version-dec
    139171
     
    146178; AMOUNT : {{number}} ; amount to adjust.
    147179
    148 
    149 == Usage
    150 
     180Currently only {{number}} elements may be targets.
     181
     182
     183== Example
    151184<enscript highlight="scheme">
    152 (import semantic-version)
     185(import (chicken base) (chicken file) (chicken pathname) (chicken sort)
     186        (srfi 1)
     187        semantic-version)
     188
     189(define (egg-repo-versions repo egg)
     190  (map! (o version-parse pathname-strip-directory)
     191        (glob (make-pathname `(,repo ,egg "tags") "*"))) )
     192
     193(for-each (o print version-string) (sort (egg-repo-versions REPO "apropos") version<?))
     194;=> prints release versions in ascending order
     195
     196(string=? "a.1,b" ((o version-string version-parse) "a.1,b"))
     197;=> #t
     198; but, assuming baseline `version-punctuation'
     199(string=? "a.1.b" (version-string (make-version 'a 1 'b)))
     200;=> #t
     201
     202(define ver1 (make-version 'a 1 'b 2))
     203((o print version-string) ver1)
     204;=> "a.1.b.2"
     205(version-inc! ver1)
     206((o print version-string) ver1)
     207;=> "a.1.b.3"
     208(version-dec! ver1 1)
     209((o print version-string) ver1)
     210;=> "a.0.b.3"
    153211</enscript>
    154212
  • release/5/semantic-version/trunk/semantic-version.scm

    r39846 r39848  
    55;;
    66;; - Support Roman Numerals & Upper/Lowercase Letters ("outline numbers").
     7;;
     8;; - Change representation to record w/ vector "arms".
     9;;
     10;; - Add cardinality operations?
    711
    812(module semantic-version
     
    2125  version-parse
    2226  version-string
     27  version-depth
    2328  version-parts
    2429  version-puncs
     
    3843;;
    3944
     45;NOTE symbols are not preserved; the printname is used!
    4046(define-type ver-part  (or number string symbol))
    4147(define-type ver-punc  char)
     
    5965(: version-parse        (string --> ver))
    6066(: version-string       (ver --> string))
     67(: version-depth        (ver --> integer))
    6168(: version-parts        (ver --> ver-parts))
    6269(: version-puncs        (ver --> ver-puncs))
     
    7077;semantic-version type
    7178
     79;NOTE symbols are not preserved; the printname is used!
    7280(define (ver-part? x) (or (number? x) (string? x) (symbol? x)))
    7381(define (ver-punc? x) (char? x))
     
    115123(define (make-version . parts)
    116124  (if (null? (check-parts 'make-version parts)) (make-ver '() '())
    117     (make-ver parts (default-puncs parts))) )
     125    (let ((parts (map (lambda (x) (if (symbol? x) (symbol->string x) x)) parts)))
     126      (make-ver parts (default-puncs parts))) ) )
    118127
    119128(define (version? ver)
     
    188197  (string-zip (map ->string (ver-parts ver)) (map string (ver-puncs ver))) )
    189198
     199(define (version-depth ver)
     200  (length (ver-parts (check-version 'version-depth ver))) )
     201
    190202(define (version-parts ver)
    191203  (list-copy (ver-parts (check-version 'version-parts ver))) )
  • release/5/semantic-version/trunk/tests/semantic-version-test.scm

    r39846 r39848  
    1313
    1414(test-error (make-version 'a 2 #\c))
    15 (test-assert (version? (make-version "a" 2 "c")))
     15(test-assert (version? (make-version 'a 2 "c")))
    1616
    1717;assumes 1st is always "."
    18 (test (make-version "a" 2 "c") (version-parse "a.2.c"))
     18(test (make-version 'a 2 "c") (version-parse "a.2.c"))
     19
     20(test 3 (version-depth (make-version 'a 2 "c")))
    1921
    2022(test-assert (version? (version-parse "a.2,c")))
Note: See TracChangeset for help on using the changeset viewer.