|
17 | 17 | sqlit --mock=perf-test --demo-rows=1000 # 1k rows |
18 | 18 | sqlit --mock=perf-test --demo-rows=10000 # 10k rows |
19 | 19 | sqlit --mock=sqlite-demo --demo-rows=5000 # Any profile works |
| 20 | +
|
| 21 | +Long Text Testing: |
| 22 | + Use --demo-long-text to generate data with long varchar columns. |
| 23 | + Useful for testing how the UI handles text truncation. |
| 24 | +
|
| 25 | + Examples: |
| 26 | + sqlit --mock=sqlite-demo --demo-long-text # 10 rows with long text |
| 27 | + sqlit --mock=sqlite-demo --demo-long-text --demo-rows=50 # 50 rows with long text |
20 | 28 | """ |
21 | 29 |
|
22 | 30 | from __future__ import annotations |
@@ -74,6 +82,45 @@ def _generate_fake_data(row_count: int) -> tuple[list[str], list[tuple]]: |
74 | 82 | return columns, rows |
75 | 83 |
|
76 | 84 |
|
| 85 | +def _generate_long_text_data(row_count: int) -> tuple[list[str], list[tuple]]: |
| 86 | + """Generate data with long varchar columns for testing truncation. |
| 87 | +
|
| 88 | + Creates columns with varying text lengths to test UI truncation behavior. |
| 89 | + Useful for verifying how long text fields are displayed/truncated. |
| 90 | +
|
| 91 | + Args: |
| 92 | + row_count: Number of rows to generate. |
| 93 | +
|
| 94 | + Returns: |
| 95 | + Tuple of (columns, rows). |
| 96 | + """ |
| 97 | + # Column lengths designed to test truncation boundaries |
| 98 | + text_lengths = { |
| 99 | + "short_text": 15, # Short, no truncation expected |
| 100 | + "medium_text": 50, # Around typical column width |
| 101 | + "long_text": 150, # Definitely needs truncation |
| 102 | + "very_long_text": 500, # Very long content |
| 103 | + "description": 300, # Realistic long field |
| 104 | + } |
| 105 | + |
| 106 | + columns = ["id", "name"] + list(text_lengths.keys()) |
| 107 | + rows = [] |
| 108 | + |
| 109 | + for i in range(row_count): |
| 110 | + row: list[object] = [i + 1, f"Row {i + 1}"] |
| 111 | + for col_name, length in text_lengths.items(): |
| 112 | + # Generate text with visible pattern showing row number and column |
| 113 | + base = f"[R{i + 1}:{col_name[:6]}]" |
| 114 | + # Fill with Lorem-style content |
| 115 | + filler = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " |
| 116 | + text = base + (filler * ((length // len(filler)) + 1)) |
| 117 | + text = text[:length] |
| 118 | + row.append(text) |
| 119 | + rows.append(tuple(row)) |
| 120 | + |
| 121 | + return columns, rows |
| 122 | + |
| 123 | + |
77 | 124 | class MockConnection: |
78 | 125 | """Mock database connection object.""" |
79 | 126 |
|
@@ -299,6 +346,18 @@ def execute_query(self, conn: Any, query: str, max_rows: int | None = None) -> t |
299 | 346 | if self._query_delay > 0: |
300 | 347 | time.sleep(self._query_delay) |
301 | 348 |
|
| 349 | + # Check if demo long text mode is enabled (for testing truncation) |
| 350 | + if os.environ.get("SQLIT_DEMO_LONG_TEXT"): |
| 351 | + demo_rows_env = os.environ.get("SQLIT_DEMO_ROWS", "10") |
| 352 | + try: |
| 353 | + demo_row_count = int(demo_rows_env) |
| 354 | + except ValueError: |
| 355 | + demo_row_count = 10 |
| 356 | + cols, rows = _generate_long_text_data(demo_row_count) |
| 357 | + if max_rows and len(rows) > max_rows: |
| 358 | + return cols, rows[:max_rows], True |
| 359 | + return cols, rows, False |
| 360 | + |
302 | 361 | # Check if demo rows mode is enabled |
303 | 362 | demo_rows_env = os.environ.get("SQLIT_DEMO_ROWS", "") |
304 | 363 | if demo_rows_env: |
|
0 commit comments