1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/substr.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,130 @@
1.4 +# 2007 May 14
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this file is testing the built-in SUBSTR() functions.
1.16 +#
1.17 +# $Id: substr.test,v 1.3 2007/10/12 19:11:55 drh Exp $
1.18 +
1.19 +set testdir [file dirname $argv0]
1.20 +source $testdir/tester.tcl
1.21 +
1.22 +ifcapable !tclvar {
1.23 + finish_test
1.24 + return
1.25 +}
1.26 +
1.27 +# Create a table to work with.
1.28 +#
1.29 +execsql {
1.30 + CREATE TABLE t1(t text, b blob)
1.31 +}
1.32 +proc substr-test {id string i1 i2 result} {
1.33 + db eval {
1.34 + DELETE FROM t1;
1.35 + INSERT INTO t1(t) VALUES($string)
1.36 + }
1.37 + do_test substr-$id.1 [subst {
1.38 + execsql {
1.39 + SELECT substr(t, $i1, $i2) FROM t1
1.40 + }
1.41 + }] [list $result]
1.42 + set qstr '[string map {' ''} $string]'
1.43 + do_test substr-$id.2 [subst {
1.44 + execsql {
1.45 + SELECT substr($qstr, $i1, $i2)
1.46 + }
1.47 + }] [list $result]
1.48 +}
1.49 +proc subblob-test {id hex i1 i2 hexresult} {
1.50 + db eval "
1.51 + DELETE FROM t1;
1.52 + INSERT INTO t1(b) VALUES(x'$hex')
1.53 + "
1.54 + do_test substr-$id.1 [subst {
1.55 + execsql {
1.56 + SELECT hex(substr(b, $i1, $i2)) FROM t1
1.57 + }
1.58 + }] [list $hexresult]
1.59 + do_test substr-$id.2 [subst {
1.60 + execsql {
1.61 + SELECT hex(substr(x'$hex', $i1, $i2))
1.62 + }
1.63 + }] [list $hexresult]
1.64 +}
1.65 +
1.66 +# Basic SUBSTR functionality
1.67 +#
1.68 +substr-test 1.1 abcdefg 1 1 a
1.69 +substr-test 1.2 abcdefg 2 1 b
1.70 +substr-test 1.3 abcdefg 1 2 ab
1.71 +substr-test 1.4 abcdefg 1 100 abcdefg
1.72 +substr-test 1.5 abcdefg 0 1 a
1.73 +substr-test 1.6 abcdefg -1 1 g
1.74 +substr-test 1.7 abcdefg -1 10 g
1.75 +substr-test 1.8 abcdefg -5 3 cde
1.76 +substr-test 1.9 abcdefg -7 3 abc
1.77 +substr-test 1.10 abcdefg -100 98 abcde
1.78 +
1.79 +# Make sure everything works with long unicode characters
1.80 +#
1.81 +substr-test 2.1 \u1234\u2345\u3456 1 1 \u1234
1.82 +substr-test 2.2 \u1234\u2345\u3456 2 1 \u2345
1.83 +substr-test 2.3 \u1234\u2345\u3456 1 2 \u1234\u2345
1.84 +substr-test 2.4 \u1234\u2345\u3456 -1 1 \u3456
1.85 +substr-test 2.5 a\u1234b\u2345c\u3456c -5 3 b\u2345c
1.86 +
1.87 +# Basic functionality for BLOBs
1.88 +#
1.89 +subblob-test 3.1 61626364656667 1 1 61
1.90 +subblob-test 3.2 61626364656667 2 1 62
1.91 +subblob-test 3.3 61626364656667 1 2 6162
1.92 +subblob-test 3.4 61626364656667 1 100 61626364656667
1.93 +subblob-test 3.5 61626364656667 0 1 61
1.94 +subblob-test 3.6 61626364656667 -1 1 67
1.95 +subblob-test 3.7 61626364656667 -1 10 67
1.96 +subblob-test 3.8 61626364656667 -5 3 636465
1.97 +subblob-test 3.9 61626364656667 -7 3 616263
1.98 +subblob-test 3.10 61626364656667 -100 98 6162636465
1.99 +
1.100 +# If these blobs were strings, then they would contain multi-byte
1.101 +# characters. But since they are blobs, the substr indices refer
1.102 +# to bytes.
1.103 +#
1.104 +subblob-test 4.1 61E188B462E28D8563E3919663 1 1 61
1.105 +subblob-test 4.2 61E188B462E28D8563E3919663 2 1 E1
1.106 +subblob-test 4.3 61E188B462E28D8563E3919663 1 2 61E1
1.107 +subblob-test 4.4 61E188B462E28D8563E3919663 -2 1 96
1.108 +subblob-test 4.5 61E188B462E28D8563E3919663 -5 4 63E39196
1.109 +subblob-test 4.6 61E188B462E28D8563E3919663 -100 98 61E188B462E28D8563E391
1.110 +
1.111 +# Two-argument SUBSTR
1.112 +#
1.113 +proc substr-2-test {id string idx result} {
1.114 + db eval {
1.115 + DELETE FROM t1;
1.116 + INSERT INTO t1(t) VALUES($string)
1.117 + }
1.118 + do_test substr-$id.1 [subst {
1.119 + execsql {
1.120 + SELECT substr(t, $idx) FROM t1
1.121 + }
1.122 + }] [list $result]
1.123 + set qstr '[string map {' ''} $string]'
1.124 + do_test substr-$id.2 [subst {
1.125 + execsql {
1.126 + SELECT substr($qstr, $idx)
1.127 + }
1.128 + }] [list $result]
1.129 +}
1.130 +substr-2-test 5.1 abcdefghijklmnop 5 efghijklmnop
1.131 +substr-2-test 5.2 abcdef -5 bcdef
1.132 +
1.133 +finish_test