(use format) (define *passed* 0) (define *failed* 0) (define (test expected . rest) (let ([result (apply format #f rest)]) (if (string=? result expected) (begin (set! *passed* (add1 *passed*)) (printf "Passed: (~S)~%Produce: ~S~%Expect: ~S~%~%" rest result expected)) (begin (set! *failed* (add1 *failed*)) (printf "Failed: (~S)~%Produce: ~S~%Expect: ~S~%~%" rest result expected))))) ; make sure both ~A and ~a work: (test "hey there" "~a ~A" "hey" "there") (test "7 tries/1 win" "~D tr~:@P/~D win~:P" 7 1) (test "1 try/0 wins" "~D tr~:@P/~D win~:P" 1 0) (test "1 try/1 win" "~D tr~:@P/~D win~:P" 1 1) (test "2 tries/3 wins" "~D tr~:@P/~D win~:P" 2 3) (test "Results: NONE\n" "Results: ~#[NONE~;~A~;~A ~0[and~;y~] ~A~;~A, ~A and ~A~]~%") (test "Results: 1\n" "Results: ~#[NONE~;~A~;~A ~0[and~;y~] ~A~;~A, ~A and ~A~]~%" 1) (test "Results: 1 and 2\n" "Results: ~#[NONE~;~A~;~A ~0[and~;y~] ~A~;~A, ~A and ~A~]~%" 1 2) (test "Results: 1, 2 and 3\n" "Results: ~#[NONE~;~A~;~A ~0[and~;y~] ~A~;~A, ~A and ~A~]~%" 1 2 3) (test "Zero" "~0[Zero~;One~:;Other~]") (test "One" "~1[Zero~;One~:;Other~]") (test "Other" "~2[Zero~;One~:;Other~]") (test "Other" "~999[Zero~;One~:;Other~]") (test "[false]" "[~:[false~;true~]]" #f) (test "[true]" "[~:[false~;true~]]" 34) (test "[]" "[~@[true~]]" #f) (test "[true]" "[~@[true~]]" 39) (test " 7" "~? ~D" "<~A ~D>" '("Foo" 5) 7) (test " 7" "~? ~D" "<~A ~D>" '("Foo" 5 14) 7) (test " 7" "~@? ~D" "<~A ~D>" "Foo" 5 7) ;;Error: (format) 1: "superfluous arguments" ;;when configured w/ format:unprocessed-arguments-error? = #t (test " 14" "~@? ~D" "<~A ~D>" "Foo" 5 14 7) (test "The winners are: fred harry jill." "The winners are:~{ ~S~}." '(fred harry jill)) (test "Pairs: ." "Pairs:~{ <~S,~S>~}." '(a 1 b 2 c 3)) (test "Pairs: ." "Pairs:~:{ <~S,~S>~}." '((a 1) (b 2) (c 3))) (test "Pairs: ." "Pairs:~@{ <~S,~S>~}." 'a 1 'b 2 'c 3) (test "Pairs: ." "Pairs:~:@{ <~S,~S>~}." '(a 1) '(b 2) '(c 3)) (test "[]" "[~{hey~}]" '()) (test "Done." "Done.~^ ~D warning~:P.~^ ~D error~:P." ) (test "Done. 3 warnings." "Done.~^ ~D warning~:P.~^ ~D error~:P." 3) (test "Done. 1 warning. 5 errors." "Done.~^ ~D warning~:P.~^ ~D error~:P." 1 5) (test "/hot .../hamburger/ice .../french ..." "~:{/~S~^ ...~}" '((hot dog) (hamburger) (ice cream) (french fries))) ;;Error: (format) 1: "superfluous arguments" ;;when configured w/ format:unprocessed-arguments-error? = #t (test "None" "~[None~;~:{/~S~^...~}~]" 0 '((h e) (d) (h d))) (test "/h.../d/h..." "~[None~;~:{/~S~^...~}~]" 1 '((h e) (d) (h d))) (test "TheData: 0" "~1{~:}" "TheData: ~A" '(0)) ;;Failed: Produce: [0][1][2][3][4] Expect: [0][1] ;;when configured w/ format:iteration-bounded = #f (test "[0][1]" "~2{[~A]~}" '(0 1 2 3 4)) (test "a \n a ^J #\\a #\\newline" "~C ~C ~:C ~:C ~@C ~@C" #\a #\newline #\a #\newline #\a #\newline) (test "XXIII MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMCCCLXXXIIII DCCCCXXIII" "~:@R ~:@R ~:@R" 23 32384 923) (test "MCMLXXX IV CCCXCIII MMMMMMMMMCCXXXIX" "~@R ~@R ~@R ~@R" 1980 4 393 9239) (test "one hundred twenty-eight zero two million, nine hundred thirty-eight thousand, three hundred twenty-eight nine thousand, two hundred thirty-eight two thousand, eight hundred thirty-nine thirty-eight three thousand, eight hundred twenty-eight" "~R ~R ~R ~R ~R ~R ~R" 128 0 2938328 9238 2839 38 3828) (test "one hundred twenty-eighth zeroth two million, nine hundred thirty-eight thousand, three hundred twenty-eighth nine thousand, two hundred thirty-eighth two thousand, eight hundred thirty-ninth thirty-eighth three thousand, eight hundred twentieth" "~:R ~:R ~:R ~:R ~:R ~:R ~:R" 128 0 2938328 9238 2839 38 3820) (test " -68." "~5,0F" -67.77) (test "-67.8" "~5,1F" -67.77) (test "1.000" "~,3F" 1) (test "1.0" "~F" 1) (test "***" "~3,3,0,'*F" 2) (test "1234.0" "~,,3F" 1.234) (define (foo expected x) (test expected "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F" x x x x x x)) (foo " 3.14| 31.42| 3.14|3.1416|3.14|3.14159" 3.14159) (foo " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159" -3.14159) (foo "100.00|******|100.00| 100.0|100.00|100.0" 100.0) (foo "1234.00|******|??????|1234.0|1234.00|1234.0" 1234.0) (foo " 0.01| 0.06| 0.01| 0.006|0.01|0.006" 0.006) (test "1.23243E+2" "~E" 123.243) (test "1.0E+0" "~E" 1) (test " 1.0E+0" "~10E" 1) (test "1.000E+0" "~,3E" 1) (test "1.0E-4" "~E" 0.0001) (test "2.3E+00001" "~,,5E" 23) (test "===" "~3,,,,'=E" 23) (test "####2.3E+1" "~10,,,,,'#E" 23) (test "1.0$+0" "~,,,,,,'$E" 1) (define (foo expected x) (test expected "~9,2,1,,'*E|~10,3,2,2,'?,,'$E|~9,3,2,-2,'%@E|~9,2E" x x x x)) ;; Fixed - wasn't leaving off leading 0 when result-len > len so considered overflow (foo " 3.14E+0| 31.42$-01|+.003E+03| 3.14E+0" 3.14159) (foo " -3.14E+0|-31.42$-01|-.003E+03| -3.14E+0" -3.14159) (foo " 1.10E+3| 11.00$+02|+.001E+06| 1.10E+3" 1100.0) (foo "*********| 11.00$+12|+.001E+16| 1.10E+13" 1.1E13) (define (foo expected x) (test expected "~9,2,1,,'*G|~9,3,2,3,'?,,'$G|~9,3,2,0,'%G|~9,2G" x x x x)) (foo " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2" 0.0314159) (foo " 3.14E+3|314.2$+01|0.314E+04| 3.14E+3" 3141.59) (foo " 0.31 |0.314 |0.314 | 0.31 " 0.314159) (foo " 3.1 | 3.14 | 3.14 | 3.1 " 3.14159) (foo " 31. | 31.4 | 31.4 | 31. " 31.4159) (foo " 3.14E+2| 314. | 314. | 3.14E+2" 314.159) (foo "*********|314.0$+10|0.314E+13| 3.14E+12" 3.14E12) (test " " "~T") (test " " " ~T") (test " " "~4T") (test " " " ~5,6T") (test " " " ~4,4T") (test " " " ~4,4T") ;; the original test was wrong (test " " " ~4,3T") (test " " "~4,4@T") (test " " "~4,3@T") (test " " " ~4,3@T") (printf "Passed: ~S Failed: ~S~%" *passed* *failed*)