123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511 |
- # 2009 November 11
- #
- # 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 built-in functions.
- #
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- # Test plan:
- #
- # func2-1.*: substr implementation (ascii)
- # func2-2.*: substr implementation (utf8)
- # func2-3.*: substr implementation (blob)
- #
- proc bin_to_hex {blob} {
- set bytes {}
- binary scan $blob \c* bytes
- set bytes2 [list]
- foreach b $bytes {lappend bytes2 [format %02X [expr $b & 0xFF]]}
- join $bytes2 {}
- }
- #----------------------------------------------------------------------------
- # Test cases func2-1.*: substr implementation (ascii)
- #
- do_test func2-1.1 {
- execsql {SELECT 'Supercalifragilisticexpialidocious'}
- } {Supercalifragilisticexpialidocious}
- # substr(x,y), substr(x,y,z)
- do_test func2-1.2.1 {
- catchsql {SELECT SUBSTR()}
- } {1 {wrong number of arguments to function SUBSTR()}}
- do_test func2-1.2.2 {
- catchsql {SELECT SUBSTR('Supercalifragilisticexpialidocious')}
- } {1 {wrong number of arguments to function SUBSTR()}}
- do_test func2-1.2.3 {
- catchsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1,1,1)}
- } {1 {wrong number of arguments to function SUBSTR()}}
- # p1 is 1-indexed
- do_test func2-1.3 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0)}
- } {Supercalifragilisticexpialidocious}
- do_test func2-1.4 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1)}
- } {Supercalifragilisticexpialidocious}
- do_test func2-1.5 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2)}
- } {upercalifragilisticexpialidocious}
- do_test func2-1.6 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30)}
- } {cious}
- do_test func2-1.7 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34)}
- } {s}
- do_test func2-1.8 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35)}
- } {{}}
- do_test func2-1.9 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36)}
- } {{}}
- # if p1<0, start from right
- do_test func2-1.10 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -0)}
- } {Supercalifragilisticexpialidocious}
- do_test func2-1.11 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1)}
- } {s}
- do_test func2-1.12 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -2)}
- } {us}
- do_test func2-1.13 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -30)}
- } {rcalifragilisticexpialidocious}
- do_test func2-1.14 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34)}
- } {Supercalifragilisticexpialidocious}
- do_test func2-1.15 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35)}
- } {Supercalifragilisticexpialidocious}
- do_test func2-1.16 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36)}
- } {Supercalifragilisticexpialidocious}
- # p1 is 1-indexed, p2 length to return
- do_test func2-1.17.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 1)}
- } {{}}
- do_test func2-1.17.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 2)}
- } {S}
- do_test func2-1.18 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, 1)}
- } {S}
- do_test func2-1.19.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 0)}
- } {{}}
- do_test func2-1.19.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 1)}
- } {u}
- do_test func2-1.19.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 2)}
- } {up}
- do_test func2-1.20 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, 1)}
- } {c}
- do_test func2-1.21 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34, 1)}
- } {s}
- do_test func2-1.22 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35, 1)}
- } {{}}
- do_test func2-1.23 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, 1)}
- } {{}}
- # if p1<0, start from right, p2 length to return
- do_test func2-1.24 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -0, 1)}
- } {{}}
- do_test func2-1.25.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 0)}
- } {{}}
- do_test func2-1.25.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 1)}
- } {s}
- do_test func2-1.25.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -1, 2)}
- } {s}
- do_test func2-1.26 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -2, 1)}
- } {u}
- do_test func2-1.27 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -30, 1)}
- } {r}
- do_test func2-1.28.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 0)}
- } {{}}
- do_test func2-1.28.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 1)}
- } {S}
- do_test func2-1.28.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -34, 2)}
- } {Su}
- do_test func2-1.29.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35, 1)}
- } {{}}
- do_test func2-1.29.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -35, 2)}
- } {S}
- do_test func2-1.30.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 0)}
- } {{}}
- do_test func2-1.30.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 1)}
- } {{}}
- do_test func2-1.30.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 2)}
- } {{}}
- do_test func2-1.30.3 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', -36, 3)}
- } {S}
- # p1 is 1-indexed, p2 length to return, p2<0 return p2 chars before p1
- do_test func2-1.31.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, 0)}
- } {{}}
- do_test func2-1.31.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, -1)}
- } {{}}
- do_test func2-1.31.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 0, -2)}
- } {{}}
- do_test func2-1.32.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, 0)}
- } {{}}
- do_test func2-1.32.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 1, -1)}
- } {{}}
- do_test func2-1.33.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, 0)}
- } {{}}
- do_test func2-1.33.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, -1)}
- } {S}
- do_test func2-1.33.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 2, -2)}
- } {S}
- do_test func2-1.34.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, 0)}
- } {{}}
- do_test func2-1.34.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, -1)}
- } {u}
- do_test func2-1.34.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 3, -2)}
- } {Su}
- do_test func2-1.35.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, -1)}
- } {o}
- do_test func2-1.35.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 30, -2)}
- } {do}
- do_test func2-1.36 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 34, -1)}
- } {u}
- do_test func2-1.37 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 35, -1)}
- } {s}
- do_test func2-1.38.0 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, 0)}
- } {{}}
- do_test func2-1.38.1 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, -1)}
- } {{}}
- do_test func2-1.38.2 {
- execsql {SELECT SUBSTR('Supercalifragilisticexpialidocious', 36, -2)}
- } {s}
- #----------------------------------------------------------------------------
- # Test cases func2-2.*: substr implementation (utf8)
- #
- # Only do the following tests if TCL has UTF-8 capabilities
- #
- if {"\u1234"!="u1234"} {
- do_test func2-2.1.1 {
- execsql "SELECT 'hi\u1234ho'"
- } "hi\u1234ho"
- # substr(x,y), substr(x,y,z)
- do_test func2-2.1.2 {
- catchsql "SELECT SUBSTR()"
- } {1 {wrong number of arguments to function SUBSTR()}}
- do_test func2-2.1.3 {
- catchsql "SELECT SUBSTR('hi\u1234ho')"
- } {1 {wrong number of arguments to function SUBSTR()}}
- do_test func2-2.1.4 {
- catchsql "SELECT SUBSTR('hi\u1234ho', 1,1,1)"
- } {1 {wrong number of arguments to function SUBSTR()}}
- do_test func2-2.2.0 {
- execsql "SELECT SUBSTR('hi\u1234ho', 0, 0)"
- } {{}}
- do_test func2-2.2.1 {
- execsql "SELECT SUBSTR('hi\u1234ho', 0, 1)"
- } {{}}
- do_test func2-2.2.2 {
- execsql "SELECT SUBSTR('hi\u1234ho', 0, 2)"
- } "h"
- do_test func2-2.2.3 {
- execsql "SELECT SUBSTR('hi\u1234ho', 0, 3)"
- } "hi"
- do_test func2-2.2.4 {
- execsql "SELECT SUBSTR('hi\u1234ho', 0, 4)"
- } "hi\u1234"
- do_test func2-2.2.5 {
- execsql "SELECT SUBSTR('hi\u1234ho', 0, 5)"
- } "hi\u1234h"
- do_test func2-2.2.6 {
- execsql "SELECT SUBSTR('hi\u1234ho', 0, 6)"
- } "hi\u1234ho"
- do_test func2-2.3.0 {
- execsql "SELECT SUBSTR('hi\u1234ho', 1, 0)"
- } {{}}
- do_test func2-2.3.1 {
- execsql "SELECT SUBSTR('hi\u1234ho', 1, 1)"
- } "h"
- do_test func2-2.3.2 {
- execsql "SELECT SUBSTR('hi\u1234ho', 1, 2)"
- } "hi"
- do_test func2-2.3.3 {
- execsql "SELECT SUBSTR('hi\u1234ho', 1, 3)"
- } "hi\u1234"
- do_test func2-2.3.4 {
- execsql "SELECT SUBSTR('hi\u1234ho', 1, 4)"
- } "hi\u1234h"
- do_test func2-2.3.5 {
- execsql "SELECT SUBSTR('hi\u1234ho', 1, 5)"
- } "hi\u1234ho"
- do_test func2-2.3.6 {
- execsql "SELECT SUBSTR('hi\u1234ho', 1, 6)"
- } "hi\u1234ho"
- do_test func2-2.4.0 {
- execsql "SELECT SUBSTR('hi\u1234ho', 3, 0)"
- } {{}}
- do_test func2-2.4.1 {
- execsql "SELECT SUBSTR('hi\u1234ho', 3, 1)"
- } "\u1234"
- do_test func2-2.4.2 {
- execsql "SELECT SUBSTR('hi\u1234ho', 3, 2)"
- } "\u1234h"
- do_test func2-2.5.0 {
- execsql "SELECT SUBSTR('\u1234', 0, 0)"
- } {{}}
- do_test func2-2.5.1 {
- execsql "SELECT SUBSTR('\u1234', 0, 1)"
- } {{}}
- do_test func2-2.5.2 {
- execsql "SELECT SUBSTR('\u1234', 0, 2)"
- } "\u1234"
- do_test func2-2.5.3 {
- execsql "SELECT SUBSTR('\u1234', 0, 3)"
- } "\u1234"
- do_test func2-2.6.0 {
- execsql "SELECT SUBSTR('\u1234', 1, 0)"
- } {{}}
- do_test func2-2.6.1 {
- execsql "SELECT SUBSTR('\u1234', 1, 1)"
- } "\u1234"
- do_test func2-2.6.2 {
- execsql "SELECT SUBSTR('\u1234', 1, 2)"
- } "\u1234"
- do_test func2-2.6.3 {
- execsql "SELECT SUBSTR('\u1234', 1, 3)"
- } "\u1234"
- do_test func2-2.7.0 {
- execsql "SELECT SUBSTR('\u1234', 2, 0)"
- } {{}}
- do_test func2-2.7.1 {
- execsql "SELECT SUBSTR('\u1234', 2, 1)"
- } {{}}
- do_test func2-2.7.2 {
- execsql "SELECT SUBSTR('\u1234', 2, 2)"
- } {{}}
- do_test func2-2.8.0 {
- execsql "SELECT SUBSTR('\u1234', -1, 0)"
- } {{}}
- do_test func2-2.8.1 {
- execsql "SELECT SUBSTR('\u1234', -1, 1)"
- } "\u1234"
- do_test func2-2.8.2 {
- execsql "SELECT SUBSTR('\u1234', -1, 2)"
- } "\u1234"
- do_test func2-2.8.3 {
- execsql "SELECT SUBSTR('\u1234', -1, 3)"
- } "\u1234"
- } ;# End \u1234!=u1234
- #----------------------------------------------------------------------------
- # Test cases func2-3.*: substr implementation (blob)
- #
- ifcapable {!bloblit} {
- finish_test
- return
- }
- do_test func2-3.1.1 {
- set blob [execsql "SELECT x'1234'"]
- bin_to_hex [lindex $blob 0]
- } "1234"
- # substr(x,y), substr(x,y,z)
- do_test func2-3.1.2 {
- catchsql {SELECT SUBSTR()}
- } {1 {wrong number of arguments to function SUBSTR()}}
- do_test func2-3.1.3 {
- catchsql {SELECT SUBSTR(x'1234')}
- } {1 {wrong number of arguments to function SUBSTR()}}
- do_test func2-3.1.4 {
- catchsql {SELECT SUBSTR(x'1234', 1,1,1)}
- } {1 {wrong number of arguments to function SUBSTR()}}
- do_test func2-3.2.0 {
- set blob [execsql "SELECT SUBSTR(x'1234', 0, 0)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.2.1 {
- set blob [execsql "SELECT SUBSTR(x'1234', 0, 1)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.2.2 {
- set blob [execsql "SELECT SUBSTR(x'1234', 0, 2)"]
- bin_to_hex [lindex $blob 0]
- } "12"
- do_test func2-3.2.3 {
- set blob [execsql "SELECT SUBSTR(x'1234', 0, 3)"]
- bin_to_hex [lindex $blob 0]
- } "1234"
- do_test func2-3.3.0 {
- set blob [execsql "SELECT SUBSTR(x'1234', 1, 0)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.3.1 {
- set blob [execsql "SELECT SUBSTR(x'1234', 1, 1)"]
- bin_to_hex [lindex $blob 0]
- } "12"
- do_test func2-3.3.2 {
- set blob [execsql "SELECT SUBSTR(x'1234', 1, 2)"]
- bin_to_hex [lindex $blob 0]
- } "1234"
- do_test func2-3.3.3 {
- set blob [execsql "SELECT SUBSTR(x'1234', 1, 3)"]
- bin_to_hex [lindex $blob 0]
- } "1234"
- do_test func2-3.4.0 {
- set blob [execsql "SELECT SUBSTR(x'1234', -1, 0)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.4.1 {
- set blob [execsql "SELECT SUBSTR(x'1234', -1, 1)"]
- bin_to_hex [lindex $blob 0]
- } "34"
- do_test func2-3.4.2 {
- set blob [execsql "SELECT SUBSTR(x'1234', -1, 2)"]
- bin_to_hex [lindex $blob 0]
- } "34"
- do_test func2-3.4.3 {
- set blob [execsql "SELECT SUBSTR(x'1234', -1, 3)"]
- bin_to_hex [lindex $blob 0]
- } "34"
- do_test func2-3.5.0 {
- set blob [execsql "SELECT SUBSTR(x'1234', -2, 0)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.5.1 {
- set blob [execsql "SELECT SUBSTR(x'1234', -2, 1)"]
- bin_to_hex [lindex $blob 0]
- } "12"
- do_test func2-3.5.2 {
- set blob [execsql "SELECT SUBSTR(x'1234', -2, 2)"]
- bin_to_hex [lindex $blob 0]
- } "1234"
- do_test func2-3.5.3 {
- set blob [execsql "SELECT SUBSTR(x'1234', -2, 3)"]
- bin_to_hex [lindex $blob 0]
- } "1234"
- do_test func2-3.6.0 {
- set blob [execsql "SELECT SUBSTR(x'1234', -1, 0)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.6.1 {
- set blob [execsql "SELECT SUBSTR(x'1234', -1, -1)"]
- bin_to_hex [lindex $blob 0]
- } "12"
- do_test func2-3.6.2 {
- set blob [execsql "SELECT SUBSTR(x'1234', -1, -2)"]
- bin_to_hex [lindex $blob 0]
- } "12"
- do_test func2-3.6.3 {
- set blob [execsql "SELECT SUBSTR(x'1234', -1, -3)"]
- bin_to_hex [lindex $blob 0]
- } "12"
- do_test func2-3.7.0 {
- set blob [execsql "SELECT SUBSTR(x'1234', -2, 0)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.7.1 {
- set blob [execsql "SELECT SUBSTR(x'1234', -2, -1)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.7.2 {
- set blob [execsql "SELECT SUBSTR(x'1234', -2, -2)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.8.0 {
- set blob [execsql "SELECT SUBSTR(x'1234', 1, 0)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.8.1 {
- set blob [execsql "SELECT SUBSTR(x'1234', 1, -1)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.8.2 {
- set blob [execsql "SELECT SUBSTR(x'1234', 1, -2)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.9.0 {
- set blob [execsql "SELECT SUBSTR(x'1234', 2, 0)"]
- bin_to_hex [lindex $blob 0]
- } {}
- do_test func2-3.9.1 {
- set blob [execsql "SELECT SUBSTR(x'1234', 2, -1)"]
- bin_to_hex [lindex $blob 0]
- } "12"
- do_test func2-3.9.2 {
- set blob [execsql "SELECT SUBSTR(x'1234', 2, -2)"]
- bin_to_hex [lindex $blob 0]
- } "12"
- finish_test
|