home/src/unit_tests.cc

54 lines
1.3 KiB
C++
Raw Normal View History

#include "unit_tests.hh"
2012-03-21 20:27:36 +01:00
#include "assert.hh"
#include "diff.hh"
#include "utf8.hh"
#include "string.hh"
2012-03-21 20:27:36 +01:00
namespace Kakoune
2012-03-21 20:27:36 +01:00
{
UnitTest test_utf8{[]()
2012-10-22 01:05:56 +02:00
{
StringView str = "maïs mélange bientôt";
kak_assert(utf8::distance(std::begin(str), std::end(str)) == 20);
kak_assert(utf8::codepoint(std::begin(str) + 2, std::end(str)) == 0x00EF);
}};
2013-01-30 19:16:36 +01:00
UnitTest test_diff{[]()
{
2015-05-14 14:57:03 +02:00
auto eq = [](const Diff& lhs, const Diff& rhs) {
return lhs.mode == rhs.mode and lhs.len == rhs.len and lhs.posB == rhs.posB;
};
{
StringView s1 = "mais que fais la police";
StringView s2 = "mais ou va la police";
auto diff = find_diff(s1.begin(), (int)s1.length(), s2.begin(), (int)s2.length());
kak_assert(diff.size() == 11);
2015-05-14 14:57:03 +02:00
}
2015-05-14 14:57:03 +02:00
{
StringView s1 = "a?";
StringView s2 = "!";
auto diff = find_diff(s1.begin(), (int)s1.length(), s2.begin(), (int)s2.length());
kak_assert(diff.size() == 3 and
eq(diff[0], {Diff::Remove, 1, 0}) and
eq(diff[1], {Diff::Add, 1, 0}) and
eq(diff[2], {Diff::Remove, 1, 0}));
}
}};
2015-05-24 23:34:05 +02:00
UnitTest* UnitTest::list = nullptr;
2015-05-24 23:34:05 +02:00
void UnitTest::run_all_tests()
2012-03-21 20:27:36 +01:00
{
2015-05-24 23:34:05 +02:00
for (const UnitTest* test = UnitTest::list; test; test = test->next)
test->func();
}
2012-03-21 20:27:36 +01:00
}