123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- # 2001 September 15
- #
- # The author disclaims copyright to this source code. In place of
- # a legal notice, here is a blessing:
- #
- # May you do good and not evil.
- # May you find forgiveness for yourself and forgive others.
- # May you share freely, never taking more than you give.
- #
- #***********************************************************************
- # This file implements regression tests for SQLite library. The
- # focus of this file is testing the sqlite_*_printf() interface.
- #
- # $Id: printf.test,v 1.5 2002/06/16 04:56:37 chw Exp $
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- set n 1
- foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} {
- do_test printf-1.$n.1 [subst {
- sqlite_mprintf_int {Three integers: %d %x %o} $v $v $v
- }] [format {Three integers: %d %x %o} $v $v $v]
- do_test printf-1.$n.2 [subst {
- sqlite_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v
- }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v]
- do_test printf-1.$n.3 [subst {
- sqlite_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v
- }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v]
- do_test printf-1.$n.4 [subst {
- sqlite_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v
- }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v]
- do_test printf-1.$n.5 [subst {
- sqlite_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v
- }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v]
- do_test printf-1.$n.6 [subst {
- sqlite_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v
- }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v]
- incr n
- }
- if {$::tcl_platform(platform)!="windows"} {
- set m 1
- foreach {a b} {1 1 5 5 10 10 10 5} {
- set n 1
- foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} {
- do_test printf-2.$m.$n.1 [subst {
- sqlite_mprintf_double {A double: %*.*f} $a $b $x
- }] [format {A double: %*.*f} $a $b $x]
- do_test printf-2.$m.$n.2 [subst {
- sqlite_mprintf_double {A double: %*.*e} $a $b $x
- }] [format {A double: %*.*e} $a $b $x]
- do_test printf-2.$m.$n.3 [subst {
- sqlite_mprintf_double {A double: %*.*g} $a $b $x
- }] [format {A double: %*.*g} $a $b $x]
- do_test printf-2.$m.$n.4 [subst {
- sqlite_mprintf_double {A double: %d %d %g} $a $b $x
- }] [format {A double: %d %d %g} $a $b $x]
- do_test printf-2.$m.$n.5 [subst {
- sqlite_mprintf_double {A double: %d %d %#g} $a $b $x
- }] [format {A double: %d %d %#g} $a $b $x]
- incr n
- }
- incr m
- }
- }
- do_test printf-3.1 {
- sqlite_mprintf_str {A String: (%*.*s)} 10 10 {This is the string}
- } [format {A String: (%*.*s)} 10 10 {This is the string}]
- do_test printf-3.2 {
- sqlite_mprintf_str {A String: (%*.*s)} 10 5 {This is the string}
- } [format {A String: (%*.*s)} 10 5 {This is the string}]
- do_test printf-3.3 {
- sqlite_mprintf_str {A String: (%*.*s)} -10 5 {This is the string}
- } [format {A String: (%*.*s)} -10 5 {This is the string}]
- do_test printf-3.4 {
- sqlite_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string}
- } [format {%d %d A String: (%s)} 1 2 {This is the string}]
- do_test printf-3.5 {
- sqlite_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string}
- } [format {%d %d A String: (%30s)} 1 2 {This is the string}]
- do_test printf-3.6 {
- sqlite_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string}
- } [format {%d %d A String: (%-30s)} 1 2 {This is the string}]
- do_test printf-4.1 {
- sqlite_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all}
- } {1 2 A quoted string: 'Hi Y''all'}
- do_test printf-4.2 {
- sqlite_mprintf_str {%d %d A NULL pointer in %%q: '%q'} 1 2
- } {1 2 A NULL pointer in %q: '(NULL)'}
- do_test printf-4.3 {
- sqlite_mprintf_str {%d %d A quoted string: %Q} 1 2 {Hi Y'all}
- } {1 2 A quoted string: 'Hi Y''all'}
- do_test printf-4.4 {
- sqlite_mprintf_str {%d %d A NULL pointer in %%Q: %Q} 1 2
- } {1 2 A NULL pointer in %Q: NULL}
- do_test printf-5.1 {
- set x [sqlite_mprintf_str {%d %d %100000s} 0 0 {Hello}]
- string length $x
- } {994}
- do_test printf-5.2 {
- sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
- } {-9 -10 (HelloHello) %}
- do_test printf-5.3 {
- sqlite_mprintf_str {%% %d %d (%=10s)} 5 6 Hello
- } {% 5 6 ( Hello )}
- finish_test
|