3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing the printf() SQL function.
15 # EVIDENCE-OF: R-63057-40065 The printf(FORMAT,...) SQL function works
16 # like the sqlite3_mprintf() C-language function and the printf()
17 # function from the standard C library.
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 # EVIDENCE-OF: R-40086-60101 If the FORMAT argument is missing or NULL
24 # then the result is NULL.
26 do_execsql_test printf2-1.1 {
27 SELECT quote(printf()), quote(printf(NULL,1,2,3));
31 do_execsql_test printf2-1.2 {
32 SELECT printf('hello');
34 do_execsql_test printf2-1.3 {
35 SELECT printf('%d,%d,%d',55,-11,3421);
37 do_execsql_test printf2-1.4 {
38 SELECT printf('%d,%d,%d',55,'-11',3421);
40 do_execsql_test printf2-1.5 {
41 SELECT printf('%d,%d,%d,%d',55,'-11',3421);
43 do_execsql_test printf2-1.6 {
44 SELECT printf('%.2f',3.141592653);
46 do_execsql_test printf2-1.7 {
47 SELECT printf('%.*f',2,3.141592653);
49 do_execsql_test printf2-1.8 {
50 SELECT printf('%*.*f',5,2,3.141592653);
52 do_execsql_test printf2-1.9 {
53 SELECT printf('%d',314159.2653);
55 do_execsql_test printf2-1.10 {
56 SELECT printf('%lld',314159.2653);
58 do_execsql_test printf2-1.11 {
59 SELECT printf('%lld%n',314159.2653,'hi');
61 do_execsql_test printf2-1.12 {
62 SELECT printf('%n',0);
65 # EVIDENCE-OF: R-17002-27534 The %z format is interchangeable with %s.
67 do_execsql_test printf2-1.12 {
68 SELECT printf('%.*z',5,'abcdefghijklmnop');
70 do_execsql_test printf2-1.13 {
71 SELECT printf('%c','abcdefghijklmnop');
74 # EVIDENCE-OF: R-02347-27622 The %n format is silently ignored and does
75 # not consume an argument.
77 do_execsql_test printf2-2.1 {
78 CREATE TABLE t1(a,b,c);
79 INSERT INTO t1 VALUES(1,2,3);
80 INSERT INTO t1 VALUES(-1,-2,-3);
81 INSERT INTO t1 VALUES('abc','def','ghi');
82 INSERT INTO t1 VALUES(1.5,2.25,3.125);
83 SELECT printf('(%s)-%n-(%s)',a,b,c) FROM t1 ORDER BY rowid;
84 } {(1)--(2) (-1)--(-2) (abc)--(def) (1.5)--(2.25)}
86 # EVIDENCE-OF: R-56064-04001 The %p format is an alias for %X.
88 do_execsql_test printf2-2.2 {
89 SELECT printf('%s=(%p)',a,a) FROM t1 ORDER BY a;
90 } {-1=(FFFFFFFFFFFFFFFF) 1=(1) 1.5=(1) abc=(0)}
92 # EVIDENCE-OF: R-29410-53018 If there are too few arguments in the
93 # argument list, missing arguments are assumed to have a NULL value,
94 # which is translated into 0 or 0.0 for numeric formats or an empty
97 do_execsql_test printf2-2.3 {
98 SELECT printf('%s=(%d/%g/%s)',a) FROM t1 ORDER BY a;
99 } {-1=(0/0/) 1=(0/0/) 1.5=(0/0/) abc=(0/0/)}
101 # The precision of the %c conversion causes the character to repeat.
103 do_execsql_test printf2-3.1 {
104 SELECT printf('|%110.100c|','*');
105 } {{| ****************************************************************************************************|}}
106 do_execsql_test printf2-3.2 {
107 SELECT printf('|%-110.100c|','*');
108 } {{|**************************************************************************************************** |}}
109 do_execsql_test printf2-3.3 {
110 SELECT printf('|%9.8c|%-9.8c|','*','*');
111 } {{| ********|******** |}}
112 do_execsql_test printf2-3.4 {
113 SELECT printf('|%8.8c|%-8.8c|','*','*');
114 } {|********|********|}
115 do_execsql_test printf2-3.5 {
116 SELECT printf('|%7.8c|%-7.8c|','*','*');
117 } {|********|********|}
120 do_execsql_test printf2-4.1 {
121 SELECT printf('|%,d|%,d|',0,-1);
123 do_execsql_test printf2-4.2 {
124 SELECT printf('|%,d|%,d|',12,-12);
126 do_execsql_test printf2-4.3 {
127 SELECT printf('|%,d|%,d|',123,-123);
129 do_execsql_test printf2-4.4 {
130 SELECT printf('|%,d|%,d|',1234,-1234);
132 do_execsql_test printf2-4.5 {
133 SELECT printf('|%,d|%,d|',12345,-12345);
135 do_execsql_test printf2-4.6 {
136 SELECT printf('|%,d|%,d|',123456,-123456);
137 } {|123,456|-123,456|}
138 do_execsql_test printf2-4.7 {
139 SELECT printf('|%,d|%,d|',1234567,-1234567);
140 } {|1,234,567|-1,234,567|}
141 do_execsql_test printf2-4.8 {
142 SELECT printf('|%,d|%,d|',12345678,-12345678);
143 } {|12,345,678|-12,345,678|}
144 do_execsql_test printf2-4.9 {
145 SELECT printf('|%,d|%,d|',123456789,-123456789);
146 } {|123,456,789|-123,456,789|}
147 do_execsql_test printf2-4.10 {
148 SELECT printf('|%,d|%,d|',1234567890,-1234567890);
149 } {|1,234,567,890|-1,234,567,890|}
151 # 2018-02-19. Unicode characters with %c
152 do_execsql_test printf2-5.100 {
153 SELECT printf('(%8c)',char(11106));
155 do_execsql_test printf2-5.101 {
156 SELECT printf('(%-8c)',char(11106));
158 do_execsql_test printf2-5.102 {
159 SELECT printf('(%5.3c)',char(1492));
161 do_execsql_test printf2-5.103 {
162 SELECT printf('(%-5.3c)',char(1492));
164 do_execsql_test printf2-5.104 {
165 SELECT printf('(%3.3c)',char(1492));
167 do_execsql_test printf2-5.105 {
168 SELECT printf('(%-3.3c)',char(1492));
170 do_execsql_test printf2-5.104 {
171 SELECT printf('(%2c)',char(1513));
173 do_execsql_test printf2-5.106 {
174 SELECT printf('(%-2c)',char(1513));
177 # 2018-02-19. Unicode characters with the "!" flag in %s and friends.
178 do_execsql_test printf2-6.100 {
179 SELECT printf('(%!.3s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
181 do_execsql_test printf2-6.101 {
182 SELECT printf('(%.6s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
184 do_execsql_test printf2-6.102 {
185 SELECT printf('(%!5.3s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
187 do_execsql_test printf2-6.103 {
188 SELECT printf('(%8.6s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
190 do_execsql_test printf2-6.104 {
191 SELECT printf('(%!-5.3s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
193 do_execsql_test printf2-6.105 {
194 SELECT printf('(%-8.6s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
196 do_execsql_test printf2-6.106 {
197 SELECT printf('(%!.3Q)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
199 do_execsql_test printf2-6.107 {
200 SELECT printf('(%.6Q)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
202 do_execsql_test printf2-6.108 {
203 SELECT printf('(%!7.3Q)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');
205 do_execsql_test printf2-6.109 {
206 SELECT printf('(%10.6Q)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד');