xref: /sqlite-3.40.0/test/cast.test (revision 4dcbdbff)
1# 2005 June 25
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# This file implements regression tests for SQLite library.  The
12# focus of this file is testing the CAST operator.
13#
14# $Id: cast.test,v 1.2 2005/06/25 19:31:48 drh Exp $
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19# Only run these tests if the build includes the CAST operator
20ifcapable !cast {
21  finish_test
22  return
23}
24
25# Tests for the CAST( AS blob), CAST( AS text) and CAST( AS numeric) built-ins
26#
27do_test cast-1.1 {
28  execsql {SELECT x'616263'}
29} abc
30do_test cast-1.2 {
31  execsql {SELECT typeof(x'616263')}
32} blob
33do_test cast-1.3 {
34  execsql {SELECT CAST(x'616263' AS text)}
35} abc
36do_test cast-1.4 {
37  execsql {SELECT typeof(CAST(x'616263' AS text))}
38} text
39do_test cast-1.5 {
40  execsql {SELECT CAST(x'616263' AS numeric)}
41} 0.0
42do_test cast-1.6 {
43  execsql {SELECT typeof(CAST(x'616263' AS numeric))}
44} real
45do_test cast-1.7 {
46  execsql {SELECT CAST(x'616263' AS blob)}
47} abc
48do_test cast-1.8 {
49  execsql {SELECT typeof(CAST(x'616263' AS blob))}
50} blob
51do_test cast-1.9 {
52  execsql {SELECT CAST(x'616263' AS integer)}
53} 0
54do_test cast-1.10 {
55  execsql {SELECT typeof(CAST(x'616263' AS integer))}
56} integer
57do_test cast-1.11 {
58  execsql {SELECT null}
59} {{}}
60do_test cast-1.12 {
61  execsql {SELECT typeof(NULL)}
62} null
63do_test cast-1.13 {
64  execsql {SELECT CAST(NULL AS text)}
65} {{}}
66do_test cast-1.14 {
67  execsql {SELECT typeof(CAST(NULL AS text))}
68} null
69do_test cast-1.15 {
70  execsql {SELECT CAST(NULL AS numeric)}
71} {{}}
72do_test cast-1.16 {
73  execsql {SELECT typeof(CAST(NULL AS numeric))}
74} null
75do_test cast-1.17 {
76  execsql {SELECT CAST(NULL AS blob)}
77} {{}}
78do_test cast-1.18 {
79  execsql {SELECT typeof(CAST(NULL AS blob))}
80} null
81do_test cast-1.19 {
82  execsql {SELECT CAST(NULL AS integer)}
83} {{}}
84do_test cast-1.20 {
85  execsql {SELECT typeof(CAST(NULL AS integer))}
86} null
87do_test cast-1.21 {
88  execsql {SELECT 123}
89} {123}
90do_test cast-1.22 {
91  execsql {SELECT typeof(123)}
92} integer
93do_test cast-1.23 {
94  execsql {SELECT CAST(123 AS text)}
95} {123}
96do_test cast-1.24 {
97  execsql {SELECT typeof(CAST(123 AS text))}
98} text
99do_test cast-1.25 {
100  execsql {SELECT CAST(123 AS numeric)}
101} 123
102do_test cast-1.26 {
103  execsql {SELECT typeof(CAST(123 AS numeric))}
104} integer
105do_test cast-1.27 {
106  execsql {SELECT CAST(123 AS blob)}
107} {123}
108do_test cast-1.28 {
109  execsql {SELECT typeof(CAST(123 AS blob))}
110} blob
111do_test cast-1.29 {
112  execsql {SELECT CAST(123 AS integer)}
113} {123}
114do_test cast-1.30 {
115  execsql {SELECT typeof(CAST(123 AS integer))}
116} integer
117do_test cast-1.31 {
118  execsql {SELECT 123.456}
119} {123.456}
120do_test cast-1.32 {
121  execsql {SELECT typeof(123.456)}
122} real
123do_test cast-1.33 {
124  execsql {SELECT CAST(123.456 AS text)}
125} {123.456}
126do_test cast-1.34 {
127  execsql {SELECT typeof(CAST(123.456 AS text))}
128} text
129do_test cast-1.35 {
130  execsql {SELECT CAST(123.456 AS numeric)}
131} 123.456
132do_test cast-1.36 {
133  execsql {SELECT typeof(CAST(123.456 AS numeric))}
134} real
135do_test cast-1.37 {
136  execsql {SELECT CAST(123.456 AS blob)}
137} {123.456}
138do_test cast-1.38 {
139  execsql {SELECT typeof(CAST(123.456 AS blob))}
140} blob
141do_test cast-1.39 {
142  execsql {SELECT CAST(123.456 AS integer)}
143} {123}
144do_test cast-1.38 {
145  execsql {SELECT typeof(CAST(123.456 AS integer))}
146} integer
147do_test cast-1.41 {
148  execsql {SELECT '123abc'}
149} {123abc}
150do_test cast-1.42 {
151  execsql {SELECT typeof('123abc')}
152} text
153do_test cast-1.43 {
154  execsql {SELECT CAST('123abc' AS text)}
155} {123abc}
156do_test cast-1.44 {
157  execsql {SELECT typeof(CAST('123abc' AS text))}
158} text
159do_test cast-1.45 {
160  execsql {SELECT CAST('123abc' AS numeric)}
161} 123.0
162do_test cast-1.46 {
163  execsql {SELECT typeof(CAST('123abc' AS numeric))}
164} real
165do_test cast-1.47 {
166  execsql {SELECT CAST('123abc' AS blob)}
167} {123abc}
168do_test cast-1.48 {
169  execsql {SELECT typeof(CAST('123abc' AS blob))}
170} blob
171do_test cast-1.49 {
172  execsql {SELECT CAST('123abc' AS integer)}
173} 123
174do_test cast-1.50 {
175  execsql {SELECT typeof(CAST('123abc' AS integer))}
176} integer
177do_test cast-1.51 {
178  execsql {SELECT CAST('123.5abc' AS numeric)}
179} 123.5
180do_test cast-1.53 {
181  execsql {SELECT CAST('123.5abc' AS integer)}
182} 123
183
184finish_test
185