boot2

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

007-buf.scm (651B)


      1 ;; tests/cc-util/07-buf.scm — make-buf / buf-push! / buf-flush.
      2 ;; Buffers preserve push order on flush (chunks are stored reversed and
      3 ;; flush reverses again).
      4 ;; Assumes cc/util.scm is loaded.
      5 
      6 (define b (make-buf))
      7 (if (bv= (buf-flush b) "")   0 (sys-exit 1)) ; empty flush
      8 
      9 (buf-push! b "hello, ")
     10 (buf-push! b "world")
     11 (buf-push! b "!")
     12 (if (bv= (buf-flush b) "hello, world!") 0 (sys-exit 2))
     13 
     14 ;; flushing again still sees the same chunks (buf-flush is non-destructive)
     15 (if (bv= (buf-flush b) "hello, world!") 0 (sys-exit 3))
     16 
     17 ;; buf? predicate
     18 (if (buf? b)              0 (sys-exit 4))
     19 (if (buf? "not a buf")    (sys-exit 5) 0)
     20 
     21 (sys-exit 0)