forked from qt-creator/qt-creator
UnitTests: Clean up line prefixer test
In TDD development is a standard advised that you setup you values in the block, run what you want to test in the second and assert in third. We should try to stick it because it makes reading the test easier. It is advised too put the setup code after the test if possible. I used const QList<QByteArray> inputChunks = {"hello\n"} instead of const QList<QByteArray> inputChunks {"hello\n"} because it is always using the initializer_list constructor. Change-Id: I1573566efc1327a2d8681e9ae7bd0ad6ee182789 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -32,84 +32,106 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
QByteArray runPrefixer(QList<QByteArray> inputChunks)
|
QByteArray runPrefixer(QList<QByteArray> inputChunks);
|
||||||
{
|
|
||||||
QByteArray actualOutput;
|
|
||||||
ClangBackEnd::LinePrefixer prefixer("PREFIX ");
|
|
||||||
foreach (const QByteArray &chunk, inputChunks)
|
|
||||||
actualOutput += prefixer.prefix(chunk);
|
|
||||||
return actualOutput;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(LinePrefixer, OneChunkEndsWithNewline)
|
TEST(LinePrefixer, OneChunkEndsWithNewline)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "hello\n" };
|
const QList<QByteArray> inputChunks = {"hello\n"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX hello\n"));
|
auto text = runPrefixer(inputChunks);
|
||||||
|
|
||||||
|
ASSERT_THAT(text, "PREFIX hello\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LinePrefixer, OneChunkEndsWithoutNewline)
|
TEST(LinePrefixer, OneChunkEndsWithoutNewline)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "hello" };
|
const QList<QByteArray> inputChunks = {"hello"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX hello"));
|
auto text = runPrefixer(inputChunks);
|
||||||
|
|
||||||
|
ASSERT_THAT(text, "PREFIX hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LinePrefixer, OneChunkStartsWithNewline)
|
TEST(LinePrefixer, OneChunkStartsWithNewline)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "\nhello" };
|
const QList<QByteArray> inputChunks = {"\nhello"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX \n"
|
auto text = runPrefixer(inputChunks);
|
||||||
"PREFIX hello"));
|
|
||||||
|
ASSERT_THAT(text, "PREFIX \n"
|
||||||
|
"PREFIX hello");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LinePrefixer, OneChunkStartsAndEndsWithNewline)
|
TEST(LinePrefixer, OneChunkStartsAndEndsWithNewline)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "\nhello\n" };
|
const QList<QByteArray> inputChunks = {"\nhello\n"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX \n"
|
auto text = runPrefixer(inputChunks);
|
||||||
"PREFIX hello\n"));
|
|
||||||
|
ASSERT_THAT(text, "PREFIX \n"
|
||||||
|
"PREFIX hello\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LinePrefixer, OneChunkEndsWithExtraNewline)
|
TEST(LinePrefixer, OneChunkEndsWithExtraNewline)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "hello\n\n" };
|
const QList<QByteArray> inputChunks = {"hello\n\n"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX hello\n"
|
auto text = runPrefixer(inputChunks);
|
||||||
"PREFIX \n"));
|
|
||||||
|
ASSERT_THAT(text, "PREFIX hello\n"
|
||||||
|
"PREFIX \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LinePrefixer, OneChunkEndsWithTwoExtraNewlines)
|
TEST(LinePrefixer, OneChunkEndsWithTwoExtraNewlines)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "hello\n\n\n" };
|
const QList<QByteArray> inputChunks = {"hello\n\n\n"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX hello\n"
|
auto text = runPrefixer(inputChunks);
|
||||||
"PREFIX \n"
|
|
||||||
"PREFIX \n"));
|
ASSERT_THAT(text, "PREFIX hello\n"
|
||||||
|
"PREFIX \n"
|
||||||
|
"PREFIX \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LinePrefixer, ChunkWithoutNewlineAndChunkWithNewline)
|
TEST(LinePrefixer, ChunkWithoutNewlineAndChunkWithNewline)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "hello", "\n" };
|
const QList<QByteArray> inputChunks = {"hello", "\n"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX hello\n"));
|
auto text = runPrefixer(inputChunks);
|
||||||
|
|
||||||
|
ASSERT_THAT(text, "PREFIX hello\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LinePrefixer, ChunkWithoutNewlineAndChunkWithTwoNewlines)
|
TEST(LinePrefixer, ChunkWithoutNewlineAndChunkWithTwoNewlines)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "hello", "\n\n" };
|
const QList<QByteArray> inputChunks = {"hello", "\n\n"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX hello\n"
|
auto text = runPrefixer(inputChunks);
|
||||||
"PREFIX \n"));
|
|
||||||
|
ASSERT_THAT(text, "PREFIX hello\n"
|
||||||
|
"PREFIX \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LinePrefixer, ChunkWithTwoNewlinesAndChunkWithoutNewline)
|
TEST(LinePrefixer, ChunkWithTwoNewlinesAndChunkWithoutNewline)
|
||||||
{
|
{
|
||||||
const QList<QByteArray> inputChunks { "\n\n", "hello" };
|
const QList<QByteArray> inputChunks = {"\n\n", "hello"};
|
||||||
ASSERT_THAT(Utf8String::fromByteArray(runPrefixer(inputChunks)),
|
|
||||||
Utf8String::fromUtf8("PREFIX \n"
|
auto text = runPrefixer(inputChunks);
|
||||||
"PREFIX \n"
|
|
||||||
"PREFIX hello"));
|
ASSERT_THAT(text, "PREFIX \n"
|
||||||
|
"PREFIX \n"
|
||||||
|
"PREFIX hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray runPrefixer(QList<QByteArray> inputChunks)
|
||||||
|
{
|
||||||
|
QByteArray actualOutput;
|
||||||
|
ClangBackEnd::LinePrefixer prefixer("PREFIX ");
|
||||||
|
|
||||||
|
for (const auto &chunk : inputChunks)
|
||||||
|
actualOutput += prefixer.prefix(chunk);
|
||||||
|
|
||||||
|
return actualOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
Reference in New Issue
Block a user