diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-07-03 11:35:18 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-07-05 11:58:10 +0200 |
| commit | 1f3f99bf62df78981c839c95ee98adad649a5ef4 (patch) | |
| tree | 2b380e5ceb25914e4541e5e451ed03ee61ba1cf4 /tools/snippets_translate/tests | |
| parent | 0faa54831af8ef7deedd2b6885ea2b3657179d7b (diff) | |
snippets_translate: Prevent the variable initialization code from triggering for functions
The code trying to change a constructor initialization:
"Foo foo(2);" into "foo = Foo(2)"
also triggered for member function definitions returning pointers
"Foo *Foo:foo()" and many function declarations in headers.
Restrict this by checking for a semicolon and non-presence of some
function qualifiers.
Pick-to: 6.5
Task-number: PYSIDE-1106
Change-Id: I224ac3e7321e57f1c5beecdcdb568a273330a664
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'tools/snippets_translate/tests')
| -rw-r--r-- | tools/snippets_translate/tests/test_converter.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/snippets_translate/tests/test_converter.py b/tools/snippets_translate/tests/test_converter.py index a1f01eae1..084cc8a6d 100644 --- a/tools/snippets_translate/tests/test_converter.py +++ b/tools/snippets_translate/tests/test_converter.py @@ -166,14 +166,14 @@ def test_cout_endl(): def test_variable_declaration(): assert st("QLabel label;") == "label = QLabel()" - assert st('QLabel label("Hello")') == 'label = QLabel("Hello")' + assert st('QLabel label("Hello");') == 'label = QLabel("Hello")' assert st("Widget w;") == "w = Widget()" assert st('QLabel *label = new QLabel("Hello");') == 'label = QLabel("Hello")' assert st('QLabel label = a_function("Hello");') == 'label = a_function("Hello")' assert st('QString a = "something";') == 'a = "something"' assert st("int var;") == "var = int()" assert st("float v = 0.1;") == "v = 0.1" - assert st("QSome<thing> var") == "var = QSome()" + assert st("QSome<thing> var;") == "var = QSome()" assert st("QQueue<int> queue;") == "queue = QQueue()" assert st("QVBoxLayout *layout = new QVBoxLayout;") == "layout = QVBoxLayout()" assert st("QPointer<QLabel> label = new QLabel;") == "label = QLabel()" @@ -181,6 +181,10 @@ def test_variable_declaration(): assert st("QList<QImage> collage =") == "collage =" assert st("bool b = true;") == "b = True" assert st("Q3DBars *m_graph = nullptr;") == "m_graph = None" + # Do not fall for member function definitions + assert st("Q3DBars *Graph::bars() const") == "Q3DBars Graph.bars()" + # Do not fall for member function declarations + assert st("virtual Q3DBars *bars();") == "virtual Q3DBars bars()" def test_for(): |
