From 4a7c6241fa354a81c85b0dd1f1680313c2f1a6ac Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Tue, 24 Jun 2014 17:30:24 -0400 Subject: [PATCH] Add types and tests for racket/format original commit: fb6f53566969f729e59191a540e8bdc588819470 --- .../typed-racket/base-env/base-env.rkt | 101 ++++++++++++++++++ .../tests/typed-racket/succeed/format.rkt | 31 ++++++ 2 files changed, 132 insertions(+) create mode 100644 pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/format.rkt diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-env.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-env.rkt index 2cc204f4..fcf2459e 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-env.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/base-env/base-env.rkt @@ -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)] diff --git a/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/format.rkt b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/format.rkt new file mode 100644 index 00000000..f1e9bb64 --- /dev/null +++ b/pkgs/typed-racket-pkgs/typed-racket-test/tests/typed-racket/succeed/format.rkt @@ -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))