003-bv-fixnum.scm (1136B)
1 ;; tests/cc-util/03-bv-fixnum.scm — bv->fixnum (values ok? val) 2 ;; plumbing and fixnum->bv round-trip. 3 ;; Assumes cc/util.scm is loaded. 4 ;; 5 ;; NOTE: scheme1's number->string and string->number currently ignore 6 ;; the radix argument and emit/parse decimal only (see scheme1.P1pp 7 ;; comment on prim_string_to_number_entry). util.scm correctly forwards 8 ;; the radix per LISP.md; once the prim grows hex support these tests 9 ;; will exercise it. For now we only check decimal. 10 11 (let-values (((ok? n) (bv->fixnum "42" 10))) 12 (if ok? 0 (sys-exit 1)) 13 (if (= n 42) 0 (sys-exit 2))) 14 15 (let-values (((ok? n) (bv->fixnum "-7" 10))) 16 (if ok? 0 (sys-exit 3)) 17 (if (= n -7) 0 (sys-exit 4))) 18 19 ;; parse failure -> (values #f #f) 20 (let-values (((ok? n) (bv->fixnum "nope" 10))) 21 (if ok? (sys-exit 5) 0) 22 (if n (sys-exit 6) 0)) 23 24 ;; empty bv: parse failure 25 (let-values (((ok? n) (bv->fixnum "" 10))) 26 (if ok? (sys-exit 7) 0)) 27 28 ;; round trip via decimal 29 (if (bv= (fixnum->bv 42 10) "42") 0 (sys-exit 8)) 30 (if (bv= (fixnum->bv 0 10) "0") 0 (sys-exit 9)) 31 (if (bv= (fixnum->bv -7 10) "-7") 0 (sys-exit 10)) 32 33 (sys-exit 0)