cs: repairs for byte-string comparison operators

This commit is contained in:
Matthew Flatt 2018-11-21 09:38:32 -07:00
parent 7231f11b60
commit e5bfba5f3c
3 changed files with 48 additions and 7 deletions

View File

@ -1140,6 +1140,49 @@
(err/rt-test (bytes-fill! #"static" 1))
(err/rt-test (bytes-fill! (bytes-copy #"oops") #\5))
(test #t bytes=? #"a" #"a" #"a")
(test #t bytes=? #"a" #"a")
(test #t bytes=? #"a")
(test #f bytes=? #"a" #"a" #"c")
(test #f bytes=? #"a" #"b" #"c")
(test #f bytes=? #"a" #"b")
(test #f bytes=? #"c" #"a" #"a")
(test #f bytes=? #"c" #"b" #"a")
(test #f bytes=? #"b" #"a")
(err/rt-test (bytes=? 1))
(err/rt-test (bytes=? #"a" 1))
(err/rt-test (bytes=? #"a" #"a" 1))
(err/rt-test (bytes=? #"a" #"b" 1))
(test #f bytes<? #"a" #"a" #"a")
(test #f bytes<? #"a" #"a")
(test #t bytes<? #"a")
(test #f bytes<? #"a" #"a" #"c")
(test #t bytes<? #"a" #"b" #"c")
(test #t bytes<? #"a" #"b")
(test #f bytes<? #"c" #"a" #"a")
(test #f bytes<? #"c" #"b" #"a")
(test #f bytes<? #"b" #"a")
(err/rt-test (bytes<? 1))
(err/rt-test (bytes<? #"a" 1))
(err/rt-test (bytes<? #"a" #"a" 1))
(err/rt-test (bytes<? #"b" #"a" 1))
(test #f bytes>? #"a" #"a" #"a")
(test #f bytes>? #"a" #"a")
(test #t bytes>? #"a")
(test #f bytes>? #"a" #"a" #"c")
(test #f bytes>? #"a" #"b" #"c")
(test #f bytes>? #"a" #"b")
(test #f bytes>? #"c" #"a" #"a")
(test #t bytes>? #"c" #"b" #"a")
(test #t bytes>? #"b" #"a")
(err/rt-test (bytes>? 1))
(err/rt-test (bytes>? #"a" 1))
(err/rt-test (bytes>? #"a" #"a" 1))
(err/rt-test (bytes>? #"a" #"b" 1))
(define r (regexp "(-[0-9]*)+"))
(test '("-12--345" "-345") regexp-match r "a-12--345b")
(test '((1 . 9) (5 . 9)) regexp-match-positions r "a-12--345b")

View File

@ -285,7 +285,7 @@
bytes->list list->bytes
bytes->immutable-bytes
bytes-copy! bytes-copy bytes-fill!
bytes=? bytes<? bytes>? bytes<=? bytes>=?
bytes=? bytes<? bytes>?
bytes-append
subbytes

View File

@ -74,6 +74,9 @@
(define-syntax-rule (define-bytes-compare name do-name)
(define/who name
(case-lambda
[(a)
(check who bytes? a)
#t]
[(a b)
(check who bytes? a)
(check who bytes? b)
@ -82,7 +85,7 @@
(check who bytes? a)
(check who bytes? b)
(for-each (lambda (arg)
(check who byte? arg))
(check who bytes? arg))
l)
(and (do-name a b)
(let loop ([a b] [l l])
@ -126,13 +129,8 @@
[(fx= va vb) (loop (fx1+ i))]
[else #f]))]))))
(define (do-bytes>=? a b) (not (do-bytes<? a b)))
(define (do-bytes<=? a b) (not (do-bytes>? a b)))
(define-bytes-compare bytes<? do-bytes<?)
(define-bytes-compare bytes<=? do-bytes<=?)
(define-bytes-compare bytes>? do-bytes>?)
(define-bytes-compare bytes>=? do-bytes>=?)
(define/who bytes-append
(case-lambda