Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Apr 2, 2024
1 parent fa526e8 commit ef5ef04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 12 additions & 2 deletions test/testcandidatelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions test/testtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
#include <fcitx-utils/log.h>
#include <fcitx/text.h>
#include "fcitx-utils/textformatflags.h"
using namespace fcitx;

void test_basic() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ef5ef04

Please sign in to comment.