summaryrefslogtreecommitdiffstats
path: root/tests/018
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-11 07:23:12 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-11 07:23:12 -0700
commitfe4652d2925bd7a2296a6c527c49bd047f78febc (patch)
treeb0f140ab230d119609525a43518636cfa078fcbf /tests/018
parente781c2a91c245bbbc3607b6b16498d99f14ea36b (diff)
downloadtxr-fe4652d2925bd7a2296a6c527c49bd047f78febc.tar.gz
txr-fe4652d2925bd7a2296a6c527c49bd047f78febc.tar.bz2
txr-fe4652d2925bd7a2296a6c527c49bd047f78febc.zip
pic: test cases and fixes.
* share/txr/stdlib/pic.tl (expand-pic-num): Bug: when a field overflows, the (rest ...) call truncates the leftmost digit. A failing test case is (pic "#.#" 12) which produces "2.0" instead of "12.0". Firstly, we only need that logic at all in the zero padding case. When the number is positive, we stick in the + request, so we are sure to get a + character. The rest call then predictably chops off the + rather than a digit. (pic-join-opt): Fix two bugs here in the string-string combine case: using s2 instead of s1, and not splicing in rest. (expand-pic, pic): Implement tightening for escape sequences. If ~ is not followed by anything, or not followed by the documented characters for escaping, it is erroneous. * format.tl: Battery of new tests.
Diffstat (limited to 'tests/018')
-rw-r--r--tests/018/format.tl88
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/018/format.tl b/tests/018/format.tl
index 3e9e4f5b..d1038c30 100644
--- a/tests/018/format.tl
+++ b/tests/018/format.tl
@@ -27,3 +27,91 @@
(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 "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"))