;;;; semantic-version-test.scm -*- Scheme -*- ;;;; Kon Lovett, Apr '21 (import test) (import (only (chicken format) format)) (include "test-gloss.incl") (test-begin "Semantic Version") ;;; (import (chicken port) (srfi 69) (srfi 128) semantic-version) (test "makes empty" (make-version 0) (version)) (test "extends empty" (string->version "1.b;ex") (version-extend (version) 1 #\. "b" #\; "ex")) (test-error (version 'a 2 #\c)) (test-assert (version? (version 'a 2 "c"))) (test (version 'a 2 "c") (version-copy (version 'a 2 "c"))) (test "record print" "#" (with-output-to-string (lambda () (display (version 'a 2 "c"))))) ;assumes 1st is always "." (test (version 'a 2 "c") (string->version "a.2.c")) (test 3 (version-depth (version 'a 2 "c"))) (test-assert (version? (string->version "a.2,c"))) (test-assert (not (version? #t))) (test "a.2,c" (version->string (string->version "a.2,c"))) (let ((ver "a.2,c")) (test '("a" 2 "c") (version-elements (string->version ver))) (test '(#\. #\,) (version-separators (string->version ver))) ) (test '("a" #\. 2 #\, "c") (version->list (list->version '("a" #\. 2 #\, "c")))) (test-assert (negative? (version-compare (version 1 2 3) (version 1 11 3)))) (test-assert (positive? (version-compare (version 1 11 3) (version 1 2 3)))) (test-assert (zero? (version-compare (version 1 2 3) (version 1 2 3)))) (test-assert (negative? (version-compare (version 1 2 3) (version 1 2 3 0) #t))) (test-assert (zero? (version-compare (version 1 2 3) (version 1 2 3 0)))) (test "inc of -# is dec" (version "a" 1 "c") (version-inc (version "a" 2 "c") 1 -1)) (test "def inc elm is last" (version 1 2 4) (version-inc (version 1 2 3))) (test (string->version "a.2.c,27-X") (version-extend (version 'a 2 "c") #\, 27 #\- 'X)) (test (version 'a 2 "c" 0 0) (version-depth+ (version 'a 2 "c") 2 0)) (test (version 'a) (version-depth- (version 'a 2 "c") 2)) ;; (define (version-comparator) (make-comparator version? version=? version=? cmptr (version 1 11 3) (version 1 2 3))) ) (let ((ver1 (string->version "1.2.1")) (ver2 (string->version "1.2;1"))) (test-assert (version=? ver1 ver2)) (test-assert "1.2.1 <> 1.2;1" (not (version-strict=? ver1 ver2))) ) ;; (let ((ht (make-hash-table version=? version-hash 10))) (hash-table-set! ht (version "a" 2 "c") 'one) (hash-table-set! ht (version 1 2 3 0) 'two) (test 'one (hash-table-ref ht (version "a" 2 "c"))) (test 'two (hash-table-ref ht (version 1 2 3 0))) (test-error "not found" (hash-table-ref ht (version 'a 'd))) (let ((ver (string->version "1.2;1.0.0"))) (test-assert "version-tail-zero influences hash" (not (= (version-hash ver) (parameterize ((version-tail-zero #t)) (version-hash ver))))) ) ) ;;; (test-end "Semantic Version") (test-exit)