1# 2014-07-23 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# This file implements tests for hexadecimal literals 13 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17 18proc hexlit1 {tnum val ans} { 19 do_execsql_test hexlit-$tnum "SELECT $val" $ans 20} 21 22hexlit1 100 0x0 0 23hexlit1 101 0x0000000000000000000000000000000000000000000001 1 24hexlit1 102 0x2 2 25hexlit1 103 0x4 4 26hexlit1 104 0x8 8 27hexlit1 105 0x00000000000000000000000000000000000000000000010 16 28hexlit1 103 0x20 32 29hexlit1 106 0x40 64 30hexlit1 107 0x80 128 31hexlit1 108 0x100 256 32hexlit1 109 0x200 512 33hexlit1 110 0X400 1024 34hexlit1 111 0x800 2048 35hexlit1 112 0x1000 4096 36hexlit1 113 0x2000 8192 37hexlit1 114 0x4000 16384 38hexlit1 115 0x8000 32768 39hexlit1 116 0x10000 65536 40hexlit1 117 0x20000 131072 41hexlit1 118 0x40000 262144 42hexlit1 119 0x80000 524288 43hexlit1 120 0x100000 1048576 44hexlit1 121 0x200000 2097152 45hexlit1 122 0x400000 4194304 46hexlit1 123 0x800000 8388608 47hexlit1 124 0x1000000 16777216 48hexlit1 125 0x2000000 33554432 49hexlit1 126 0x4000000 67108864 50hexlit1 127 0x8000000 134217728 51hexlit1 128 0x10000000 268435456 52hexlit1 129 0x20000000 536870912 53hexlit1 130 0x40000000 1073741824 54hexlit1 131 0x80000000 2147483648 55hexlit1 132 0x100000000 4294967296 56hexlit1 133 0x200000000 8589934592 57hexlit1 134 0x400000000 17179869184 58hexlit1 135 0x800000000 34359738368 59hexlit1 136 0x1000000000 68719476736 60hexlit1 137 0x2000000000 137438953472 61hexlit1 138 0x4000000000 274877906944 62hexlit1 139 0x8000000000 549755813888 63hexlit1 140 0x10000000000 1099511627776 64hexlit1 141 0x20000000000 2199023255552 65hexlit1 142 0x40000000000 4398046511104 66hexlit1 143 0x80000000000 8796093022208 67hexlit1 144 0x100000000000 17592186044416 68hexlit1 145 0x200000000000 35184372088832 69hexlit1 146 0x400000000000 70368744177664 70hexlit1 147 0x800000000000 140737488355328 71hexlit1 148 0x1000000000000 281474976710656 72hexlit1 149 0x2000000000000 562949953421312 73hexlit1 150 0x4000000000000 1125899906842624 74hexlit1 151 0x8000000000000 2251799813685248 75hexlit1 152 0x10000000000000 4503599627370496 76hexlit1 153 0x20000000000000 9007199254740992 77hexlit1 154 0x40000000000000 18014398509481984 78hexlit1 155 0x80000000000000 36028797018963968 79hexlit1 156 0x100000000000000 72057594037927936 80hexlit1 157 0x200000000000000 144115188075855872 81hexlit1 158 0x400000000000000 288230376151711744 82hexlit1 159 0x800000000000000 576460752303423488 83hexlit1 160 0X1000000000000000 1152921504606846976 84hexlit1 161 0x2000000000000000 2305843009213693952 85hexlit1 162 0X4000000000000000 4611686018427387904 86hexlit1 163 0x8000000000000000 -9223372036854775808 87hexlit1 164 0XFFFFFFFFFFFFFFFF -1 88 89for {set n 1} {$n < 0x10} {incr n} { 90 hexlit1 200.$n.1 0X[format %03X $n] $n 91 hexlit1 200.$n.2 0x[format %03X $n] $n 92 hexlit1 200.$n.3 0X[format %03x $n] $n 93 hexlit1 200.$n.4 0x[format %03x $n] $n 94} 95 96# String literals that look like hex do not get cast or coerced. 97# 98do_execsql_test hexlit-300 { 99 CREATE TABLE t1(x INT, y REAL); 100 INSERT INTO t1 VALUES('1234','4567'),('0x1234','0x4567'); 101 SELECT typeof(x), x, typeof(y), y, '#' FROM t1 ORDER BY rowid; 102} {integer 1234 real 4567.0 # text 0x1234 text 0x4567 #} 103do_execsql_test hexlit-301 { 104 SELECT CAST('0x1234' AS INTEGER); 105} {0} 106 107# Oversized hex literals are rejected 108# 109do_catchsql_test hexlist-400 { 110 SELECT 0x10000000000000000; 111} {1 {hex literal too big: 0x10000000000000000}} 112do_catchsql_test hexlist-401 { 113 SELECT DISTINCT 0x10000000000000000; 114} {1 {hex literal too big: 0x10000000000000000}} 115do_catchsql_test hexlist-402 { 116 SELECT DISTINCT -0x08000000000000000; 117} {1 {hex literal too big: -0x08000000000000000}} 118do_catchsql_test hexlist-410 { 119 DROP TABLE IF EXISTS t1; 120 CREATE TABLE t1(x); 121 INSERT INTO t1 VALUES(1+0x10000000000000000); 122} {1 {hex literal too big: 0x10000000000000000}} 123 124 125finish_test 126