Reformat code.
This commit is contained in:
@@ -1109,6 +1109,7 @@ cmd_theme_set_by_name(const CommandContext &ctx)
|
|||||||
static bool
|
static bool
|
||||||
cmd_theme_set_by_name(CommandContext &ctx)
|
cmd_theme_set_by_name(CommandContext &ctx)
|
||||||
{
|
{
|
||||||
|
|
||||||
# if defined(KTE_BUILD_GUI) && defined(KTE_USE_QT)
|
# if defined(KTE_BUILD_GUI) && defined(KTE_USE_QT)
|
||||||
// Qt GUI build: schedule theme change for frontend
|
// Qt GUI build: schedule theme change for frontend
|
||||||
std::string name = ctx.arg;
|
std::string name = ctx.arg;
|
||||||
|
|||||||
@@ -442,11 +442,9 @@ ImGuiInputHandler::ProcessSDLEvent(const SDL_Event &e)
|
|||||||
if (ed_ && ed_
|
if (ed_ && ed_
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
->
|
->
|
||||||
UArg() != 0
|
UArg() != 0
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
const char *txt = e.text.text;
|
const char *txt = e.text.text;
|
||||||
if (txt && *txt) {
|
if (txt && *txt) {
|
||||||
unsigned char c0 = static_cast<unsigned char>(txt[0]);
|
unsigned char c0 = static_cast<unsigned char>(txt[0]);
|
||||||
|
|||||||
@@ -287,8 +287,7 @@ QtInputHandler::ProcessKeyEvent(const QKeyEvent &e)
|
|||||||
|
|
||||||
->
|
->
|
||||||
UArg() != 0
|
UArg() != 0
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
if (!(mods & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
|
if (!(mods & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
|
||||||
if (e.key() >= Qt::Key_0 && e.key() <= Qt::Key_9) {
|
if (e.key() >= Qt::Key_0 && e.key() <= Qt::Key_9) {
|
||||||
int d = e.key() - Qt::Key_0;
|
int d = e.key() - Qt::Key_0;
|
||||||
@@ -379,10 +378,9 @@ QtInputHandler::ProcessKeyEvent(const QKeyEvent &e)
|
|||||||
// ESC/meta chords: on macOS, do NOT treat Meta as ESC; only Alt (Option) should trigger.
|
// ESC/meta chords: on macOS, do NOT treat Meta as ESC; only Alt (Option) should trigger.
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
if (esc_meta_ || (mods & Qt::AltModifier)) {
|
if (esc_meta_ || (mods & Qt::AltModifier)) {
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (esc_meta_ || (mods & (Qt::AltModifier | Qt::MetaModifier))) {
|
if (esc_meta_ || (mods & (Qt::AltModifier | Qt::MetaModifier))) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
int ascii_key = 0;
|
int ascii_key = 0;
|
||||||
if (e.key() == Qt::Key_Backspace) {
|
if (e.key() == Qt::Key_Backspace) {
|
||||||
|
|||||||
25719
fonts/Go.h
25719
fonts/Go.h
File diff suppressed because it is too large
Load Diff
22047
fonts/Triplicate.h
22047
fonts/Triplicate.h
File diff suppressed because it is too large
Load Diff
1
main.cc
1
main.cc
@@ -195,7 +195,6 @@ main(int argc, char *argv[])
|
|||||||
} else if (req_term) {
|
} else if (req_term) {
|
||||||
use_gui = false;
|
use_gui = false;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Default depends on build target: kge defaults to GUI, kte to terminal
|
// Default depends on build target: kge defaults to GUI, kte to terminal
|
||||||
#if defined(KTE_DEFAULT_GUI)
|
#if defined(KTE_DEFAULT_GUI)
|
||||||
use_gui = true;
|
use_gui = true;
|
||||||
|
|||||||
26
tests/Test.h
26
tests/Test.h
@@ -8,19 +8,23 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace ktet {
|
namespace ktet {
|
||||||
|
|
||||||
struct TestCase {
|
struct TestCase {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::function<void()> fn;
|
std::function<void()> fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::vector<TestCase>& registry() {
|
|
||||||
|
inline std::vector<TestCase> &
|
||||||
|
registry()
|
||||||
|
{
|
||||||
static std::vector<TestCase> r;
|
static std::vector<TestCase> r;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Registrar {
|
struct Registrar {
|
||||||
Registrar(const char* name, std::function<void()> fn) {
|
Registrar(const char *name, std::function<void()> fn)
|
||||||
|
{
|
||||||
registry().push_back(TestCase{std::string(name), std::move(fn)});
|
registry().push_back(TestCase{std::string(name), std::move(fn)});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -30,27 +34,35 @@ struct AssertionFailure {
|
|||||||
std::string msg;
|
std::string msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void expect(bool cond, const char* expr, const char* file, int line) {
|
|
||||||
|
inline void
|
||||||
|
expect(bool cond, const char *expr, const char *file, int line)
|
||||||
|
{
|
||||||
if (!cond) {
|
if (!cond) {
|
||||||
std::cerr << file << ":" << line << ": EXPECT failed: " << expr << "\n";
|
std::cerr << file << ":" << line << ": EXPECT failed: " << expr << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void assert_true(bool cond, const char* expr, const char* file, int line) {
|
|
||||||
|
inline void
|
||||||
|
assert_true(bool cond, const char *expr, const char *file, int line)
|
||||||
|
{
|
||||||
if (!cond) {
|
if (!cond) {
|
||||||
throw AssertionFailure{std::string(file) + ":" + std::to_string(line) + ": ASSERT failed: " + expr};
|
throw AssertionFailure{std::string(file) + ":" + std::to_string(line) + ": ASSERT failed: " + expr};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename A, typename B>
|
template<typename A, typename B>
|
||||||
inline void assert_eq_impl(const A& a, const B& b, const char* ea, const char* eb, const char* file, int line) {
|
inline void
|
||||||
|
assert_eq_impl(const A &a, const B &b, const char *ea, const char *eb, const char *file, int line)
|
||||||
|
{
|
||||||
if (!(a == b)) {
|
if (!(a == b)) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << file << ":" << line << ": ASSERT_EQ failed: " << ea << " == " << eb;
|
oss << file << ":" << line << ": ASSERT_EQ failed: " << ea << " == " << eb;
|
||||||
throw AssertionFailure{oss.str()};
|
throw AssertionFailure{oss.str()};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ktet
|
} // namespace ktet
|
||||||
|
|
||||||
#define TEST(name) \
|
#define TEST(name) \
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
auto ® = ktet::registry();
|
auto ® = ktet::registry();
|
||||||
std::cout << "kte unit tests: " << reg.size() << " test(s)\n";
|
std::cout << "kte unit tests: " << reg.size() << " test(s)\n";
|
||||||
|
|||||||
@@ -4,12 +4,17 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
|
||||||
static std::string read_all(const std::string &path) {
|
|
||||||
|
static std::string
|
||||||
|
read_all(const std::string &path)
|
||||||
|
{
|
||||||
std::ifstream in(path, std::ios::binary);
|
std::ifstream in(path, std::ios::binary);
|
||||||
return std::string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
return std::string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Buffer_SaveAs_and_Save_new_file) {
|
|
||||||
|
TEST(Buffer_SaveAs_and_Save_new_file)
|
||||||
|
{
|
||||||
const std::string path = "./.kte_ut_buffer_io_1.tmp";
|
const std::string path = "./.kte_ut_buffer_io_1.tmp";
|
||||||
std::remove(path.c_str());
|
std::remove(path.c_str());
|
||||||
|
|
||||||
@@ -34,7 +39,9 @@ TEST(Buffer_SaveAs_and_Save_new_file) {
|
|||||||
std::remove(path.c_str());
|
std::remove(path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Buffer_Save_after_Open_existing) {
|
|
||||||
|
TEST(Buffer_Save_after_Open_existing)
|
||||||
|
{
|
||||||
const std::string path = "./.kte_ut_buffer_io_2.tmp";
|
const std::string path = "./.kte_ut_buffer_io_2.tmp";
|
||||||
std::remove(path.c_str());
|
std::remove(path.c_str());
|
||||||
{
|
{
|
||||||
@@ -57,7 +64,9 @@ TEST(Buffer_Save_after_Open_existing) {
|
|||||||
std::remove(path.c_str());
|
std::remove(path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Buffer_Open_nonexistent_then_SaveAs) {
|
|
||||||
|
TEST(Buffer_Open_nonexistent_then_SaveAs)
|
||||||
|
{
|
||||||
const std::string path = "./.kte_ut_buffer_io_3.tmp";
|
const std::string path = "./.kte_ut_buffer_io_3.tmp";
|
||||||
std::remove(path.c_str());
|
std::remove(path.c_str());
|
||||||
|
|
||||||
|
|||||||
@@ -3,22 +3,32 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
static std::vector<std::size_t> ref_find_all(const std::string &text, const std::string &pat) {
|
|
||||||
|
static std::vector<std::size_t>
|
||||||
|
ref_find_all(const std::string &text, const std::string &pat)
|
||||||
|
{
|
||||||
std::vector<std::size_t> res;
|
std::vector<std::size_t> res;
|
||||||
if (pat.empty()) return res;
|
if (pat.empty())
|
||||||
|
return res;
|
||||||
std::size_t from = 0;
|
std::size_t from = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
auto p = text.find(pat, from);
|
auto p = text.find(pat, from);
|
||||||
if (p == std::string::npos) break;
|
if (p == std::string::npos)
|
||||||
|
break;
|
||||||
res.push_back(p);
|
res.push_back(p);
|
||||||
from = p + pat.size();
|
from = p + pat.size();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(OptimizedSearch_basic_cases) {
|
|
||||||
|
TEST(OptimizedSearch_basic_cases)
|
||||||
|
{
|
||||||
OptimizedSearch os;
|
OptimizedSearch os;
|
||||||
struct Case { std::string text; std::string pat; } cases[] = {
|
struct Case {
|
||||||
|
std::string text;
|
||||||
|
std::string pat;
|
||||||
|
} cases[] = {
|
||||||
{"", ""},
|
{"", ""},
|
||||||
{"", "a"},
|
{"", "a"},
|
||||||
{"a", ""},
|
{"a", ""},
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#if defined(KTE_TESTS)
|
#if defined(KTE_TESTS)
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
validate_undo_subtree(const UndoNode *node, const UndoNode *expected_parent,
|
validate_undo_subtree(const UndoNode *node, const UndoNode *expected_parent,
|
||||||
std::unordered_set<const UndoNode *> &seen)
|
std::unordered_set<const UndoNode *> &seen)
|
||||||
|
|||||||
Reference in New Issue
Block a user