Commit 06592b28 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

C++: Consolidate with/without comments preprocessor tests



Change-Id: Ib08569d642da51f6d51bb0763fc95d5a5c13d28c
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 0a817c4e
......@@ -346,8 +346,6 @@ private slots:
void comments_before_args();
void comments_within();
void comments_within_data();
void comments_within2();
void comments_within2_data();
void multitokens_argument();
void multitokens_argument_data();
void multiline_strings();
......@@ -1107,12 +1105,25 @@ void tst_Preprocessor::dont_eagerly_expand()
void tst_Preprocessor::comments_within()
{
compare_input_output();
QFETCH(QByteArray, input);
QFETCH(QByteArray, without_comments);
QFETCH(QByteArray, with_comments);
Environment env;
Preprocessor preprocess(0, &env);
preprocess.setKeepComments(false);
QByteArray prep = preprocess.run(QLatin1String("<stdin>"), input);
QCOMPARE(prep.constData(), without_comments.constData());
preprocess.setKeepComments(true);
prep = preprocess.run(QLatin1String("<stdin>"), input);
QCOMPARE(prep.constData(), with_comments.constData());
}
void tst_Preprocessor::comments_within_data()
{
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QByteArray>("output");
QTest::addColumn<QByteArray>("without_comments");
QTest::addColumn<QByteArray>("with_comments");
QTest::newRow("case 1") << _(
"#define FOO int x;\n"
......@@ -1136,59 +1147,22 @@ void tst_Preprocessor::comments_within_data()
"# expansion end\n"
"# 8 \"<stdin>\"\n"
"x = 10\n"
);
QTest::newRow("case 2") << _(
"#define FOO int x;\n"
"\n"
" /* comment\n"
" comment\n"
" comment\n"
" comment */\n"
"FOO\n"
"x = 10\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"# expansion begin 79,3 ~3\n"
"int x;\n"
"# expansion end\n"
"# 8 \"<stdin>\"\n"
"x = 10\n"
);
QTest::newRow("case 3") << _(
"#define FOO int x;\n"
"\n"
" // comment\n"
" // comment\n"
" // comment\n"
" // comment\n"
"FOO\n"
"// test\n"
"// test again\n"
"x = 10\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"# expansion begin 76,3 ~3\n"
"int x;\n"
"# expansion end\n"
"# 10 \"<stdin>\"\n"
"# 8 \"<stdin>\"\n"
"x = 10\n"
);
QTest::newRow("case 4") << _(
QTest::newRow("case 2") << _(
"#define FOO int x;\n"
"\n"
" /* comment\n"
......@@ -1196,8 +1170,6 @@ void tst_Preprocessor::comments_within_data()
" comment\n"
" comment */\n"
"FOO\n"
"/* \n"
"*/\n"
"x = 10\n"
) << _(
"# 1 \"<stdin>\"\n"
......@@ -1210,134 +1182,8 @@ void tst_Preprocessor::comments_within_data()
"# expansion begin 79,3 ~3\n"
"int x;\n"
"# expansion end\n"
"# 10 \"<stdin>\"\n"
"x = 10\n"
);
QTest::newRow("case 5") << _(
"#define FOO(x, y) { (void)x; (void)y; }\n"
"\n"
"void foo() {\n"
" FOO(10,\n"
" //comment\n"
" 12\n"
"}\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() {\n"
"# expansion begin 57,3 ~4 4:7 ~4 6:7 7:0 ~2\n"
"{ (void)10; (void)12}; }\n"
"# expansion end\n"
"# 8 \"<stdin>\"\n"
);
QTest::newRow("case 6") << _(
"#define FOO(x, y) { (void)x; (void)y; }\n"
"\n"
"void foo() {\n"
" FOO(10,\n"
" //tricky*/comment\n"
" 12\n"
"}\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() {\n"
"# expansion begin 57,3 ~4 4:7 ~4 6:7 7:0 ~2\n"
"{ (void)10; (void)12}; }\n"
"# expansion end\n"
"# 8 \"<stdin>\"\n"
);
QTest::newRow("case 7") << _(
"#define FOO 0 //comment\n"
"#define BAR (1 == FOO)\n"
"void foo() {\n"
" if (BAR) {}\n"
"}\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() {\n"
" if (\n"
"# expansion begin 68,3 ~5\n"
"(1 == 0)\n"
"# expansion end\n"
"# 4 \"<stdin>\"\n"
" ) {}\n"
"}\n"
);
}
void tst_Preprocessor::comments_before_args()
{
Client *client = 0; // no client.
Environment env;
Preprocessor preprocess(client, &env);
preprocess.setKeepComments(true);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"\n#define foo(a,b) int a = b;"
"\nfoo/*C comment*/(a,1)\n"
"\nfoo/**Doxygen comment*/(b,2)\n"
"\nfoo//C++ comment\n(c,3)\n"
"\nfoo///Doxygen C++ comment\n(d,4)\n"
"\nfoo/*multiple*///comments\n/**as well*/(e,5)\n",
true, false);
preprocessed = preprocessed.simplified();
// DUMP_OUTPUT(preprocessed);
QCOMPARE(simplified(preprocessed),
QString("int a=1;int b=2;int c=3;int d=4;int e=5;"));
}
void tst_Preprocessor::comments_within2()
{
compare_input_output(true);
}
void tst_Preprocessor::comments_within2_data()
{
QTest::addColumn<QByteArray>("input");
QTest::addColumn<QByteArray>("output");
QTest::newRow("case 1") << _(
"#define FOO int x;\n"
"\n"
" // comment\n"
" // comment\n"
" // comment\n"
" // comment\n"
"FOO\n"
"x = 10\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
" // comment\n"
" // comment\n"
" // comment\n"
" // comment\n"
"# expansion begin 76,3 ~3\n"
"int x;\n"
"# expansion end\n"
"# 8 \"<stdin>\"\n"
"x = 10\n"
);
QTest::newRow("case 2") << _(
"#define FOO int x;\n"
"\n"
" /* comment\n"
" comment\n"
" comment\n"
" comment */\n"
"FOO\n"
"x = 10\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
......@@ -1364,6 +1210,19 @@ void tst_Preprocessor::comments_within2_data()
"// test\n"
"// test again\n"
"x = 10\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"# expansion begin 76,3 ~3\n"
"int x;\n"
"# expansion end\n"
"# 10 \"<stdin>\"\n"
"x = 10\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
......@@ -1384,7 +1243,7 @@ void tst_Preprocessor::comments_within2_data()
QTest::newRow("case 4") << _(
"#define FOO int x;\n"
"\n"
"void foo() { /* comment\n"
" /* comment\n"
" comment\n"
" comment\n"
" comment */\n"
......@@ -1396,11 +1255,24 @@ void tst_Preprocessor::comments_within2_data()
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() { /* comment\n"
"\n"
"\n"
"\n"
"\n"
"# expansion begin 79,3 ~3\n"
"int x;\n"
"# expansion end\n"
"# 10 \"<stdin>\"\n"
"x = 10\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
" /* comment\n"
" comment\n"
" comment\n"
" comment */\n"
"# expansion begin 91,3 ~3\n"
"# expansion begin 79,3 ~3\n"
"int x;\n"
"# expansion end\n"
"# 8 \"<stdin>\"\n"
......@@ -1417,6 +1289,15 @@ void tst_Preprocessor::comments_within2_data()
" //comment\n"
" 12\n"
"}\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() {\n"
"# expansion begin 57,3 ~4 4:7 ~4 6:7 7:0 ~2\n"
"{ (void)10; (void)12}; }\n"
"# expansion end\n"
"# 8 \"<stdin>\"\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
......@@ -1436,6 +1317,15 @@ void tst_Preprocessor::comments_within2_data()
" //tricky*/comment\n"
" 12\n"
"}\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() {\n"
"# expansion begin 57,3 ~4 4:7 ~4 6:7 7:0 ~2\n"
"{ (void)10; (void)12}; }\n"
"# expansion end\n"
"# 8 \"<stdin>\"\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
......@@ -1465,9 +1355,43 @@ void tst_Preprocessor::comments_within2_data()
"# 4 \"<stdin>\"\n"
" ) {}\n"
"}\n"
) << _(
"# 1 \"<stdin>\"\n"
"\n"
"\n"
"void foo() {\n"
" if (\n"
"# expansion begin 68,3 ~5\n"
"(1 == 0)\n"
"# expansion end\n"
"# 4 \"<stdin>\"\n"
" ) {}\n"
"}\n"
);
}
void tst_Preprocessor::comments_before_args()
{
Client *client = 0; // no client.
Environment env;
Preprocessor preprocess(client, &env);
preprocess.setKeepComments(true);
QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"),
"\n#define foo(a,b) int a = b;"
"\nfoo/*C comment*/(a,1)\n"
"\nfoo/**Doxygen comment*/(b,2)\n"
"\nfoo//C++ comment\n(c,3)\n"
"\nfoo///Doxygen C++ comment\n(d,4)\n"
"\nfoo/*multiple*///comments\n/**as well*/(e,5)\n",
true, false);
preprocessed = preprocessed.simplified();
// DUMP_OUTPUT(preprocessed);
QCOMPARE(simplified(preprocessed),
QString("int a=1;int b=2;int c=3;int d=4;int e=5;"));
}
void tst_Preprocessor::multiline_strings()
{
compare_input_output();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment