From ef5ef04cc80dba051b010529456fd7942ec6c20b Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Mon, 1 Apr 2024 23:04:20 -0400 Subject: [PATCH] add test --- test/testcandidatelist.cpp | 14 ++++++++++++-- test/testtext.cpp | 9 +++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/test/testcandidatelist.cpp b/test/testcandidatelist.cpp index 2ef4cc8cf..28a38bc9f 100644 --- a/test/testcandidatelist.cpp +++ b/test/testcandidatelist.cpp @@ -14,8 +14,10 @@ int selected = 0; class TestCandidateWord : public CandidateWord { public: - TestCandidateWord(int number) - : CandidateWord(Text(std::to_string(number))), number_(number) {} + TestCandidateWord(int number, Text comment = {}) + : CandidateWord(Text(std::to_string(number))), number_(number) { + setComment(std::move(comment)); + } void select(InputContext *) const override { selected = number_; } private: @@ -303,9 +305,17 @@ void test_label() { FCITX_ASSERT(candidatelist.label(9).toString() == ",. "); } +void test_comment() { + TestCandidateWord candidate(1, Text("comment")); + FCITX_ASSERT(candidate.text().toString() == "1"); + FCITX_ASSERT(candidate.comment().toString() == "comment"); + FCITX_ASSERT(candidate.textWithComment().toString() == "1 comment"); +} + int main() { test_basic(); test_faulty_placeholder(); test_label(); + test_comment(); return 0; } diff --git a/test/testtext.cpp b/test/testtext.cpp index 179795b71..bfd271110 100644 --- a/test/testtext.cpp +++ b/test/testtext.cpp @@ -6,6 +6,7 @@ */ #include #include +#include "fcitx-utils/textformatflags.h" using namespace fcitx; void test_basic() { @@ -33,6 +34,14 @@ void test_basic() { FCITX_ASSERT(lines[2].toStringForCommit() == ""); FCITX_ASSERT(lines[3].toStringForCommit() == "Z"); FCITX_ASSERT(lines[4].toStringForCommit() == "1"); + + text = Text("ABC"); + Text another = Text("DEF", TextFormatFlag::Bold); + another.append("GHI", TextFormatFlag::Italic); + text.append(another); + FCITX_ASSERT(text.toString() == "ABCDEFGHI"); + FCITX_ASSERT(text.formatAt(1) == TextFormatFlag::Bold); + FCITX_ASSERT(text.formatAt(2) == TextFormatFlag::Italic); } void test_normalize() {