CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
prefixes.test89 linesDownload Raw Back to test
1# 2018-01-152#3# The author disclaims copyright to this source code.  In place of4# 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.  The12# focus of this file is prefixes.c extension13#14 15set testdir [file dirname $argv0]16source $testdir/tester.tcl17set testprefix unionvtab18 19ifcapable !vtab {20  finish_test21  return22}23 24load_static_extension db prefixes25 26foreach {tn zLeft zRight expected} {27  1 abcdxxx abcyy    328  2 abcdxxx bcyyy    029  3 abcdxxx ab       230  4 ab      abcd     231 32  5 "xyz\u1234xz" "xyz\u1234xy" 533  6 "xyz\u1234"   "xyz\u1234xy" 434  7 "xyz\u1234"   "xyz\u1234"   435  8 "xyz\u1234xy" "xyz\u1234"   436  9 "xyz\u1234xy" "xyz\u1233"   337 10 "xyz\u1234xy" "xyz\u1235"   338} {39  do_execsql_test 1.$tn { SELECT prefix_length($zLeft, $zRight) } $expected40}41 42 43do_execsql_test 2.0 {44  CREATE TABLE t1(k TEXT UNIQUE, v INTEGER);45  INSERT INTO t1 VALUES46    ('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 69foreach {tn INPUT expected} {70  1 abatementt   abatement71  2 abashet      abash72  3 abandonio    abandon73  4 abasemenu    abase74} {75  do_execsql_test 2.$tn {76    WITH finder(str) AS (77      SELECT (SELECT max(k) FROM t1 WHERE k<=$INPUT)78        UNION ALL79        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)>083      )84    SELECT str FROM finder WHERE length(str)==prefix_length(str, $INPUT) LIMIT 185  } $expected86}87 88finish_test89