Integrates googletest
parent
8e18d610f5
commit
268719ed1f
@ -0,0 +1 @@
|
||||
Subproject commit 15460959cbbfa20e66ef0b5ab497367e47fc0a04
|
@ -1,47 +1,26 @@
|
||||
#include "Internal.h"
|
||||
#include "MiscUtils.h"
|
||||
|
||||
#include "MiscUtils.h"
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
int compare_result(const vector<string> &expect, const vector<string> &result)
|
||||
{
|
||||
if (result == expect)
|
||||
{
|
||||
cout << "ok\n";
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
cout << "not ok\n";
|
||||
auto e = expect.begin();
|
||||
auto r = result.begin();
|
||||
cout << "# " << setw(20) << left << "Expected" << " " << left << "Got\n";
|
||||
while (e < expect.end() || r < result.end())
|
||||
{
|
||||
cout
|
||||
<< "# "
|
||||
<< setw(20) << left << ":" + (e < expect.end() ? *e++ : "") + ":"
|
||||
<< " "
|
||||
<< setw(20) << left << ":" + (r < result.end() ? *r++ : "") + ":"
|
||||
<< "\n";
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
TEST(MiscUtils, wordwrap) {
|
||||
std::vector<std::string> result;
|
||||
|
||||
int main()
|
||||
{
|
||||
int fails = 0;
|
||||
#define TEST_WORDWRAP(label, expect, args) \
|
||||
{ \
|
||||
vector<string> result; \
|
||||
cout << label << "... "; \
|
||||
word_wrap args; \
|
||||
fails += compare_result(expect, result); \
|
||||
}
|
||||
std::cout << "MiscUtils.wordwrap: 0 wrap" << "... ";
|
||||
word_wrap(&result, "123", 3);
|
||||
ASSERT_EQ(result.size(), 1);
|
||||
std::cout << "ok\n";
|
||||
|
||||
TEST_WORDWRAP("Short line, no wrap", vector<string>({"12345"}), (&result, "12345", 15));
|
||||
result.clear();
|
||||
std::cout << "MiscUtils.wordwrap: 1 wrap" << "... ";
|
||||
word_wrap(&result, "12345", 3);
|
||||
ASSERT_EQ(result.size(), 2);
|
||||
std::cout << "ok\n";
|
||||
|
||||
return fails == 0 ? 0 : 1;
|
||||
result.clear();
|
||||
std::cout << "MiscUtils.wordwrap: 2 wrap" << "... ";
|
||||
word_wrap(&result, "1234567", 3);
|
||||
ASSERT_EQ(result.size(), 3);
|
||||
std::cout << "ok\n";
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Reference in New Issue