diff options
| author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-08 09:58:54 -0700 |
|---|---|---|
| committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-11 09:34:31 -0700 |
| commit | 99897920d77148981e91ec1b2ba25370567ef6d7 (patch) | |
| tree | 7c2e25f1392c97b4512b4dffc1b058f72a1a5b64 | |
| parent | 751933d3abdce2234bd869ee65a1ebc7ccbf6b53 (diff) | |
| download | sqlparse-99897920d77148981e91ec1b2ba25370567ef6d7.tar.gz | |
Fix grouping of `case` within parenthesis.
Closes #164
| -rw-r--r-- | sqlparse/engine/grouping.py | 2 | ||||
| -rw-r--r-- | tests/test_regressions.py | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index e8e9dc3..91bb3d9 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -42,6 +42,8 @@ def _group_left_right(tlist, m, cls, def _group_matching(tlist, cls): """Groups Tokens that have beginning and end.""" + [_group_matching(sgroup, cls) for sgroup in tlist.get_sublists() + if not isinstance(sgroup, cls)] idx = 1 if isinstance(tlist, cls) else 0 token = tlist.token_next_by(m=cls.M_OPEN, idx=idx) diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 9f3c9a9..4eb1621 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -311,3 +311,10 @@ def test_issue207_runaway_format(): " 2 as two,", " 3", " from dual) t0"]) + + +def test_case_within_parenthesis(): + # see issue #164 + s = '(case when 1=1 then 2 else 5 end)' + p = sqlparse.parse(s)[0] + assert isinstance(p[0][1], sql.Case) |
