gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/prefixes.test (about) 1 # 2018-01-15 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 prefixes.c extension 13 # 14 15 set testdir [file dirname $argv0] 16 source $testdir/tester.tcl 17 set testprefix unionvtab 18 19 ifcapable !vtab { 20 finish_test 21 return 22 } 23 24 load_static_extension db prefixes 25 26 foreach {tn zLeft zRight expected} { 27 1 abcdxxx abcyy 3 28 2 abcdxxx bcyyy 0 29 3 abcdxxx ab 2 30 4 ab abcd 2 31 32 5 "xyz\u1234xz" "xyz\u1234xy" 5 33 6 "xyz\u1234" "xyz\u1234xy" 4 34 7 "xyz\u1234" "xyz\u1234" 4 35 8 "xyz\u1234xy" "xyz\u1234" 4 36 9 "xyz\u1234xy" "xyz\u1233" 3 37 10 "xyz\u1234xy" "xyz\u1235" 3 38 } { 39 do_execsql_test 1.$tn { SELECT prefix_length($zLeft, $zRight) } $expected 40 } 41 42 43 do_execsql_test 2.0 { 44 CREATE TABLE t1(k TEXT UNIQUE, v INTEGER); 45 INSERT INTO t1 VALUES 46 ('aback', 1), 47 ('abaft', 2), 48 ('abandon', 3), 49 ('abandoned', 4), 50 ('abandoning', 5), 51 ('abandonment', 6), 52 ('abandons', 7), 53 ('abase', 8), 54 ('abased', 9), 55 ('abasement', 10), 56 ('abasements', 11), 57 ('abases', 12), 58 ('abash', 13), 59 ('abashed', 14), 60 ('abashes', 15), 61 ('abashing', 16), 62 ('abasing', 17), 63 ('abate', 18), 64 ('abated', 19), 65 ('abatement', 20), 66 ('abatements', 21); 67 } 68 69 foreach {tn INPUT expected} { 70 1 abatementt abatement 71 2 abashet abash 72 3 abandonio abandon 73 4 abasemenu abase 74 } { 75 do_execsql_test 2.$tn { 76 WITH finder(str) AS ( 77 SELECT (SELECT max(k) FROM t1 WHERE k<=$INPUT) 78 UNION ALL 79 SELECT ( 80 SELECT max(k) FROM t1 81 WHERE k<=substr($INPUT, 1, prefix_length(finder.str, $INPUT)) 82 ) FROM finder WHERE length(finder.str)>0 83 ) 84 SELECT str FROM finder WHERE length(str)==prefix_length(str, $INPUT) LIMIT 1 85 } $expected 86 } 87 88 finish_test