summaryrefslogtreecommitdiffstats
path: root/tests/018/format.tl
blob: b8cf7445c54d968f6d4c37d2ad7f0c0344bdedba (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
(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
  (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")