Add tests to e_expr.test.

FossilOrigin-Name: 5c1c694ee1b3b71e20089412f6cba1847dc7f958
This commit is contained in:
dan 2010-08-24 13:11:52 +00:00
parent ee2c813b72
commit eb385b4093
3 changed files with 283 additions and 18 deletions

View File

@ -1,8 +1,5 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C The\sR-tree\smodule\sshould\snot\sassume\sthat\sits\sshadow\stables\sare\sconsistent.\nIf\sa\sproblem\sis\sfound\sin\sa\sshadow\stable,\sreturn\sSQLITE_CORRUPT.
D 2010-08-24T01:49:48
C Add\stests\sto\se_expr.test.
D 2010-08-24T13:11:53
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 543f91f24cd7fee774ecc0a61c19704c0c3e78fd
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -344,7 +341,7 @@ F test/descidx2.test 9f1a0c83fd57f8667c82310ca21b30a350888b5d
F test/descidx3.test fe720e8b37d59f4cef808b0bf4e1b391c2e56b6f
F test/diskfull.test 0cede7ef9d8f415d9d3944005c76be7589bb5ebb
F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
F test/e_expr.test 8a35ce2718c61e871970bda09f4f3e549067c1ba
F test/e_expr.test 1c531745c94f091445157fb7953a2cc3f256f8e4
F test/e_fkey.test 6721a741c6499b3ab7e5385923233343c8f1ad05
F test/e_fts3.test 75bb0aee26384ef586165e21018a17f7cd843469
F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
@ -849,14 +846,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 42537b60566f288167f1b5864a5435986838e3a3
R 2c180f83601b5fb3eca266f1d7990e7f
U drh
Z 10d60dee314996598be1db5d0c7786c6
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFMcyU/oxKgR168RlERAix8AJ4mlLsRwIdCGZXuMMz9jxnrImU9JACffIYe
yL2XIDq+iw10tkqZ3HaRjys=
=n6uZ
-----END PGP SIGNATURE-----
P 7f2f71cc9e3c39093f09231f448576cff6afb5fe
R aba17ed62d7523dad2435b92dcbb7f3b
U dan
Z 181c658325527cf2c74e166fe7d3a968

View File

@ -1 +1 @@
7f2f71cc9e3c39093f09231f448576cff6afb5fe
5c1c694ee1b3b71e20089412f6cba1847dc7f958

View File

