aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-08-15 14:41:24 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-15 20:34:36 +0000
commitbecb2b6b64933c6082da6d81fd131be1c3b01aa9 (patch)
treee890bfa37df1233bb7456b5b38c5246c7ad04980
parent921de12c092ca7110ccd665dee1865dfa8902a56 (diff)
snippets_translate: Fix indented conditions
Adapt the regexes accordingly. Fixes: PYSIDE-2030 Change-Id: I6515b2ca0fe23c753feadeb491173b72889abba5 Reviewed-by: Adrian Herrmann <adrian.herrmann@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 9f727745797a433de70f491ef7997016bb57ee04) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tools/snippets_translate/handlers.py6
-rw-r--r--tools/snippets_translate/tests/test_converter.py1
2 files changed, 4 insertions, 3 deletions
diff --git a/tools/snippets_translate/handlers.py b/tools/snippets_translate/handlers.py
index 8f58d218f..6ededfc06 100644
--- a/tools/snippets_translate/handlers.py
+++ b/tools/snippets_translate/handlers.py
@@ -43,9 +43,9 @@ import sys
from parse_utils import (dstrip, get_indent, get_qt_module_class,
parse_arguments, remove_ref, replace_main_commas)
-IF_PATTERN = re.compile(r'^if\s*\(')
-ELSE_IF_PATTERN = re.compile(r'^}?\s*else if\s*\(')
-WHILE_PATTERN = re.compile(r'^while\s*\(')
+IF_PATTERN = re.compile(r'^\s*if\s*\(')
+ELSE_IF_PATTERN = re.compile(r'^\s*}?\s*else if\s*\(')
+WHILE_PATTERN = re.compile(r'^\s*while\s*\(')
def handle_condition(x, name):
diff --git a/tools/snippets_translate/tests/test_converter.py b/tools/snippets_translate/tests/test_converter.py
index a41f3190e..84e266f41 100644
--- a/tools/snippets_translate/tests/test_converter.py
+++ b/tools/snippets_translate/tests/test_converter.py
@@ -78,6 +78,7 @@ def test_and_or():
def test_while_if_elseif():
assert st("while(a)") == "while a:"
assert st("if (condition){") == "if condition:"
+ assert st(" if (condition){") == " if condition:"
assert st("} else if (a) {") == " elif a:"
assert (
st("if (!m_vbo.isCreated()) // init() failed,")