printf.test 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # 2001 September 15
  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 sqlite_*_printf() interface.
  13. #
  14. # $Id: printf.test,v 1.5 2002/06/16 04:56:37 chw Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. set n 1
  18. foreach v {1 2 5 10 99 100 1000000 999999999 0 -1 -2 -5 -10 -99 -100 -9999999} {
  19. do_test printf-1.$n.1 [subst {
  20. sqlite_mprintf_int {Three integers: %d %x %o} $v $v $v
  21. }] [format {Three integers: %d %x %o} $v $v $v]
  22. do_test printf-1.$n.2 [subst {
  23. sqlite_mprintf_int {Three integers: (%6d) (%6x) (%6o)} $v $v $v
  24. }] [format {Three integers: (%6d) (%6x) (%6o)} $v $v $v]
  25. do_test printf-1.$n.3 [subst {
  26. sqlite_mprintf_int {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v
  27. }] [format {Three integers: (%-6d) (%-6x) (%-6o)} $v $v $v]
  28. do_test printf-1.$n.4 [subst {
  29. sqlite_mprintf_int {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v
  30. }] [format {Three integers: (%+6d) (%+6x) (%+6o)} $v $v $v]
  31. do_test printf-1.$n.5 [subst {
  32. sqlite_mprintf_int {Three integers: (%06d) (%06x) (%06o)} $v $v $v
  33. }] [format {Three integers: (%06d) (%06x) (%06o)} $v $v $v]
  34. do_test printf-1.$n.6 [subst {
  35. sqlite_mprintf_int {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v
  36. }] [format {Three integers: (% 6d) (% 6x) (% 6o)} $v $v $v]
  37. incr n
  38. }
  39. if {$::tcl_platform(platform)!="windows"} {
  40. set m 1
  41. foreach {a b} {1 1 5 5 10 10 10 5} {
  42. set n 1
  43. foreach x {0.001 1.0e-20 1.0 0.0 100.0 9.99999 -0.00543 -1.0 -99.99999} {
  44. do_test printf-2.$m.$n.1 [subst {
  45. sqlite_mprintf_double {A double: %*.*f} $a $b $x
  46. }] [format {A double: %*.*f} $a $b $x]
  47. do_test printf-2.$m.$n.2 [subst {
  48. sqlite_mprintf_double {A double: %*.*e} $a $b $x
  49. }] [format {A double: %*.*e} $a $b $x]
  50. do_test printf-2.$m.$n.3 [subst {
  51. sqlite_mprintf_double {A double: %*.*g} $a $b $x
  52. }] [format {A double: %*.*g} $a $b $x]
  53. do_test printf-2.$m.$n.4 [subst {
  54. sqlite_mprintf_double {A double: %d %d %g} $a $b $x
  55. }] [format {A double: %d %d %g} $a $b $x]
  56. do_test printf-2.$m.$n.5 [subst {
  57. sqlite_mprintf_double {A double: %d %d %#g} $a $b $x
  58. }] [format {A double: %d %d %#g} $a $b $x]
  59. incr n
  60. }
  61. incr m
  62. }
  63. }
  64. do_test printf-3.1 {
  65. sqlite_mprintf_str {A String: (%*.*s)} 10 10 {This is the string}
  66. } [format {A String: (%*.*s)} 10 10 {This is the string}]
  67. do_test printf-3.2 {
  68. sqlite_mprintf_str {A String: (%*.*s)} 10 5 {This is the string}
  69. } [format {A String: (%*.*s)} 10 5 {This is the string}]
  70. do_test printf-3.3 {
  71. sqlite_mprintf_str {A String: (%*.*s)} -10 5 {This is the string}
  72. } [format {A String: (%*.*s)} -10 5 {This is the string}]
  73. do_test printf-3.4 {
  74. sqlite_mprintf_str {%d %d A String: (%s)} 1 2 {This is the string}
  75. } [format {%d %d A String: (%s)} 1 2 {This is the string}]
  76. do_test printf-3.5 {
  77. sqlite_mprintf_str {%d %d A String: (%30s)} 1 2 {This is the string}
  78. } [format {%d %d A String: (%30s)} 1 2 {This is the string}]
  79. do_test printf-3.6 {
  80. sqlite_mprintf_str {%d %d A String: (%-30s)} 1 2 {This is the string}
  81. } [format {%d %d A String: (%-30s)} 1 2 {This is the string}]
  82. do_test printf-4.1 {
  83. sqlite_mprintf_str {%d %d A quoted string: '%q'} 1 2 {Hi Y'all}
  84. } {1 2 A quoted string: 'Hi Y''all'}
  85. do_test printf-4.2 {
  86. sqlite_mprintf_str {%d %d A NULL pointer in %%q: '%q'} 1 2
  87. } {1 2 A NULL pointer in %q: '(NULL)'}
  88. do_test printf-4.3 {
  89. sqlite_mprintf_str {%d %d A quoted string: %Q} 1 2 {Hi Y'all}
  90. } {1 2 A quoted string: 'Hi Y''all'}
  91. do_test printf-4.4 {
  92. sqlite_mprintf_str {%d %d A NULL pointer in %%Q: %Q} 1 2
  93. } {1 2 A NULL pointer in %Q: NULL}
  94. do_test printf-5.1 {
  95. set x [sqlite_mprintf_str {%d %d %100000s} 0 0 {Hello}]
  96. string length $x
  97. } {994}
  98. do_test printf-5.2 {
  99. sqlite_mprintf_str {%d %d (%-10.10s) %} -9 -10 {HelloHelloHello}
  100. } {-9 -10 (HelloHello) %}
  101. do_test printf-5.3 {
  102. sqlite_mprintf_str {%% %d %d (%=10s)} 5 6 Hello
  103. } {% 5 6 ( Hello )}
  104. finish_test