numcast.test 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # 2013 March 20
  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.
  12. # This particular file does testing of casting strings into numeric
  13. # values.
  14. #
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. foreach enc {utf8 utf16le utf16be} {
  18. do_test numcast-$enc.0 {
  19. db close
  20. sqlite3 db :memory:
  21. db eval "PRAGMA encoding='$enc'"
  22. set x [db eval {PRAGMA encoding}]
  23. string map {- {}} [string tolower $x]
  24. } $enc
  25. foreach {idx str rval ival} {
  26. 1 12345.0 12345.0 12345
  27. 2 12345.0e0 12345.0 12345
  28. 3 -12345.0e0 -12345.0 -12345
  29. 4 -12345.25 -12345.25 -12345
  30. 5 { -12345.0} -12345.0 -12345
  31. 6 { 876xyz} 876.0 876
  32. 7 { 456ķ89} 456.0 456
  33. 8 { Ġ 321.5} 0.0 0
  34. } {
  35. do_test numcast-$enc.$idx.1 {
  36. db eval {SELECT CAST($str AS real)}
  37. } $rval
  38. do_test numcast-$enc.$idx.2 {
  39. db eval {SELECT CAST($str AS integer)}
  40. } $ival
  41. }
  42. }
  43. finish_test