boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

057-bytevector-eq.scm (988B)


      1 ; Boot2 widens bytevector=? to its byte bridge: either operand may be a
      2 ; bytevector or string. bytes=? gives the same mixed-type comparison an
      3 ; explicitly nonstandard name.
      4 
      5 ; Self-equal.
      6 (if (bytevector=? "abc" "abc") 0 (sys-exit 1))
      7 
      8 ; Empty bytevectors.
      9 (if (bytevector=? "" "") 0 (sys-exit 2))
     10 
     11 ; Distinct identity, same bytes.
     12 (define a (make-bytevector 3 65))
     13 (define b (make-bytevector 3 65))
     14 (if (bytevector=? a b) 0 (sys-exit 3))
     15 
     16 ; Same length, differing byte.
     17 (bytevector-u8-set! b 1 66)
     18 (if (not (bytevector=? a b)) 0 (sys-exit 4))
     19 
     20 ; Different length (prefix match).
     21 (define c (make-bytevector 4 65))
     22 (if (not (bytevector=? a c)) 0 (sys-exit 5))
     23 
     24 ; String literal vs handcrafted bv with identical bytes.
     25 (define s "AAA")
     26 (if (bytevector=? s a) 0 (sys-exit 6))
     27 (if (bytes=? s a) 0 (sys-exit 9))
     28 
     29 ; Non-bytevector inputs return #f rather than crashing.
     30 (if (not (bytevector=? '(1 2 3) "abc")) 0 (sys-exit 7))
     31 (if (not (bytevector=? "abc" 'foo)) 0 (sys-exit 8))
     32 
     33 (sys-exit 0)