From 2528523a1f26b1e58b48fa83c60219afcd40d72e Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Wed, 25 Jun 2008 14:31:02 +0000 Subject: [PATCH] started a test suite, PR 9545 svn: r10451 --- collects/planet/private/planet-shared.ss | 20 +++++++------ collects/planet/private/test.ss | 38 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 collects/planet/private/test.ss diff --git a/collects/planet/private/planet-shared.ss b/collects/planet/private/planet-shared.ss index 16cb4fb1b1..24fe6fec1a 100644 --- a/collects/planet/private/planet-shared.ss +++ b/collects/planet/private/planet-shared.ss @@ -247,7 +247,7 @@ Various common pieces of code that both the client and server need to access (define (make-assoc-table-row name path maj min dir required-version type) (list name path maj min dir required-version type)) - (define-struct mz-version (major minor)) + (define-struct mz-version (major minor) #:inspector #f) ;; string->mz-version : string -> mz-version | #f @@ -280,14 +280,16 @@ Various common pieces of code that both the client and server need to access (lambda (ver) (cond [(list-ref ver 3) (let* ([chunks (regexp-split #rx"\\." (list-ref ver 3))]) - (make-mz-version (+ (* (string->number (list-ref ver 1)) - 100) - (if (> (length chunks) 0) - (string->number (car chunks)) - 0)) - (if (> (length (cdr chunks)) 0) - (minor+maint-chunks->minor (cdr chunks)) - 0)))] + (and (andmap (λ (x) (not (equal? x ""))) chunks) + (make-mz-version (+ (* (string->number (list-ref ver 1)) + 100) + (if (> (length chunks) 0) + (begin + (string->number (car chunks))) + 0)) + (if (> (length (cdr chunks)) 0) + (minor+maint-chunks->minor (cdr chunks)) + 0))))] [else (make-mz-version (* (string->number (list-ref ver 1)) 100) diff --git a/collects/planet/private/test.ss b/collects/planet/private/test.ss new file mode 100644 index 0000000000..8694f42ebe --- /dev/null +++ b/collects/planet/private/test.ss @@ -0,0 +1,38 @@ +#lang scheme + +(require "planet-shared.ss") + +(define-syntax (test stx) + (syntax-case stx () + [(_ a b) + (with-syntax ([line (syntax-line stx)] + [file (let ([s (syntax-source stx)]) + (if (string? s) + s + "<>"))]) + #`(test/proc file line a b))])) + +(define (test/proc file line got expected) + (unless (equal? got expected) + (error 'test.ss "FAILED ~a: ~s\n got ~s\nexpected ~s" file line got expected))) + + +(test (string->mz-version "372") + (make-mz-version 372 0)) + +(test (string->mz-version "372.2") + (make-mz-version 372 2000)) + +(test (string->mz-version "4.0") + (make-mz-version 400 0)) + +(test (string->mz-version "4.1") + (make-mz-version 401 0)) + +(test (string->mz-version "4.0.1") + (make-mz-version 400 1000)) + +(test (string->mz-version "4..1") + #f) + +(printf "tests passed\n") \ No newline at end of file