|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
| 3 | +import pytest |
| 4 | + |
3 | 5 | from tests.utils import TestCaseBase |
4 | 6 |
|
5 | 7 | import sqlparse |
@@ -283,3 +285,27 @@ def test_format_column_ordering(): # issue89 |
283 | 285 | ' c2,', |
284 | 286 | ' c3;']) |
285 | 287 | assert formatted == expected |
| 288 | + |
| 289 | + |
| 290 | +def test_truncate_strings(): |
| 291 | + sql = 'update foo set value = \'' + 'x' * 1000 + '\';' |
| 292 | + formatted = sqlparse.format(sql, truncate_strings=10) |
| 293 | + assert formatted == 'update foo set value = \'xxxxxxxxxx[...]\';' |
| 294 | + formatted = sqlparse.format(sql, truncate_strings=3, truncate_char='YYY') |
| 295 | + assert formatted == 'update foo set value = \'xxxYYY\';' |
| 296 | + |
| 297 | + |
| 298 | +def test_truncate_strings_invalid_option(): |
| 299 | + pytest.raises(SQLParseError, sqlparse.format, |
| 300 | + 'foo', truncate_strings='bar') |
| 301 | + pytest.raises(SQLParseError, sqlparse.format, |
| 302 | + 'foo', truncate_strings=-1) |
| 303 | + pytest.raises(SQLParseError, sqlparse.format, |
| 304 | + 'foo', truncate_strings=0) |
| 305 | + |
| 306 | + |
| 307 | +@pytest.mark.parametrize('sql', ['select verrrylongcolumn from foo', |
| 308 | + 'select "verrrylongcolumn" from "foo"']) |
| 309 | +def test_truncate_strings_doesnt_truncate_identifiers(sql): |
| 310 | + formatted = sqlparse.format(sql, truncate_strings=2) |
| 311 | + assert formatted == sql |
0 commit comments