From e2d13486d923426c9e986124ed953070dce8454d Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Thu, 3 Dec 2026 11:59:08 -0500 Subject: [PATCH] improve test coverage for /delimiter special command * 100% test coverage for the /delimiter special command * incidentally improve markup for pending entries in the changelog doc * incidentally improve typing in the /delimiter command unit tests, and remove no-longer-needed "type: ignore" comment --- changelog.md | 7 +++++- mycli_test/pytests/test_delimitercommand.py | 27 ++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 3fe4a3e1..5a0d87c3 100644 --- a/changelog.md +++ b/changelog.md @@ -8,7 +8,7 @@ Features Bug Fixes -------- -* Display DATE and TIME scalars returned by `.|` transforms. +* Display `DATE` and `TIME` scalars returned by `.|` transforms. * Stop truncating `/llm` table schemas at MySQL's `group_concat_max_len`. @@ -17,6 +17,11 @@ Documentation * Note transform limitations when the result contains invalid dates. +Internal +-------- +* Improve test coverage for the `/delimiter` special command. + + v2.32.3 (2026/12/02) ============== diff --git a/mycli_test/pytests/test_delimitercommand.py b/mycli_test/pytests/test_delimitercommand.py index 5ad459d7..3c4ad1ff 100644 --- a/mycli_test/pytests/test_delimitercommand.py +++ b/mycli_test/pytests/test_delimitercommand.py @@ -1,5 +1,3 @@ -# type: ignore - from __future__ import annotations import pytest @@ -67,6 +65,27 @@ def test_split_handles_placeholder_collision_in_original_sql() -> None: ] +@pytest.mark.parametrize( + 'literal', + [ + '\ufffb', + '\ufffb\ufffb', + '\ufffb\ufffb\ufffb', + '\ufffb\ufffb\ufffc\ufffc text', + pytest.param( + '\ufffb\ufffb\ufffc\ufffc', + marks=pytest.mark.xfail(strict=True, reason='Adjacent original and generated placeholders are restored at the wrong offset.'), + ), + ], +) +def test_split_preserves_colliding_delimiter_placeholders(literal: str) -> None: + command = DelimiterCommand() + command.set('$$') + sql = f"select '{literal};'$$ select 2$$" + + assert command._split(sql) == [f"select '{literal};'$$", 'select 2$$'] + + def test_queries_iter_resplits_remaining_input_after_delimiter_change() -> None: command = DelimiterCommand() queries = command.queries_iter('select 1; delimiter $$ select 2$$ select 3$$') @@ -79,7 +98,7 @@ def test_queries_iter_resplits_remaining_input_after_delimiter_change() -> None: assert list(queries) == ['select 2', 'select 3'] -def test_queries_iter_reappends_old_trailing_delimiter_before_resplitting(monkeypatch) -> None: +def test_queries_iter_reappends_old_trailing_delimiter_before_resplitting(monkeypatch: pytest.MonkeyPatch) -> None: command = DelimiterCommand() command._delimiter = ';;' split_calls: list[str] = [] @@ -171,5 +190,5 @@ def test_queries_iter_with_quoted_delimiter_containing_semicolon() -> None: ('select `#a;b`; select 2', ['select `#a;b`', 'select 2']), ], ) -def test_queries_iter_reads_hash_comment_without_a_space(sql, expected) -> None: +def test_queries_iter_reads_hash_comment_without_a_space(sql: str, expected: list[str]) -> None: assert list(DelimiterCommand().queries_iter(sql)) == expected