drh | 652fbf5 | 2008-04-01 01:42:41 +0000 | [diff] [blame^] | 1 | # 2008 April 1 |
| 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 | # |
| 12 | # Test cases designed to exercise and verify the logic for |
| 13 | # factoring constant expressions out of loops and for |
| 14 | # common subexpression eliminations. |
| 15 | # |
| 16 | # $Id: cse.test,v 1.1 2008/04/01 01:42:41 drh Exp $ |
| 17 | # |
| 18 | |
| 19 | set testdir [file dirname $argv0] |
| 20 | source $testdir/tester.tcl |
| 21 | |
| 22 | do_test cse-1.1 { |
| 23 | execsql { |
| 24 | CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d, e, f); |
| 25 | INSERT INTO t1 VALUES(1,11,12,13,14,15); |
| 26 | INSERT INTO t1 VALUES(2,21,22,23,24,25); |
| 27 | } |
| 28 | execsql { |
| 29 | SELECT b, -b, ~b, NOT b, NOT NOT b, b-b, b+b, b*b, b/b, b FROM t1 |
| 30 | } |
| 31 | } {11 -11 -12 0 1 0 22 121 1 11 21 -21 -22 0 1 0 42 441 1 21} |
| 32 | do_test cse-1.2 { |
| 33 | execsql { |
| 34 | SELECT b, b%b, b==b, b!=b, b<b, b<=b, b IS NULL, b NOT NULL, b FROM t1 |
| 35 | } |
| 36 | } {11 0 1 0 0 1 0 1 11 21 0 1 0 0 1 0 1 21} |
| 37 | do_test cse-1.3 { |
| 38 | execsql { |
| 39 | SELECT b, abs(b), coalesce(b,-b,NOT b,c,NOT c), c, -c FROM t1; |
| 40 | } |
| 41 | } {11 11 11 12 -12 21 21 21 22 -22} |
| 42 | do_test cse-1.4 { |
| 43 | execsql { |
| 44 | SELECT CASE WHEN a==1 THEN b ELSE c END, b, c FROM t1 |
| 45 | } |
| 46 | } {11 11 12 22 21 22} |
| 47 | do_test cse-1.5 { |
| 48 | execsql { |
| 49 | SELECT CASE a WHEN 1 THEN b WHEN 2 THEN c ELSE d END, b, c, d FROM t1 |
| 50 | } |
| 51 | } {11 11 12 13 22 21 22 23} |
| 52 | do_test cse-1.6 { |
| 53 | execsql { |
| 54 | SELECT CASE b WHEN 11 THEN -b WHEN 21 THEN -c ELSE -d END, b, c, d FROM t1 |
| 55 | } |
| 56 | } {-11 11 12 13 -22 21 22 23} |
| 57 | do_test cse-1.7 { |
| 58 | execsql { |
| 59 | SELECT a, -a, ~a, NOT a, NOT NOT a, a-a, a+a, a*a, a/a, a FROM t1 |
| 60 | } |
| 61 | } {1 -1 -2 0 1 0 2 1 1 1 2 -2 -3 0 1 0 4 4 1 2} |
| 62 | do_test cse-1.8 { |
| 63 | execsql { |
| 64 | SELECT a, a%a, a==a, a!=a, a<a, a<=a, a IS NULL, a NOT NULL, a FROM t1 |
| 65 | } |
| 66 | } {1 0 1 0 0 1 0 1 1 2 0 1 0 0 1 0 1 2} |
| 67 | |
| 68 | |
| 69 | finish_test |