source: project/format-modular/tags/1.7/tests.scm @ 8363

Last change on this file since 8363 was 4403, checked in by azul, 13 years ago

Giving this egg the usual trunk/tags structure.

File size: 5.5 KB
Line 
1(use format-modular)
2(define mod-format format)
3#;(load "format.so")
4#;(define mod-format cl-format)
5
6(define (test result . rest)
7  (unless (string=? (apply mod-format #f rest) result)
8    (format #t "Failed: (~S)~%Produce: ~S~%Expect:  ~S~%~%" rest (apply mod-format #f rest) result)))
9; make sure both ~A and ~a work:
10(test "hey there" "~a ~A" "hey" "there")
11(test "7 tries/1 win" "~D tr~:@P/~D win~:P" 7 1)
12(test "1 try/0 wins" "~D tr~:@P/~D win~:P" 1 0)
13(test "1 try/1 win" "~D tr~:@P/~D win~:P" 1 1)
14(test "2 tries/3 wins" "~D tr~:@P/~D win~:P" 2 3)
15(test "Results: NONE\n" "Results: ~#[NONE~;~A~;~A ~0[and~;y~] ~A~;~A, ~A and ~A~]~%")
16(test "Results: 1\n" "Results: ~#[NONE~;~A~;~A ~0[and~;y~] ~A~;~A, ~A and ~A~]~%" 1)
17(test "Results: 1 and 2\n" "Results: ~#[NONE~;~A~;~A ~0[and~;y~] ~A~;~A, ~A and ~A~]~%" 1 2)
18(test "Results: 1, 2 and 3\n" "Results: ~#[NONE~;~A~;~A ~0[and~;y~] ~A~;~A, ~A and ~A~]~%" 1 2 3)
19(test "Zero" "~0[Zero~;One~:;Other~]")
20(test "One" "~1[Zero~;One~:;Other~]")
21(test "Other" "~2[Zero~;One~:;Other~]")
22(test "Other" "~999[Zero~;One~:;Other~]")
23(test "[false]" "[~:[false~;true~]]" #f)
24(test "[true]" "[~:[false~;true~]]" 34)
25(test "[]" "[~@[true~]]" #f)
26(test "[true]" "[~@[true~]]" 39)
27(test "<Foo 5> 7" "~? ~D" "<~A ~D>" '("Foo" 5) 7)
28(test "<Foo 5> 7" "~? ~D" "<~A ~D>" '("Foo" 5 14) 7)
29(test "<Foo 5> 7" "~@? ~D" "<~A ~D>" "Foo" 5 7)
30(test "<Foo 5> 14" "~@? ~D" "<~A ~D>" "Foo" 5 14 7)
31(test "The winners are: fred harry jill." "The winners are:~{ ~S~}." '(fred harry jill))
32(test "Pairs: <a,1> <b,2> <c,3>." "Pairs:~{ <~S,~S>~}." '(a 1 b 2 c 3))
33(test "Pairs: <a,1> <b,2> <c,3>." "Pairs:~:{ <~S,~S>~}." '((a 1) (b 2) (c 3)))
34(test "Pairs: <a,1> <b,2> <c,3>." "Pairs:~@{ <~S,~S>~}." 'a 1 'b 2 'c 3)
35(test "Pairs: <a,1> <b,2> <c,3>." "Pairs:~:@{ <~S,~S>~}." '(a 1) '(b 2) '(c 3))
36(test "[]" "[~{hey~}]" '())
37(test "Done." "Done.~^  ~D warning~:P.~^  ~D error~:P." )
38(test "Done.  3 warnings." "Done.~^  ~D warning~:P.~^  ~D error~:P." 3)
39(test "Done.  1 warning.  5 errors." "Done.~^  ~D warning~:P.~^  ~D error~:P." 1 5)
40(test "/hot .../hamburger/ice .../french ..." "~:{/~S~^ ...~}" '((hot dog) (hamburger) (ice cream) (french fries)))
41(test "None" "~[None~;~:{/~S~^...~}~]" 0 '((h e) (d) (h d)))
42(test "/h.../d/h..." "~[None~;~:{/~S~^...~}~]" 1 '((h e) (d) (h d)))
43(test "TheData: 0" "~1{~:}" "TheData: ~A" '(0))
44(test "[0][1]" "~2{[~A]~}" '(0 1 2 3 4))
45(test "a \n a ^J #\\a #\\newline" "~C ~C ~:C ~:C ~@C ~@C" #\a #\newline #\a #\newline #\a #\newline)
46(test "XXIII MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMCCCLXXXIIII DCCCCXXIII" "~:@R ~:@R ~:@R" 23 32384 923)
47(test "MCMLXXX IV CCCXCIII MMMMMMMMMCCXXXIX" "~@R ~@R ~@R ~@R" 1980 4 393 9239)
48(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)
49(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)
50
51(test " -68." "~5,0F" -67.77)
52(test "-67.8" "~5,1F" -67.77)
53(test "1.000" "~,3F" 1)
54(test "1.0" "~F" 1)
55(test "***" "~3,3,0,'*F" 2)
56(test "1234.0" "~,,3F" 1.234)
57
58(define (foo result x) 
59  (test result "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F" x x x x x x))
60
61(foo "  3.14| 31.42|  3.14|3.1416|3.14|3.14159" 3.14159)
62(foo " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159" -3.14159)
63(foo "100.00|******|100.00| 100.0|100.00|100.0" 100.0)
64(foo "1234.00|******|??????|1234.0|1234.00|1234.0" 1234.0)
65(foo "  0.01|  0.06|  0.01| 0.006|0.01|0.006" 0.006)
66
67(test "1.23243E+2" "~E" 123.243)
68(test "1.0E+0" "~E" 1)
69(test "    1.0E+0" "~10E" 1)
70(test "1.000E+0" "~,3E" 1)
71(test "1.0E-4" "~E" 0.0001)
72(test "2.3E+00001" "~,,5E" 23)
73(test "===" "~3,,,,'=E" 23)
74(test "####2.3E+1" "~10,,,,,'#E" 23)
75(test "1.0$+0" "~,,,,,,'$E" 1)
76
77(define (foo result x) 
78  (test result "~9,2,1,,'*E|~10,3,2,2,'?,,'$E|~9,3,2,-2,'%@E|~9,2E" x x x x)) 
79
80(foo "  3.14E+0| 31.42$-01|+.003E+03|  3.14E+0" 3.14159) 
81(foo " -3.14E+0|-31.42$-01|-.003E+03| -3.14E+0" -3.14159) 
82(foo "  1.10E+3| 11.00$+02|+.001E+06|  1.10E+3" 1100.0) 
83
84(foo "*********| 11.00$+12|+.001E+16| 1.10E+13" 1.1E13) 
85
86; Some tests we might never pass:
87
88;(foo "  1.10L+3| 11.00$+02|+.001L+06|  1.10L+3" 1100.0L0)
89;(foo "*********|??????????|%%%%%%%%%|1.10L+120" 1.1L120)
90;(foo "*********|??????????|%%%%%%%%%|1.10L+1200" 1.1L1200)
91
92(define (foo result x)
93  (test result "~9,2,1,,'*G|~9,3,2,3,'?,,'$G|~9,3,2,0,'%G|~9,2G" x x x x)) 
94
95(foo  "  3.14E-2|314.2$-04|0.314E-01|  3.14E-2" 0.0314159)
96(foo  "  3.14E+3|314.2$+01|0.314E+04|  3.14E+3" 3141.59)
97(foo  "  0.31   |0.314    |0.314    | 0.31    " 0.314159)
98(foo  "   3.1   | 3.14    | 3.14    |  3.1    " 3.14159)
99(foo  "   31.   | 31.4    | 31.4    |  31.    " 31.4159)
100(foo  "  3.14E+2| 314.    | 314.    |  3.14E+2" 314.159)
101(foo  "*********|314.0$+10|0.314E+13| 3.14E+12" 3.14E12)
102
103; Some tests we might never pass:
104
105;(foo  "  3.14L+3|314.2$+01|0.314L+04|  3.14L+3" 3141.59L0)
106;(foo  "*********|?????????|%%%%%%%%%|3.14L+120" 3.14L120)
107;(foo  "*********|?????????|%%%%%%%%%|3.14L+1200" 3.14L1200)
108
109(test " " "~T")
110(test "  " "  ~T")
111(test "    " "~4T")
112(test "     " "  ~5,6T")
113(test "        " "      ~4,4T")
114(test "        " "     ~4,4T")
115(test "      " "     ~4,3T")
116(test "    " "~4,4@T")
117(test "      " "~4,3@T")
118(test "         " "   ~4,3@T")
Note: See TracBrowser for help on using the repository browser.