@ -1102,5 +1102,280 @@ do_execsql_test e_expr-19.2.3 { SELECT 'X' NOT MATCH 'Y' } 0
do_test e_expr-19.2.4 { set matchargs } {Y X}
sqlite3 db test.db
#-------------------------------------------------------------------------
# Test cases for the testable statements related to the CASE expression.
#
# EVIDENCE-OF: R-15199-61389 There are two basic forms of the CASE
# expression: those with a base expression and those without.
#
do_execsql_test e_expr-20.1 {
SELECT CASE WHEN 1 THEN 'true' WHEN 0 THEN 'false' ELSE 'else' END;
} {true}
do_execsql_test e_expr-20.2 {
SELECT CASE 0 WHEN 1 THEN 'true' WHEN 0 THEN 'false' ELSE 'else' END;
} {false}
proc var {nm} {
lappend ::varlist $nm
return [set "::$nm"]
}
db func var var
# EVIDENCE-OF: R-30638-59954 In a CASE without a base expression, each
# WHEN expression is evaluated and the result treated as a boolean,
# starting with the leftmost and continuing to the right.
#
foreach {a b c} {0 0 0} break
set varlist [list]
do_execsql_test e_expr-21.1.1 {
SELECT CASE WHEN var('a') THEN 'A'
WHEN var('b') THEN 'B'
WHEN var('c') THEN 'C' END
} {{}}
do_test e_expr-21.1.2 { set varlist } {a b c}
set varlist [list]
do_execsql_test e_expr-21.1.3 {
SELECT CASE WHEN var('c') THEN 'C'
WHEN var('b') THEN 'B'
WHEN var('a') THEN 'A'
ELSE 'no result'
END
} {{no result}}
do_test e_expr-21.1.4 { set varlist } {c b a}
# EVIDENCE-OF: R-39009-25596 The result of the CASE expression is the
# evaluation of the THEN expression that corresponds to the first WHEN
# expression that evaluates to true.
#
foreach {a b c} {0 1 0} break
do_execsql_test e_expr-21.2.1 {
SELECT CASE WHEN var('a') THEN 'A'
WHEN var('b') THEN 'B'
WHEN var('c') THEN 'C'
ELSE 'no result'
END
} {B}
foreach {a b c} {0 1 1} break
do_execsql_test e_expr-21.2.2 {
SELECT CASE WHEN var('a') THEN 'A'
WHEN var('b') THEN 'B'
WHEN var('c') THEN 'C'
ELSE 'no result'
END
} {B}
foreach {a b c} {0 0 1} break
do_execsql_test e_expr-21.2.3 {
SELECT CASE WHEN var('a') THEN 'A'
WHEN var('b') THEN 'B'
WHEN var('c') THEN 'C'
ELSE 'no result'
END
} {C}
# EVIDENCE-OF: R-24227-04807 Or, if none of the WHEN expressions
# evaluate to true, the result of evaluating the ELSE expression, if
# any.
#
foreach {a b c} {0 0 0} break
do_execsql_test e_expr-21.3.1 {
SELECT CASE WHEN var('a') THEN 'A'
WHEN var('b') THEN 'B'
WHEN var('c') THEN 'C'
ELSE 'no result'
END
} {{no result}}
# EVIDENCE-OF: R-14168-07579 If there is no ELSE expression and none of
# the WHEN expressions are true, then the overall result is NULL.
#
db nullvalue null
do_execsql_test e_expr-21.3.2 {
SELECT CASE WHEN var('a') THEN 'A'
WHEN var('b') THEN 'B'
WHEN var('c') THEN 'C'
END
} {null}
db nullvalue {}
# EVIDENCE-OF: R-13943-13592 A NULL result is considered untrue when
# evaluating WHEN terms.
#
do_execsql_test e_expr-21.4.1 {
SELECT CASE WHEN NULL THEN 'A' WHEN 1 THEN 'B' END
} {B}
do_execsql_test e_expr-21.4.2 {
SELECT CASE WHEN 0 THEN 'A' WHEN NULL THEN 'B' ELSE 'C' END
} {C}
# EVIDENCE-OF: R-38620-19499 In a CASE with a base expression, the base
# expression is evaluated just once and the result is compared against
# the evaluation of each WHEN expression from left to right.
#
# Note: This test case tests the "evaluated just once" part of the above
# statement. Tests associated with the next two statements test that the
# comparisons take place.
#
foreach {a b c} [list [expr 3] [expr 4] [expr 5]] break
set ::varlist [list]
do_execsql_test e_expr-22.1.1 {
SELECT CASE var('a') WHEN 1 THEN 'A' WHEN 2 THEN 'B' WHEN 3 THEN 'C' END
} {C}
do_test e_expr-22.1.2 { set ::varlist } {a}
# EVIDENCE-OF: R-07667-49537 The result of the CASE expression is the
# evaluation of the THEN expression that corresponds to the first WHEN
# expression for which the comparison is true.
#
do_execsql_test e_expr-22.2.1 {
SELECT CASE 23 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END
} {B}
do_execsql_test e_expr-22.2.2 {
SELECT CASE 1 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END
} {A}
# EVIDENCE-OF: R-47543-32145 Or, if none of the WHEN expressions
# evaluate to a value equal to the base expression, the result of
# evaluating the ELSE expression, if any.
#
do_execsql_test e_expr-22.3.1 {
SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' ELSE 'D' END
} {D}
# EVIDENCE-OF: R-54721-48557 If there is no ELSE expression and none of
# the WHEN expressions produce a result equal to the base expression,
# the overall result is NULL.
#
do_execsql_test e_expr-22.4.1 {
SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END
} {{}}
db nullvalue null
do_execsql_test e_expr-22.4.2 {
SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END
} {null}
db nullvalue {}
# EVIDENCE-OF: R-11479-62774 When comparing a base expression against a
# WHEN expression, the same collating sequence, affinity, and
# NULL-handling rules apply as if the base expression and WHEN
# expression are respectively the left- and right-hand operands of an =
# operator.
#
proc rev {str} {
set ret ""
set chars [split $str]
for {set i [expr [llength $chars]-1]} {$i>=0} {incr i -1} {
append ret [lindex $chars $i]
}
set ret
}
proc reverse {lhs rhs} {
string compare [rev $lhs] [ref $rhs]
}
db collate reverse reverse
do_execsql_test e_expr-23.1.1 {
CREATE TABLE t1(
a TEXT COLLATE NOCASE,
b COLLATE REVERSE,
c INTEGER,
d BLOB
);
INSERT INTO t1 VALUES('abc', 'cba', 55, 34.5);
} {}
do_execsql_test e_expr-23.1.2 {
SELECT CASE a WHEN 'xyz' THEN 'A' WHEN 'AbC' THEN 'B' END FROM t1
} {B}
do_execsql_test e_expr-23.1.3 {
SELECT CASE 'AbC' WHEN 'abc' THEN 'A' WHEN a THEN 'B' END FROM t1
} {B}
do_execsql_test e_expr-23.1.4 {
SELECT CASE a WHEN b THEN 'A' ELSE 'B' END FROM t1
} {B}
do_execsql_test e_expr-23.1.5 {
SELECT CASE b WHEN a THEN 'A' ELSE 'B' END FROM t1
} {A}
do_execsql_test e_expr-23.1.6 {
SELECT CASE 55 WHEN '55' THEN 'A' ELSE 'B' END
} {B}
do_execsql_test e_expr-23.1.7 {
SELECT CASE c WHEN '55' THEN 'A' ELSE 'B' END FROM t1
} {A}
do_execsql_test e_expr-23.1.8 {
SELECT CASE '34.5' WHEN d THEN 'A' ELSE 'B' END FROM t1
} {B}
do_execsql_test e_expr-23.1.9 {
SELECT CASE NULL WHEN NULL THEN 'A' ELSE 'B' END
} {B}
# EVIDENCE-OF: R-37304-39405 If the base expression is NULL then the
# result of the CASE is always the result of evaluating the ELSE
# expression if it exists, or NULL if it does not.
#
do_execsql_test e_expr-24.1.1 {
SELECT CASE NULL WHEN 'abc' THEN 'A' WHEN 'def' THEN 'B' END;
} {{}}
do_execsql_test e_expr-24.1.2 {
SELECT CASE NULL WHEN 'abc' THEN 'A' WHEN 'def' THEN 'B' ELSE 'C' END;
} {C}
# EVIDENCE-OF: R-56280-17369 Both forms of the CASE expression use lazy,
# or short-circuit, evaluation.
#
set varlist [list]
foreach {a b c} {0 1 0} break
do_execsql_test e_expr-25.1.1 {
SELECT CASE WHEN var('a') THEN 'A'
WHEN var('b') THEN 'B'
WHEN var('c') THEN 'C'
END
} {B}
do_test e_expr-25.1.2 { set ::varlist } {a b}
set varlist [list]
do_execsql_test e_expr-25.1.3 {
SELECT CASE '0' WHEN var('a') THEN 'A'
WHEN var('b') THEN 'B'
WHEN var('c') THEN 'C'
END
} {A}
do_test e_expr-25.1.4 { set ::varlist } {a}
# EVIDENCE-OF: R-34773-62253 The only difference between the following
# two CASE expressions is that the x expression is evaluated exactly
# once in the first example but might be evaluated multiple times in the
# second: CASE x WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END CASE WHEN
# x=w1 THEN r1 WHEN x=w2 THEN r2 ELSE r3 END
#
proc ceval {x} {
incr ::evalcount
return $x
}
db func ceval ceval
set ::evalcount 0
do_execsql_test e_expr-26.1.1 {
CREATE TABLE t2(x, w1, r1, w2, r2, r3);
INSERT INTO t2 VALUES(1, 1, 'R1', 2, 'R2', 'R3');
INSERT INTO t2 VALUES(2, 1, 'R1', 2, 'R2', 'R3');
INSERT INTO t2 VALUES(3, 1, 'R1', 2, 'R2', 'R3');
} {}
do_execsql_test e_expr-26.1.2 {
SELECT CASE x WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END FROM t2
} {R1 R2 R3}
do_execsql_test e_expr-26.1.3 {
SELECT CASE WHEN x=w1 THEN r1 WHEN x=w2 THEN r2 ELSE r3 END FROM t2
} {R1 R2 R3}
do_execsql_test e_expr-26.1.4 {
SELECT CASE ceval(x) WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END FROM t2
} {R1 R2 R3}
do_test e_expr-26.1.5 { set ::evalcount } {3}
set ::evalcount 0
do_execsql_test e_expr-26.1.6 {
SELECT CASE
WHEN ceval(x)=w1 THEN r1
WHEN ceval(x)=w2 THEN r2
ELSE r3 END
FROM t2
} {R1 R2 R3}
do_test e_expr-26.1.6 { set ::evalcount } {5}
finish_test