Enhance the command-line completion extension to return the names of
[sqlite.git] / test / istrue.test
blob250f1f9d5d2e4c50bca22bcbd1428d34df4863b1
1 # 2018-02-26
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.  The
12 # focus of this file is testing expressions of the form
14 #        x IS TRUE
15 #        x IS FALSE
16 #        x IS NOT TRUE
17 #        x IS NOT FALSE
19 # Tests are also included for the use of TRUE and FALSE as
20 # literal values.
22 set testdir [file dirname $argv0]
23 source $testdir/tester.tcl
25 do_execsql_test istrue-100 {
26   CREATE TABLE t1(x INTEGER PRIMARY KEY, y BOOLEAN);
27   INSERT INTO t1 VALUES(1, true),(2, false),(3, null);
28   SELECT x FROM t1 WHERE y IS TRUE;
29 } {1}
30 do_execsql_test istrue-110 {
31   SELECT x FROM t1 WHERE y IS FALSE;
32 } {2}
33 do_execsql_test istrue-120 {
34   SELECT x FROM t1 WHERE y IS NULL;
35 } {3}
36 do_execsql_test istrue-130 {
37   SELECT x FROM t1 WHERE y IS NOT TRUE;
38 } {2 3}
39 do_execsql_test istrue-140 {
40   SELECT x FROM t1 WHERE y IS NOT FALSE;
41 } {1 3}
42 do_execsql_test istrue-150 {
43   SELECT x FROM t1 WHERE y IS NOT NULL;
44 } {1 2}
45 unset -nocomplain X
46 set X 9
47 do_execsql_test istrue-160 {
48   SELECT x FROM t1 WHERE y IS TRUE OR (8==$X)
49 } {1}
50 do_execsql_test istrue-170 {
51   SELECT x FROM t1 WHERE y IS FALSE OR (8==$X)
52 } {2}
53 do_execsql_test istrue-180 {
54   SELECT x FROM t1 WHERE y IS NULL OR (8==$X);
55 } {3}
56 do_execsql_test istrue-190 {
57   SELECT x FROM t1 WHERE y IS NOT TRUE OR (8==$X);
58 } {2 3}
59 do_execsql_test istrue-200 {
60   SELECT x FROM t1 WHERE y IS NOT FALSE OR (8==$X);
61 } {1 3}
62 do_execsql_test istrue-210 {
63   SELECT x FROM t1 WHERE y IS NOT NULL OR (8==$X);
64 } {1 2}
66 do_execsql_test istrue-300 {
67   SELECT x,
68          y IS TRUE, y IS FALSE, y is NULL,
69          y IS NOT TRUE, y IS NOT FALSE, y IS NOT NULL, '|'
70     FROM t1 ORDER BY x;
71 } {1 1 0 0 0 1 1 | 2 0 1 0 1 0 1 | 3 0 0 1 1 1 0 |}
73 do_execsql_test istrue-400 {
74   SELECT x FROM t1 WHERE true;
75 } {1 2 3}
76 do_execsql_test istrue-410 {
77   SELECT x FROM t1 WHERE false;
78 } {}
80 do_execsql_test istrue-500 {
81   CREATE TABLE t2(
82      a INTEGER PRIMARY KEY,
83      b BOOLEAN DEFAULT true,
84      c BOOLEAN DEFAULT(true),
85      d BOOLEAN DEFAULT false,
86      e BOOLEAN DEFAULT(false)
87   );
88   INSERT INTO t2 DEFAULT VALUES;
89   SELECT * FROM t2;
90 } {1 1 1 0 0}
91 do_execsql_test istrue-510 {
92   DROP TABLE t2;
93   CREATE TABLE t2(
94      a INTEGER PRIMARY KEY,
95      b BOOLEAN DEFAULT(not true),
96      c BOOLEAN DEFAULT(not false)
97   );
98   INSERT INTO t2(a) VALUES(99);
99   SELECT * FROM t2;
100 } {99 0 1}
101 do_execsql_test istrue-520 {
102   DROP TABLE t2;
103   CREATE TABLE t2(
104      a INTEGER PRIMARY KEY,
105      b BOOLEAN CHECK(b IS TRUE),
106      c BOOLEAN CHECK(c IS FALSE),
107      d BOOLEAN CHECK(d IS NOT TRUE),
108      e BOOLEAN CHECK(e IS NOT FALSE)
109   );
110   INSERT INTO t2 VALUES(1,true,false,null,null);
111   SELECT * FROM t2;
112 } {1 1 0 {} {}}
113 do_catchsql_test istrue-521 {
114   INSERT INTO t2 VALUES(2,false,false,null,null);
115 } {1 {CHECK constraint failed: t2}}
116 do_catchsql_test istrue-522 {
117   INSERT INTO t2 VALUES(2,true,true,null,null);
118 } {1 {CHECK constraint failed: t2}}
119 do_catchsql_test istrue-523 {
120   INSERT INTO t2 VALUES(2,true,false,true,null);
121 } {1 {CHECK constraint failed: t2}}
122 do_catchsql_test istrue-524 {
123   INSERT INTO t2 VALUES(2,true,false,null,false);
124 } {1 {CHECK constraint failed: t2}}
126 finish_test