Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/printf2.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / printf2.test` 213 lines · 7107 bytes Raw Blame History 1 # 2013-12-17 2 # 3 # The author disclaims copyright to this source code. In place of 4 # a legal notice, here is a blessing: 5 # 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. 9 # 10 #*********************************************************************** 11 # This file implements regression tests for SQLite library. The 12 # focus of this file is testing the printf() SQL function. 13 # 14 # 15 # EVIDENCE-OF: R-32560-14372 The format(FORMAT,...) SQL function works 16 # like the sqlite3_mprintf() C-language function and the printf() 17 # function from the standard C library. 18 # 19 # EVIDENCE-OF: R-64900-53159 The printf() SQL function is an alias for 20 # the format() SQL function. 21 # 22 23 set testdir [file dirname $argv0] 24 source $testdir/tester.tcl 25 26 # EVIDENCE-OF: R-40086-60101 If the FORMAT argument is missing or NULL 27 # then the result is NULL. 28 # 29 do_execsql_test printf2-1.1 { 30 SELECT quote(format()), quote(format(NULL,1,2,3)); 31 } {NULL NULL} 32 33 34 do_execsql_test printf2-1.2 { 35 SELECT printf('hello'); 36 } {hello} 37 do_execsql_test printf2-1.3 { 38 SELECT format('%d,%d,%d',55,-11,3421); 39 } {55,-11,3421} 40 do_execsql_test printf2-1.4 { 41 SELECT printf('%d,%d,%d',55,'-11',3421); 42 } {55,-11,3421} 43 do_execsql_test printf2-1.5 { 44 SELECT format('%d,%d,%d,%d',55,'-11',3421); 45 } {55,-11,3421,0} 46 do_execsql_test printf2-1.6 { 47 SELECT printf('%.2f',3.`141592653`); 48 } {3.14} 49 do_execsql_test printf2-1.7 { 50 SELECT format('%.*f',2,3.`141592653`); 51 } {3.14} 52 do_execsql_test printf2-1.8 { 53 SELECT printf('%*.*f',5,2,3.`141592653`); 54 } {{ 3.14}} 55 do_execsql_test printf2-1.9 { 56 SELECT format('%d',314159.2653); 57 } {314159} 58 do_execsql_test printf2-1.10 { 59 SELECT printf('%lld',314159.2653); 60 } {314159} 61 do_execsql_test printf2-1.11 { 62 SELECT format('%lld%n',314159.2653,'hi'); 63 } {314159} 64 do_execsql_test printf2-1.12 { 65 SELECT printf('%n',0); 66 } {{}} 67 68 # EVIDENCE-OF: R-17002-27534 The %z format is interchangeable with %s. 69 # 70 do_execsql_test printf2-1.12 { 71 SELECT format('%.*z',5,'abcdefghijklmnop'); 72 } {abcde} 73 do_execsql_test printf2-1.13 { 74 SELECT printf('%c','abcdefghijklmnop'); 75 } {a} 76 77 # EVIDENCE-OF: R-02347-27622 The %n format is silently ignored and does 78 # not consume an argument. 79 # 80 do_execsql_test printf2-2.1 { 81 CREATE TABLE t1(a,b,c); 82 INSERT INTO t1 VALUES(1,2,3); 83 INSERT INTO t1 VALUES(-1,-2,-3); 84 INSERT INTO t1 VALUES('abc','def','ghi'); 85 INSERT INTO t1 VALUES(1.5,2.25,3.125); 86 SELECT printf('(%s)-%n-(%s)',a,b,c) FROM t1 ORDER BY rowid; 87 } {(1)--(2) (-1)--(-2) (abc)--(def) (1.5)--(2.25)} 88 89 # EVIDENCE-OF: R-56064-04001 The %p format is an alias for %X. 90 # 91 do_execsql_test printf2-2.2 { 92 SELECT printf('%s=(%p)',a,a) FROM t1 ORDER BY a; 93 } {-1=(FFFFFFFFFFFFFFFF) 1=(1) 1.5=(1) abc=(0)} 94 95 # EVIDENCE-OF: R-29410-53018 If there are too few arguments in the 96 # argument list, missing arguments are assumed to have a NULL value, 97 # which is translated into 0 or 0.0 for numeric formats or an empty 98 # string for %s. 99 # 100 do_execsql_test printf2-2.3 { 101 SELECT printf('%s=(%d/%g/%s)',a) FROM t1 ORDER BY a; 102 } {-1=(0/0/) 1=(0/0/) 1.5=(0/0/) abc=(0/0/)} 103 104 # The precision of the %c conversion causes the character to repeat. 105 # 106 do_execsql_test printf2-3.1 { 107 SELECT printf('|%110.100c|','*'); 108 } {{| ****************************************************************************************************|}} 109 do_execsql_test printf2-3.2 { 110 SELECT printf('|%-110.100c|','*'); 111 } {{|**************************************************************************************************** |}} 112 do_execsql_test printf2-3.3 { 113 SELECT printf('|%9.8c|%-9.8c|','*','*'); 114 } {{| ********|******** |}} 115 do_execsql_test printf2-3.4 { 116 SELECT printf('|%8.8c|%-8.8c|','*','*'); 117 } {|********|********|} 118 do_execsql_test printf2-3.5 { 119 SELECT printf('|%7.8c|%-7.8c|','*','*'); 120 } {|********|********|} 121 122 # The "," separator 123 do_execsql_test printf2-4.1 { 124 SELECT printf('|%,d|%,d|',0,-1); 125 } {|0|-1|} 126 do_execsql_test printf2-4.2 { 127 SELECT printf('|%,d|%,d|',12,-12); 128 } {|12|-12|} 129 do_execsql_test printf2-4.3 { 130 SELECT printf('|%,d|%,d|',123,-123); 131 } {|123|-123|} 132 do_execsql_test printf2-4.4 { 133 SELECT printf('|%,d|%,d|',1234,-1234); 134 } {|1,234|-1,234|} 135 do_execsql_test printf2-4.5 { 136 SELECT printf('|%,d|%,d|',12345,-12345); 137 } {|12,345|-12,345|} 138 do_execsql_test printf2-4.6 { 139 SELECT printf('|%,d|%,d|',123456,-123456); 140 } {|123,456|-123,456|} 141 do_execsql_test printf2-4.7 { 142 SELECT printf('|%,d|%,d|',`1234567`,-`1234567`); 143 } {|1,234,567|-1,234,567|} 144 do_execsql_test printf2-4.8 { 145 SELECT printf('|%,d|%,d|',`12345678`,-`12345678`); 146 } {|12,345,678|-12,345,678|} 147 do_execsql_test printf2-4.9 { 148 SELECT printf('|%,d|%,d|',`123456789`,-`123456789`); 149 } {|123,456,789|-123,456,789|} 150 do_execsql_test printf2-4.10 { 151 SELECT printf('|%,d|%,d|',`1234567890`,-`1234567890`); 152 } {|1,234,567,890|-1,234,567,890|} 153 154 # 2018-02-19. Unicode characters with %c 155 do_execsql_test printf2-5.100 { 156 SELECT printf('(%8c)',char(11106)); 157 } {{( ⭢)}} 158 do_execsql_test printf2-5.101 { 159 SELECT printf('(%-8c)',char(11106)); 160 } {{(⭢ )}} 161 do_execsql_test printf2-5.102 { 162 SELECT printf('(%5.3c)',char(1492)); 163 } {{( ההה)}} 164 do_execsql_test printf2-5.103 { 165 SELECT printf('(%-5.3c)',char(1492)); 166 } {{(ההה )}} 167 do_execsql_test printf2-5.104 { 168 SELECT printf('(%3.3c)',char(1492)); 169 } {{(ההה)}} 170 do_execsql_test printf2-5.105 { 171 SELECT printf('(%-3.3c)',char(1492)); 172 } {{(ההה)}} 173 do_execsql_test printf2-5.104 { 174 SELECT printf('(%2c)',char(1513)); 175 } {{( ש)}} 176 do_execsql_test printf2-5.106 { 177 SELECT printf('(%-2c)',char(1513)); 178 } {{(ש )}} 179 180 # 2018-02-19. Unicode characters with the "!" flag in %s and friends. 181 do_execsql_test printf2-6.100 { 182 SELECT printf('(%!.3s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 183 } {(הנה)} 184 do_execsql_test printf2-6.101 { 185 SELECT printf('(%.6s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 186 } {(הנה)} 187 do_execsql_test printf2-6.102 { 188 SELECT printf('(%!5.3s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 189 } {{( הנה)}} 190 do_execsql_test printf2-6.103 { 191 SELECT printf('(%8.6s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 192 } {{( הנה)}} 193 do_execsql_test printf2-6.104 { 194 SELECT printf('(%!-5.3s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 195 } {{(הנה )}} 196 do_execsql_test printf2-6.105 { 197 SELECT printf('(%-8.6s)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 198 } {{(הנה )}} 199 do_execsql_test printf2-6.106 { 200 SELECT printf('(%!.3Q)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 201 } {('הנה')} 202 do_execsql_test printf2-6.107 { 203 SELECT printf('(%.6Q)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 204 } {('הנה')} 205 do_execsql_test printf2-6.108 { 206 SELECT printf('(%!7.3Q)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 207 } {{( 'הנה')}} 208 do_execsql_test printf2-6.109 { 209 SELECT printf('(%10.6Q)','הנה מה־טוב ומה־נעים שבת אחים גם־יחד'); 210 } {{( 'הנה')}} 211 212 213 finish_test