summaryrefslogtreecommitdiffstats
path: root/tests/018
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-06-14 07:06:05 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-06-14 07:06:05 -0700
commita0834f3bd8a3beca14501190b46062484b90f555 (patch)
treee874d2b981ecda584a30f58e2b1e2126af0f53d3 /tests/018
parent86d04654a747f537c43e464adb227118d11bfd10 (diff)
downloadtxr-a0834f3bd8a3beca14501190b46062484b90f555.tar.gz
txr-a0834f3bd8a3beca14501190b46062484b90f555.tar.bz2
txr-a0834f3bd8a3beca14501190b46062484b90f555.zip
format: revise numeric handling.
There are a number of issues, such as left adjustment not working and such. This needs a better treatment from the requirements level, through to a set of test cases. * stream.c (max, min): Macros macros added, in their usual form. (vformat_num): Implement new rules which suppress the zero and space characters used in place of a sign if they overflow the field width. (formatv): Clamp integer precision field to width - 1 for integers, for consistency with floating-point handling. For floating-point values under ~a and ~s, do not force the second stage precision to width - 1; only clamp it if it is greater. * format.tl: Numerous new tests. * txr.1: Significant redocumenting of this area. The handling of numbers is described as a two stage process, clarifying the changing role of "precision" in the two stages.
Diffstat (limited to 'tests/018')
-rw-r--r--tests/018/format.tl101
1 files changed, 96 insertions, 5 deletions
diff --git a/tests/018/format.tl b/tests/018/format.tl
index 6c58d45b..1b161936 100644
--- a/tests/018/format.tl
+++ b/tests/018/format.tl
@@ -24,16 +24,107 @@
(fmt "~4,03x" #xaf) " 0af"
(fmt "~-4,03X" #xaf) "0AF ")
-(mtest
- (fmt "~8,02f" 12) " 0012.00"
- (fmt "~8,+02f" 12) "+0012.00"
- (fmt "~8,-02f" 12) "00012.00")
-
(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