summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2013-07-09 10:10:33 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2013-07-09 10:10:33 +0200
commit204b77954eacc85615eace5ac895fab5ebb16e04 (patch)
tree111f910d540f97253c77caf05d5b703b8d3cf86d /tests
parent223e41045f2b4396007249c59b912aaea149e873 (diff)
downloadsqlparse-204b77954eacc85615eace5ac895fab5ebb16e04.tar.gz
Add option to truncate long string literals.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_format.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_format.py b/tests/test_format.py
index 6daf5a3..701540b 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
+import pytest
+
from tests.utils import TestCaseBase
import sqlparse
@@ -283,3 +285,27 @@ def test_format_column_ordering(): # issue89
' c2,',
' c3;'])
assert formatted == expected
+
+
+def test_truncate_strings():
+ sql = 'update foo set value = \'' + 'x' * 1000 + '\';'
+ formatted = sqlparse.format(sql, truncate_strings=10)
+ assert formatted == 'update foo set value = \'xxxxxxxxxx[...]\';'
+ formatted = sqlparse.format(sql, truncate_strings=3, truncate_char='YYY')
+ assert formatted == 'update foo set value = \'xxxYYY\';'
+
+
+def test_truncate_strings_invalid_option():
+ pytest.raises(SQLParseError, sqlparse.format,
+ 'foo', truncate_strings='bar')
+ pytest.raises(SQLParseError, sqlparse.format,
+ 'foo', truncate_strings=-1)
+ pytest.raises(SQLParseError, sqlparse.format,
+ 'foo', truncate_strings=0)
+
+
+@pytest.mark.parametrize('sql', ['select verrrylongcolumn from foo',
+ 'select "verrrylongcolumn" from "foo"'])
+def test_truncate_strings_doesnt_truncate_identifiers(sql):
+ formatted = sqlparse.format(sql, truncate_strings=2)
+ assert formatted == sql