1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

Bug fix and initial test-case infrastructure for control-character escaping

in the CLI.

FossilOrigin-Name: c809997792602a7299b8ab84d018a03d291695e308ce750fc8b9d7a824edfd6e
This commit is contained in:
drh
2025-02-24 13:27:16 +00:00
parent 21b431e685
commit 7db5e50b8d
4 changed files with 98 additions and 8 deletions

89
test/shellA.test Normal file
View File

@ -0,0 +1,89 @@
# 2025-02-24
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Test cases for the command-line shell - focusing on .mode and
# especially control-character escaping and the --escape option.
#
# TESTRUNNER: shell
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set CLI [test_cli_invocation]
db close
forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db
do_execsql_test shellA-1.0 {
CREATE TABLE t1(a INT, x TEXT);
INSERT INTO t1 VALUES
(1, 'line with '' single quote'),
(2, concat(char(0x1b),'[31mVT-100 codes',char(0x1b),'[0m')),
(3, NULL),
(4, 1234),
(5, 568.25),
(6, unistr('new\u000aline')),
(7, unistr('carriage\u000dreturn')),
(8, 'last line');
} {}
# Initial verification that the database created correctly
# and that our calls to the CLI are working.
#
do_test shellA-1.2 {
exec $CLI test.db {.mode box} {SELECT * FROM t1;}
} {
┌───┬──────────────────────────┐
│ a │ x │
├───┼──────────────────────────┤
│ 1 │ line with ' single quote │
├───┼──────────────────────────┤
│ 2 │ ␛[31mVT-100 codes␛[0m │
├───┼──────────────────────────┤
│ 3 │ │
├───┼──────────────────────────┤
│ 4 │ 1234 │
├───┼──────────────────────────┤
│ 5 │ 568.25 │
├───┼──────────────────────────┤
│ 6 │ new │
│ │ line │
├───┼──────────────────────────┤
│ 7 │ carriage␍return │
├───┼──────────────────────────┤
│ 8 │ last line │
└───┴──────────────────────────┘
}
# Default output mode uses symbols for control characters
#
do_test shellA-1.3 {
exec $CLI test.db {SELECT x FROM t1 WHERE a=2;}
} {
␛[31mVT-100 codes␛[0m
}
do_test shellA-1.4 {
exec $CLI test.db --escape ascii {SELECT x FROM t1 WHERE a=2;}
} {
^[[31mVT-100 codes^[[0m
}
do_test shellA-1.5 {
exec $CLI test.db {.mode list --escape symbol} {SELECT x FROM t1 WHERE a=2;}
} {
␛[31mVT-100 codes␛[0m
}
do_test shellA-1.6 {
exec $CLI test.db {.mode list --escape ascii} {SELECT x FROM t1 WHERE a=2;}
} {
^[[31mVT-100 codes^[[0m
}
finish_test