(library (tests string-to-number)
  (export test-string-to-number)
  (import (ikarus) (tests framework))
  (define (t x s)
    (let ([fl (format "~a" (exact->inexact x))])
      (unless (string=? s fl)
        (error 'bignum->flonum
          "incorrect result for ~s\n expected ~a, \n      got ~a" x s fl))))
  (define-syntax test*
    (syntax-rules ()
      [(_ name [str num] ...)
       (define-tests name 
         [(lambda (x) (and x (= x num)))
          (string->number str)]
         ...)]))
  (test* test-string-to-number
    ("10" 10)
    ("1" 1)
    ("-17" -17)
    ("+13476238746782364786237846872346782364876238477" 
     13476238746782364786237846872346782364876238477)
    ("1/2" (/ 1 2))
    ("-1/2" (/ 1 -2))
    ("#x24" 36)
    ("#x-24" -36)
    ("#b+00000110110" 54)
    ("#b-00000110110/10" -27)
    ("#e10" 10)
    ("#e1" 1)
    ("#e-17" -17)
    ("#e#x24" 36)
    ("#e#x-24" -36)
    ("#e#b+00000110110" 54)
    ("#e#b-00000110110/10" -27)
    ("#x#e24" 36)
    ("#x#e-24" -36)
    ("#b#e+00000110110" 54)
    ("#b#e-00000110110/10" -27)
    ("#e1e1000" (expt 10 1000))
    ("#e-1e1000" (- (expt 10 1000)))
    ("#e1e-1000" (expt 10 -1000))
    ("#e-1e-1000" (- (expt 10 -1000)))
    ("#i1e100" (exact->inexact (expt 10 100)))
    ("#i1e1000" (exact->inexact (expt 10 1000)))
    ("#i-1e1000" (exact->inexact (- (expt 10 1000))))
    ("1e100" (exact->inexact (expt 10 100)))
    ("1.0e100" (exact->inexact (expt 10 100)))
    ("1.e100" (exact->inexact (expt 10 100)))
    ("0.1e100" (exact->inexact (expt 10 99)))
    (".1e100" (exact->inexact (expt 10 99)))
    ("+1e100" (exact->inexact (expt 10 100)))
    ("+1.0e100" (exact->inexact (expt 10 100)))
    ("+1.e100" (exact->inexact (expt 10 100)))
    ("+0.1e100" (exact->inexact (expt 10 99)))
    ("+.1e100" (exact->inexact (expt 10 99)))
    ("-1e100" (exact->inexact   (- (expt 10 100))))
    ("-1.0e100" (exact->inexact (- (expt 10 100))))
    ("-1.e100" (exact->inexact  (- (expt 10 100))))
    ("-0.1e100" (exact->inexact (- (expt 10 99))))
    ("-.1e100" (exact->inexact  (- (expt 10 99))))))