diff --git a/test/testcandidatelist.cpp b/test/testcandidatelist.cpp index 2ef4cc8c..28a38bc9 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 179795b7..bfd27111 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() {