| 36 | } |
| 37 | |
| 38 | void TestFormattingHelpers::testFuzzyMatching_data() |
| 39 | { |
| 40 | QTest::addColumn<QString>("formattedMergedText"); |
| 41 | QTest::addColumn<QString>("selectedText"); |
| 42 | QTest::addColumn<QString>("leftContext"); |
| 43 | QTest::addColumn<QString>("rightContext"); |
| 44 | QTest::addColumn<QString>("expectedOutput"); |
| 45 | |
| 46 | QString selectedText = QStringLiteral("void bar() {\nint x;\n}"); |
| 47 | QString expectedOutput = QStringLiteral("void bar() {\n int x;\n}"); |
| 48 | |
| 49 | QTest::newRow("left-indentation-fixed") |
| 50 | << QStringLiteral("void foo() {\n int i;\n int j;\n}\n\nvoid bar() {\n int x;\n}") |
| 51 | << selectedText |
| 52 | << QStringLiteral("void foo() {\nint i;\n\n\nint j;\n}\n\n") |
| 53 | << QStringLiteral("") |
| 54 | << expectedOutput; |
| 55 | |
| 56 | QTest::newRow("right-indentation-fixed") |
| 57 | << QStringLiteral("void bar() {\n int x;\n}\n\nvoid foo() {\n int i;\n int j;\n}") |
| 58 | << selectedText |
| 59 | << QStringLiteral("") |
| 60 | << QStringLiteral("\n\nvoid foo() {\nint i;\n\n\nint j;\n}") |
| 61 | << expectedOutput; |
| 62 | |
| 63 | // clang-format can break long comments into multiple lines, adding new "//". |
| 64 | // For the sake of readability, the comments in the test are actually not very long. |
| 65 | QTest::newRow("left-comment-break-fixed") |
| 66 | << QStringLiteral("void foo() {\n // very\n // long\n}\n\nvoid bar() {\n int x;\n}") |
| 67 | << selectedText |
| 68 | << QStringLiteral("void foo() {\n// very long\n}\n\n") |
| 69 | << QStringLiteral("") |
| 70 | << expectedOutput; |
| 71 | |
| 72 | QTest::newRow("right-comment-break-fixed") |
| 73 | << QStringLiteral("void bar() {\n int x;\n}\n\nvoid foo() {\n // very\n // long\n}") |
| 74 | << selectedText |
| 75 | << QStringLiteral("") |
| 76 | << QStringLiteral("\n\nvoid foo() {\n// very long\n}") |
| 77 | << expectedOutput; |
| 78 | |
| 79 | QTest::newRow("left-multilinecomment-break-fixed") |
| 80 | << QStringLiteral("void foo() {\n /* very\n * long */\n}\n\nvoid bar() {\n int x;\n}") |
| 81 | << selectedText |
| 82 | << QStringLiteral("void foo() {\n/* very long */\n}\n\n") |
| 83 | << QStringLiteral("") |
| 84 | << expectedOutput; |
| 85 | |
| 86 | QTest::newRow("right-multilinecomment-break-fixed") |
| 87 | << QStringLiteral("void bar() {\n int x;\n}\n\nvoid foo() {\n /* very\n * long */\n}") |
| 88 | << selectedText |
| 89 | << QStringLiteral("") |
| 90 | << QStringLiteral("\n\nvoid foo() {\n/* very long */\n}") |
| 91 | << expectedOutput; |
| 92 | |
| 93 | // clang-format can break long macros and add (or remove) "\" |
| 94 | QTest::newRow("left-macro-break-removed") |
| 95 | << QStringLiteral("#define foo(a,b) a = b\n\nvoid bar() {\n int x;\n}") |