interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / unhex.test

102 lines · 2343 bytes Raw Blame History
1# 2023 January 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
13set testdir [file dirname $argv0]
14source [file join $testdir tester.tcl]
15
16set testprefix unhex
17
18
19foreach {tn hex} {
20 1 0000
21 2 FFFF
22 3 0123456789ABCDEF
23} {
24 do_execsql_test 1.$tn.1 {
25 SELECT hex( unhex( $hex ) );
26 } $hex
27
28 do_execsql_test 1.$tn.2 {
29 SELECT hex( unhex( lower( $hex ) ) );
30 } $hex
31}
32
33do_execsql_test 2.0 {
34 SELECT typeof( unhex('') ), length( unhex('') );
35} {blob 0}
36
37foreach {tn hex} {
38 1 ABC
39 2 hello
40 3 123456x7
41 4 0xff
42} {
43 do_execsql_test 2.$tn {
44 SELECT unhex( $hex ) IS NULL;
45 } 1
46}
47
48do_catchsql_test 3.0 {
49 SELECT unhex();
50} {1 {wrong number of arguments to function unhex()}}
51do_catchsql_test 3.1 {
52 SELECT unhex('ABCD', '1234', '');
53} {1 {wrong number of arguments to function unhex()}}
54
55#--------------------------------------------------------------------------
56# Test the 2-argument version.
57#
58# Zap global x array set in some previous test.
59if {[array exists x]} {array unset x}
60foreach {tn hex} {
61 1 "FFFF ABCD"
62 2 "FFFF ABCD"
63 3 "FFFFABCD "
64 4 " FFFFABCD"
65 5 "--FFFF AB- -CD- "
66 6 "--"
67 7 " --"
68} {
69 set out ""
70 foreach x [split $hex ""] {
71 if {[string is xdigit $x]} { append out $x }
72 }
73
74 do_execsql_test 5.$tn.1 {
75 SELECT hex( unhex($hex, ' -') );
76 } [list $out]
77}
78
79do_execsql_test 6.0 {
80 SELECT typeof( unhex(' ', ' -') ), length( unhex('-', ' -') );
81} {blob 0}
82
83
84do_execsql_test 6.1 "
85 SELECT hex( unhex('\u0E01ABCD\u0E02', '\uE01\uE02') )
86" {ABCD}
87do_execsql_test 6.2 "
88 SELECT typeof( unhex('\u0E01ABCD\u0E02', '\uE03\uE02') )
89" {null}
90do_execsql_test 6.3 "
91 SELECT hex( unhex('\u0E01AB CD\uE02\uE01', '\uE01 \uE02') )
92" {ABCD}
93
94#--------------------------------------------------------------------------
95# Test that if either argument is NULL, the returned value is also NULL.
96#
97do_execsql_test 6.4.1 { SELECT typeof(unhex(NULL)) } {null}
98do_execsql_test 6.4.2 { SELECT typeof(unhex(NULL, ' ')) } {null}
99do_execsql_test 6.4.3 { SELECT typeof(unhex('1234', NULL)) } {null}
100
101
102finish_test