| 194 | } |
| 195 | |
| 196 | void TestAstyle::testContext() |
| 197 | { |
| 198 | auto* formatter = new AStyleFormatter; |
| 199 | formatter->setBracketFormatMode(astyle::LINUX_MODE); |
| 200 | formatter->setParensInsidePaddingMode(true); |
| 201 | formatter->setBlockIndent(true); |
| 202 | // We enable break-blocks mode, so that we can test the newline matching |
| 203 | formatter->setBreakBlocksMode(true); |
| 204 | formatter->setBreakClosingHeaderBlocksMode(true); |
| 205 | formatter->setParensUnPaddingMode(true); |
| 206 | |
| 207 | QString leftContext = QStringLiteral("int main() {\n"); |
| 208 | QString rightContext = QStringLiteral(";\n}\n"); |
| 209 | |
| 210 | /// Newline tests |
| 211 | |
| 212 | QString formattedSource = formatter->formatSource( |
| 213 | QStringLiteral(" int a;\n"), leftContext, "int b;" + rightContext ); |
| 214 | |
| 215 | // qDebug() << formattedSource; |
| 216 | // Adjust indentation |
| 217 | QCOMPARE(formattedSource, QString(" int a;\n ")); |
| 218 | |
| 219 | formattedSource = formatter->formatSource( |
| 220 | QStringLiteral(" int a;\n"), leftContext + " ", " int b;" + rightContext ); |
| 221 | |
| 222 | // qDebug() << formattedSource; |
| 223 | QCOMPARE(formattedSource, QString(" int a;\n ")); |
| 224 | |
| 225 | /// "if(a);" is interpreted as own block, so due to the "break blocks" option, |
| 226 | /// astyle breaks these blocks with a newline in between. |
| 227 | formattedSource = formatter->formatSource( |
| 228 | QStringLiteral(" if(a); "), leftContext + " if(a); ", " if(a);" + rightContext ); |
| 229 | |
| 230 | // qDebug() << formattedSource; |
| 231 | QCOMPARE(formattedSource, QString("\n\n if( a );\n\n ")); |
| 232 | |
| 233 | formattedSource = formatter->formatSource( |
| 234 | QStringLiteral(" if(a); "), leftContext + " if(a);\n", " \n if(a);" + rightContext ); |
| 235 | |
| 236 | // qDebug() << formattedSource; |
| 237 | QCOMPARE(formattedSource, QString("\n if( a );\n")); |
| 238 | |
| 239 | formattedSource = formatter->formatSource( |
| 240 | QStringLiteral(" if(a)\na; "), leftContext + " if(a);\n", " \n\n if(a);" + rightContext ); |
| 241 | |
| 242 | // qDebug() << formattedSource; |
| 243 | // Adjust indentation, successor already partially indentend |
| 244 | QCOMPARE(formattedSource, QString("\n if( a )\n a;")); |
| 245 | |
| 246 | /// Whitespace tests |
| 247 | |
| 248 | formattedSource = formatter->formatSource( |
| 249 | QStringLiteral("int "), leftContext + " ", rightContext ); |
| 250 | |
| 251 | // 2 whitespaces are already in the context, so add only 2 |
| 252 | // qDebug() << "formatted source:" << formattedSource; |
| 253 | QCOMPARE(formattedSource, QString(" int ")); |
nothing calls this directly
no test coverage detected