summaryrefslogtreecommitdiffstats
path: root/tests/018/format.tl
blob: 1b161936cc48d5264551896b24c2f8d460f0de63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
(load "../common")

(mtest
  (fmt "~x" #b'') ""
  (fmt "~4x" #b'') "    "
  (fmt "~4,02x" #b'') "  00"
  (fmt "~x" #b'AF') "af"
  (fmt "~4x" #b'AF') "  af"
  (fmt "~-4x" #b'AF') "af  "
  (fmt "~4,03x" #b'AF') " 0af"
  (fmt "~-4,03X" #b'AF') "0AF ")

(mtest
  (fmt "~x" #\xaf) "af"
  (fmt "~4x" #\xaf) "  af"
  (fmt "~-4x" #\xaf) "af  "
  (fmt "~4,03x" #\xaf) " 0af"
  (fmt "~-4,03X" #\xaf) "0AF ")

(mtest
  (fmt "~x" #xaf) "af"
  (fmt "~4x" #xaf) "  af"
  (fmt "~-4x" #xaf) "af  "
  (fmt "~4,03x" #xaf) " 0af"
  (fmt "~-4,03X" #xaf) "0AF ")

(test
  (fmt "~x" (sha256 "abc"))
  "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")

(mtest
  (fmt "~8,02f"   12) " 0012.00"
  (fmt "~8,+02f"  12) "+0012.00"
  (fmt "~8,-02f"  12) "00012.00"
  (fmt "~8, 02f"  12) " 0012.00"
  (fmt "~8,-02f" -12) "-0012.00"
  (fmt "~6,02f"   12)   " 12.00"
  (fmt "~6,+02f"  12)   "+12.00"
  (fmt "~6,-02f"  12)   "012.00"
  (fmt "~6,- 2f"  12)   " 12.00"
  (fmt "~6,-02f" -12)   "-12.00"
  (fmt "~5,02f"   12)    "12.00"
  (fmt "~5,+02f"  12)   "+12.00"
  (fmt "~5,-02f"  12)    "12.00"
  (fmt "~5,- 2f"  12)    "12.00"
  (fmt "~5,-02f" -12)   "-12.00")

(mtest
  (fmt "~<8,02f"   12) "0012.00 "
  (fmt "~<8,+02f"  12) "+0012.00"
  (fmt "~<8,-02f"  12) "00012.00"
  (fmt "~<8, 02f"  12) " 0012.00"
  (fmt "~<8,-02f" -12) "-0012.00"
  (fmt "~<6,02f"   12)   "12.00 "
  (fmt "~<6,+02f"  12)   "+12.00"
  (fmt "~<6,-02f"  12)   "012.00"
  (fmt "~<6,- 2f"  12)   " 12.00"
  (fmt "~<6,-02f" -12)   "-12.00"
  (fmt "~<5,02f"   12)    "12.00"
  (fmt "~<5,+02f"  12)   "+12.00"
  (fmt "~<5,-02f"  12)    "12.00"
  (fmt "~<5,- 2f"  12)    "12.00"
  (fmt "~<5,-02f" -12)   "-12.00")

(mtest
  (fmt "~<8,2a"    12)   "12      "
  (fmt "~<8,02a"   12)   "12      "
  (fmt "~<8,+02a"  12)   "+12     "
  (fmt "~<8,-02a"  12)   "012     "
  (fmt "~<8, 02a"  12)   " 12     "
  (fmt "~<8,2a"    12.0) "12      "
  (fmt "~<8,02a"   12.0) "12      "
  (fmt "~<8,+02a"  12.0) "+12     "
  (fmt "~<8,-02a"  12.0) "012     "
  (fmt "~<8, 02a"  12.0) " 12     "
  (fmt "~<8,4a"    12.0) "  12    "
  (fmt "~<8,04a"   12.0) "0012    "
  (fmt "~<8,+04a"  12.0) "+0012   "
  (fmt "~<8,-04a"  12.0) "00012   "
  (fmt "~<8, 04a"  12.0) " 0012   "
  (fmt "~<8,8a"    12.0) "     12 "
  (fmt "~<8,08a"   12.0) "0000012 "
  (fmt "~<8,+08a"  12.0) "+0000012"
  (fmt "~<8,-08a"  12.0) "00000012"
  (fmt "~<8, 08a"  12.0) " 0000012")

(mtest
  (fmt "~,04a" 1) "0001"
  (fmt "~,4a" 1) "   1"
  (fmt "~4,a" 1) "   1"
  (fmt "~<8,a" 1) "1       "
  (fmt "~<8,0a" 1) "1       "
  (fmt "~<8,4a" 1) "   1    "
  (fmt "~<8,04a" 1) "0001    "
  (fmt "~<8,+04a" 1) "+0001   "
  (fmt "~<,4a" 1) "   1")

(mtest
  (fmt "~,04a" 1) "0001"
  (fmt "~,4a" 1) "   1"
  (fmt "~4,a" 1) "   1"
  (fmt "~<8,a" 1) "1       "
  (fmt "~<8,0a" 1) "1       "
  (fmt "~<8,4a" 1) "   1    "
  (fmt "~<8,04a" 1) "0001    "
  (fmt "~<8,+04a" 1) "+0001   "
  (fmt "~<,4a" 1) "   1")

(mtest
  (fmt "~e"   1.2e13)     "1.200e13"
  (fmt "~,2e" 1.2e13)      "1.20e13"
  (fmt "~,0e" 1.2e13)         "1e13"
  (fmt "~8,0e" 1.2e13)    "    1e13"
  (fmt "~8,00e" 1.2e13)   " 0001e13"
  (fmt "~8,-0e" 1.2e13)   "   01e13"
  (fmt "~8,-00e" 1.2e13)  "00001e13"
  (fmt "~8, 00e" 1.2e13)  " 0001e13"
  (fmt "~8,+00e" 1.2e13)  "+0001e13"
  (fmt "~8,+00e" -1.2e13) "-0001e13"
  (fmt "~8,00e" -1.2e13)  "-0001e13"
  (fmt "~<8,0e" 1.2e13)   "   1e13 "
  (fmt "~<8,00e" 1.2e13)  "0001e13 "
  (fmt "~<8,-0e" 1.2e13)  "   01e13"
  (fmt "~<8,-00e" 1.2e13) "00001e13"
  (fmt "~<8,+00e" 1.2e13) "+0001e13")

(mtest
  (pic "") ""
  (pic "~") :error
  (pic "~z") :error
  (pic "#") :error
  (pic "# #" 1) :error
  (pic "# # #" 1 2) :error
  (pic "# # #" 1 2 3 4) :warning
  (pic "~<") "<"
  (pic "~>") ">"
  (pic "~|") "|"
  (pic "~#") "#"
  (pic "~0") "0"
  (pic "~+") "+"
  (pic "~-") "-"
  (pic "~.") "."
  (pic "~!") "!"
  (pic "~~") "~"
  (pic "x~~y") "x~y"
  (pic "~~x~~~~y~~") "~x~~y~")

(mtest
  (pic "<" "a") "a"
  (pic "<<" "a") "a "
  (pic "<<<" "a") "a  "
  (pic "~<<~>" "a") "<a>"
  (pic "~<<<~>" "a") "<a >"
  (pic "~<<<<~>" "a") "<a  >")

(mtest
  (pic ">" "a") "a"
  (pic ">>" "a") " a"
  (pic ">>>" "a") "  a"
  (pic "~>>~<" "a") ">a<"
  (pic "~>>>~<" "a") "> a<"
  (pic "~>>>>~<" "a") ">  a<")

(mtest
  (pic "|" "a") "a"
  (pic "||" "a") "a "
  (pic "|||" "a") " a "
  (pic "||||" "a") " a  "
  (pic "|||||" "a") "  a  "
  (pic "|||||" "aaa") " aaa "
  (pic "|||||" "aaaaa") "aaaaa"
  (pic "|||||" "aaaaaa") "aaaaaa"
  (pic "~||~|" "a") "|a|"
  (pic "~|||~|" "a") "|a |"
  (pic "~||||~|" "a") "| a |")

(mtest
  (pic "#" 0) "0"
  (pic "#" 0.0) "0"
  (pic "#" 0.1) "0"
  (pic "#" 0.7) "1"
  (pic "+#" 0.7) "+1"
  (pic "-#" -0.7) "-1"
  (pic "+#" -0.7) "-1"
  (pic "-#" 0.7) " 1")

(mtest
  (pic "####" 1234) "1234"
  (pic "####" 1234.1) "1234"
  (pic "#" 1) "1"
  (pic "#.#" 1) "1.0"
  (pic "######" 1234.1) "  1234"
  (pic  "######.#" 1234.1)   "  1234.1"
  (pic "#######.##" 1234.1)  "   1234.10"
  (pic "#######.##" -1234.1) "  -1234.10"
  (pic "0######.##" 1234.1)  "0001234.10"
  (pic "+######.##" 1234.1)  "  +1234.10"
  (pic "-######.##" 1234.1)  "   1234.10"
  (pic "+0#####.##" 1234.1)  "+001234.10"
  (pic "-0#####.##" 1234.1)  " 001234.10")

(mtest
  (pic "#!#" 1234)   "###"
  (pic "#!#"  123)   "###"
  (pic "#.#"  123) "123.0")

(mtest
  (pic "-##!#"   12)  " 12.0"
  (pic "+##!#"   12)  "+12.0"
  (pic "-##!#" -123)  "#####"
  (pic "+##!#"  123)  "#####")

(mtest
  (pic "###!" 123) "123"
  (pic "###." 123) "123."
  (pic "###!" 1234) "###")

(mtest
  (pic "X##.#Y<<<Z>>>W" 1 2 3) "X 1.0Y2  Z  3W"
  (pic "~###.#~#<<<~#>>>~#" 1 2 3) "# 1.0#2  #  3#")

(test (mapcar (do pic "foo~-0##.jpg") (rlist 0..5 8 12))
      ("foo-000.jpg" "foo-001.jpg" "foo-002.jpg" "foo-003.jpg"
       "foo-004.jpg" "foo-005.jpg" "foo-008.jpg" "foo-012.jpg"))

(test
  (let ((a 2) (b "###") (c 13.5))
    (pic `abc@(+ a a)###.##@b>>>>` c "x"))
  "abc4 13.50###   x")