drh | ff6e911 | 2000-08-28 16:21:58 +0000 | [diff] [blame^] | 1 | # Copyright (c) 1999, 2000 D. Richard Hipp |
| 2 | # |
| 3 | # This program is free software; you can redistribute it and/or |
| 4 | # modify it under the terms of the GNU General Public |
| 5 | # License as published by the Free Software Foundation; either |
| 6 | # version 2 of the License, or (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | # General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public |
| 14 | # License along with this library; if not, write to the |
| 15 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | # Boston, MA 02111-1307, USA. |
| 17 | # |
| 18 | # Author contact information: |
| 19 | # drh@hwaci.com |
| 20 | # http://www.hwaci.com/drh/ |
| 21 | # |
| 22 | #*********************************************************************** |
| 23 | # This file implements regression tests for SQLite library. The |
| 24 | # focus of this file is testing built-in functions. |
| 25 | # |
| 26 | # $Id: func.test,v 1.1 2000/08/28 16:22:00 drh Exp $ |
| 27 | |
| 28 | set testdir [file dirname $argv0] |
| 29 | source $testdir/tester.tcl |
| 30 | |
| 31 | # Create a table to work with. |
| 32 | # |
| 33 | execsql {CREATE TABLE tbl1(t1 text)} |
| 34 | foreach word {this program is free software} { |
| 35 | execsql "INSERT INTO tbl1 VALUES('$word')" |
| 36 | } |
| 37 | |
| 38 | # Make sure the table was created properly. |
| 39 | # |
| 40 | do_test func-0.0 { |
| 41 | execsql {SELECT t1 FROM tbl1 ORDER BY t1} |
| 42 | } {free is program software this} |
| 43 | |
| 44 | # Check out the length() function |
| 45 | # |
| 46 | do_test func-1.0 { |
| 47 | execsql {SELECT length(t1) FROM tbl1 ORDER BY t1} |
| 48 | } {4 2 7 8 4} |
| 49 | do_test func-1.1 { |
| 50 | set r [catch {execsql {SELECT length(*) FROM tbl1 ORDER BY t1}} msg] |
| 51 | lappend r $msg |
| 52 | } {1 {too few arguments to function length()}} |
| 53 | do_test func-1.2 { |
| 54 | set r [catch {execsql {SELECT length(t1,5) FROM tbl1 ORDER BY t1}} msg] |
| 55 | lappend r $msg |
| 56 | } {1 {too many arguments to function length()}} |
| 57 | do_test func-1.3 { |
| 58 | execsql {SELECT length(t1), count(*) FROM tbl1 GROUP BY length(t1) |
| 59 | ORDER BY length(t1)} |
| 60 | } {2 1 4 2 7 1 8 1} |
| 61 | |
| 62 | # Check out the substr() function |
| 63 | # |
| 64 | do_test func-2.0 { |
| 65 | execsql {SELECT substr(t1,1,2) FROM tbl1 ORDER BY t1} |
| 66 | } {fr is pr so th} |
| 67 | do_test func-2.1 { |
| 68 | execsql {SELECT substr(t1,2,1) FROM tbl1 ORDER BY t1} |
| 69 | } {r s r o h} |
| 70 | do_test func-2.2 { |
| 71 | execsql {SELECT substr(t1,3,3) FROM tbl1 ORDER BY t1} |
| 72 | } {ee {} ogr ftw is} |
| 73 | do_test func-2.3 { |
| 74 | execsql {SELECT substr(t1,-1,1) FROM tbl1 ORDER BY t1} |
| 75 | } {e s m e s} |
| 76 | do_test func-2.4 { |
| 77 | execsql {SELECT substr(t1,-1,2) FROM tbl1 ORDER BY t1} |
| 78 | } {e s m e s} |
| 79 | do_test func-2.5 { |
| 80 | execsql {SELECT substr(t1,-2,1) FROM tbl1 ORDER BY t1} |
| 81 | } {e i a r i} |
| 82 | do_test func-2.6 { |
| 83 | execsql {SELECT substr(t1,-2,2) FROM tbl1 ORDER BY t1} |
| 84 | } {ee is am re is} |
| 85 | do_test func-2.7 { |
| 86 | execsql {SELECT substr(t1,-4,2) FROM tbl1 ORDER BY t1} |
| 87 | } {fr {} gr wa th} |
| 88 | do_test func-2.8 { |
| 89 | execsql {SELECT t1 FROM tbl1 ORDER BY substr(t1,2,20)} |
| 90 | } {this software free program is} |
| 91 | |
| 92 | finish_test |