Add types and tests for racket/format

original commit: fb6f53566969f729e59191a540e8bdc588819470
This commit is contained in:
Asumu Takikawa 2014-06-24 17:30:24 -04:00
parent bd3eb045b0
commit 4a7c6241fa
2 changed files with 132 additions and 0 deletions

View File

@ -175,6 +175,107 @@
#:repeat? Univ #f
-String)]
;; Section 4.3.6 (racket/format)
[~a (->optkey []
#:rest Univ
#:separator -String #f
#:width (Un -Nat (-val #f)) #f
#:max-width (Un -Nat (-val +inf.0)) #f
#:min-width -Nat #f
#:limit-marker -String #f
#:align (one-of/c 'left 'center 'right) #f
#:pad-string -String #f
#:left-pad-string -String #f
#:right-pad-string -String #f
-String)]
[~v (->optkey []
#:rest Univ
#:separator -String #f
#:width (Un -Nat (-val #f)) #f
#:max-width (Un -Nat (-val +inf.0)) #f
#:min-width -Nat #f
#:limit-marker -String #f
#:align (one-of/c 'left 'center 'right) #f
#:pad-string -String #f
#:left-pad-string -String #f
#:right-pad-string -String #f
-String)]
[~s (->optkey []
#:rest Univ
#:separator -String #f
#:width (Un -Nat (-val #f)) #f
#:max-width (Un -Nat (-val +inf.0)) #f
#:min-width -Nat #f
#:limit-marker -String #f
#:align (one-of/c 'left 'center 'right) #f
#:pad-string -String #f
#:left-pad-string -String #f
#:right-pad-string -String #f
-String)]
[~e (->optkey []
#:rest Univ
#:separator -String #f
#:width (Un -Nat (-val #f)) #f
#:max-width (Un -Nat (-val +inf.0)) #f
#:min-width -Nat #f
#:limit-marker -String #f
#:align (one-of/c 'left 'center 'right) #f
#:pad-string -String #f
#:left-pad-string -String #f
#:right-pad-string -String #f
-String)]
[~r (->optkey -Real []
#:sign (Un (-val #f) (one-of/c '+ '++ 'parens)
(-lst* (Un -String (-lst* -String -String))
(Un -String (-lst* -String -String))
(Un -String (-lst* -String -String))))
#f
#:base (Un -Integer (-lst* (-val 'up) -Integer)) #f
#:precision (Un -Integer (-lst* (-val '=) -Integer)) #f
#:notation (Un (-val 'positional) (-val 'exponential)
(-> -Real (one-of/c 'positional 'exponential)))
#f
#:format-exponent (-opt (Un -String (-> -Integer -String))) #f
#:min-width -Integer #f
#:pad-string -String #f
-String)]
[~.a (->optkey []
#:rest Univ
#:separator -String #f
#:width (Un -Nat (-val #f)) #f
#:max-width (Un -Nat (-val +inf.0)) #f
#:min-width -Nat #f
#:limit-marker -String #f
#:align (one-of/c 'left 'center 'right) #f
#:pad-string -String #f
#:left-pad-string -String #f
#:right-pad-string -String #f
-String)]
[~.v (->optkey []
#:rest Univ
#:separator -String #f
#:width (Un -Nat (-val #f)) #f
#:max-width (Un -Nat (-val +inf.0)) #f
#:min-width -Nat #f
#:limit-marker -String #f
#:align (one-of/c 'left 'center 'right) #f
#:pad-string -String #f
#:left-pad-string -String #f
#:right-pad-string -String #f
-String)]
[~.s (->optkey []
#:rest Univ
#:separator -String #f
#:width (Un -Nat (-val #f)) #f
#:max-width (Un -Nat (-val +inf.0)) #f
#:min-width -Nat #f
#:limit-marker -String #f
#:align (one-of/c 'left 'center 'right) #f
#:pad-string -String #f
#:left-pad-string -String #f
#:right-pad-string -String #f
-String)]
;; Section 4.4 (Byte Strings)
[bytes (->* (list) -Integer -Bytes)]
[bytes? (make-pred-ty -Bytes)]

View File

@ -0,0 +1,31 @@
#lang typed/racket
;; Test racket/format. Should be a unit test, but lifts don't
;; work well with TR's top-level currently.
(require racket/format)
(~a "foo" 'a 3)
(~a "foo" 'a 3 #:separator ", " #:width 20)
(~a "foo" 'a 3 #:max-width 20 #:min-width 10)
(~s "foo" 'a 3)
(~s "foo" 'a 3 #:separator ", " #:width 20)
(~s "foo" 'a 3 #:max-width 20 #:min-width 10)
(~v "foo" 'a 3)
(~v "foo" 'a 3 #:separator ", " #:width 20)
(~v "foo" 'a 3 #:max-width 20 #:min-width 10)
(~.a "foo" 'a 3)
(~.a "foo" 'a 3 #:separator ", " #:width 20)
(~.a "foo" 'a 3 #:max-width 20 #:min-width 10)
(~.s "foo" 'a 3)
(~.s "foo" 'a 3 #:separator ", " #:width 20)
(~.s "foo" 'a 3 #:max-width 20 #:min-width 10)
(~.v "foo" 'a 3)
(~.v "foo" 'a 3 #:separator ", " #:width 20)
(~.v "foo" 'a 3 #:max-width 20 #:min-width 10)
(~r 234234)
(~r 3.5 #:sign '+ #:base 3 #:precision 3
#:notation 'positional #:format-exponent "fooo"
#:min-width 10 #:pad-string ",")
(~r 3.5 #:sign (list "x" "y" (list "z" "z"))
#:notation (lambda (_) 'positional))