Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/unhex.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 13 set testdir [file dirname $argv0] 14 source [file join $testdir tester.tcl] 15 16 set testprefix unhex 17 18 19 foreach {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 33 do_execsql_test 2.0 { 34 SELECT typeof( unhex('') ), length( unhex('') ); 35 } {blob 0} 36 37 foreach {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 48 do_catchsql_test 3.0 { 49 SELECT unhex(); 50 } {1 {wrong number of arguments to function unhex()}} 51 do_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. 59 if {[array exists x]} {array unset x} 60 foreach {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 79 do_execsql_test 6.0 { 80 SELECT typeof( unhex(' ', ' -') ), length( unhex('-', ' -') ); 81 } {blob 0} 82 83 84 do_execsql_test 6.1 " 85 SELECT hex( unhex('\u0E01ABCD\u0E02', '\uE01\uE02') ) 86 " {ABCD} 87 do_execsql_test 6.2 " 88 SELECT typeof( unhex('\u0E01ABCD\u0E02', '\uE03\uE02') ) 89 " {null} 90 do_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 # 97 do_execsql_test 6.4.1 { SELECT typeof(unhex(NULL)) } {null} 98 do_execsql_test 6.4.2 { SELECT typeof(unhex(NULL, ' ')) } {null} 99 do_execsql_test 6.4.3 { SELECT typeof(unhex('1234', NULL)) } {null} 100 101 102 finish_test