blob: 98244c95b5343ffb89e6feb3331df7bf80f88060 [file] [log] [blame]
drhb19a2bc2001-09-16 00:13:26 +00001# 2001 September 15
drhd1bf3512001-04-07 15:24:33 +00002#
drhb19a2bc2001-09-16 00:13:26 +00003# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
drhd1bf3512001-04-07 15:24:33 +00005#
drhb19a2bc2001-09-16 00:13:26 +00006# 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.
drhd1bf3512001-04-07 15:24:33 +00009#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this file is testing the sqlite_*_printf() interface.
13#
drhb19a2bc2001-09-16 00:13:26 +000014# $Id: printf.test,v 1.3 2001/09/16 00:13:28 drh Exp $
drhd1bf3512001-04-07 15:24:33 +000015
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19set n 1
20foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} {
21 do_test printf-1.$n.1 [subst {
22 sqlite_mprintf_int {Three integers: %d %x %o} $v $v $v
23 }] [format {Three integers: %d %x %o} $v $v $v]
24 do_test printf-1.$n.2 [subst {
25 sqlite_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v
26 }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v]
27 do_test printf-1.$n.3 [subst {
28 sqlite_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v
29 }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v]
drhdaffd0e2001-04-11 14:28:42 +000030 do_test printf-1.$n.4 [subst {
31 sqlite_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v
32 }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v]
33 do_test printf-1.$n.5 [subst {
34 sqlite_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v
35 }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v]
36 do_test printf-1.$n.6 [subst {
37 sqlite_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v
38 }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v]
drhd1bf3512001-04-07 15:24:33 +000039 incr n
40}
41
42set m 1
43foreach {a b} {1 1 5 5 10 10 10 5} {
44 set n 1
45 foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} {
46 do_test printf-2.$m.$n.1 [subst {
47 sqlite_mprintf_double {A double: %*.*f} $a $b $x
48 }] [format {A double: %*.*f} $a $b $x]
49 do_test printf-2.$m.$n.2 [subst {
50 sqlite_mprintf_double {A double: %*.*e} $a $b $x
51 }] [format {A double: %*.*e} $a $b $x]
52 do_test printf-2.$m.$n.3 [subst {
53 sqlite_mprintf_double {A double: %*.*g} $a $b $x
54 }] [format {A double: %*.*g} $a $b $x]
55 do_test printf-2.$m.$n.4 [subst {
56 sqlite_mprintf_double {A double: %d %d %g} $a $b $x
57 }] [format {A double: %d %d %g} $a $b $x]
58 do_test printf-2.$m.$n.5 [subst {
59 sqlite_mprintf_double {A double: %d %d %#g} $a $b $x
60 }] [format {A double: %d %d %#g} $a $b $x]
61 incr n
62 }
63 incr m
64}
65
66do_test printf-3.1 {
67 sqlite_mprintf_str {A String: (%*.*s)} 10 10 {This is the string}
68} [format {A String: (%*.*s)} 10 10 {This is the string}]
69do_test printf-3.2 {
70 sqlite_mprintf_str {A String: (%*.*s)} 10 5 {This is the string}
71} [format {A String: (%*.*s)} 10 5 {This is the string}]
72do_test printf-3.3 {
73 sqlite_mprintf_str {A String: (%*.*s)} -10 5 {This is the string}
74} [format {A String: (%*.*s)} -10 5 {This is the string}]
75do_test printf-3.4 {
76 sqlite_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string}
77} [format {%d %d A String: (%s)} 1 2 {This is the string}]
78do_test printf-3.5 {
79 sqlite_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string}
80} [format {%d %d A String: (%30s)} 1 2 {This is the string}]
81do_test printf-3.6 {
82 sqlite_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string}
83} [format {%d %d A String: (%-30s)} 1 2 {This is the string}]
84
85do_test printf-4.1 {
86 sqlite_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all}
87} {1 2 A quoted string: 'Hi Y''all'}
88
drhdaffd0e2001-04-11 14:28:42 +000089do_test printf-5.1 {
90 set x [sqlite_mprintf_str {%d %d %100000s} 0 0 {Hello}]
91 string length $x
92} {994}
93do_test printf-5.2 {
94 sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
95} {-9 -10 (HelloHello) %}
96do_test printf-5.3 {
97 sqlite_mprintf_str {%% %d %d (%=10s)} 5 6 Hello
98} {% 5 6 ( Hello )}
99
drhd1bf3512001-04-07 15:24:33 +0000100finish_test