Skip to content

Commit ef5ef04

Browse files
committed
add test
1 parent fa526e8 commit ef5ef04

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

test/testcandidatelist.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ int selected = 0;
1414

1515
class TestCandidateWord : public CandidateWord {
1616
public:
17-
TestCandidateWord(int number)
18-
: CandidateWord(Text(std::to_string(number))), number_(number) {}
17+
TestCandidateWord(int number, Text comment = {})
18+
: CandidateWord(Text(std::to_string(number))), number_(number) {
19+
setComment(std::move(comment));
20+
}
1921
void select(InputContext *) const override { selected = number_; }
2022

2123
private:
@@ -303,9 +305,17 @@ void test_label() {
303305
FCITX_ASSERT(candidatelist.label(9).toString() == ",. ");
304306
}
305307

308+
void test_comment() {
309+
TestCandidateWord candidate(1, Text("comment"));
310+
FCITX_ASSERT(candidate.text().toString() == "1");
311+
FCITX_ASSERT(candidate.comment().toString() == "comment");
312+
FCITX_ASSERT(candidate.textWithComment().toString() == "1 comment");
313+
}
314+
306315
int main() {
307316
test_basic();
308317
test_faulty_placeholder();
309318
test_label();
319+
test_comment();
310320
return 0;
311321
}

test/testtext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
#include <fcitx-utils/log.h>
88
#include <fcitx/text.h>
9+
#include "fcitx-utils/textformatflags.h"
910
using namespace fcitx;
1011

1112
void test_basic() {
@@ -33,6 +34,14 @@ void test_basic() {
3334
FCITX_ASSERT(lines[2].toStringForCommit() == "");
3435
FCITX_ASSERT(lines[3].toStringForCommit() == "Z");
3536
FCITX_ASSERT(lines[4].toStringForCommit() == "1");
37+
38+
text = Text("ABC");
39+
Text another = Text("DEF", TextFormatFlag::Bold);
40+
another.append("GHI", TextFormatFlag::Italic);
41+
text.append(another);
42+
FCITX_ASSERT(text.toString() == "ABCDEFGHI");
43+
FCITX_ASSERT(text.formatAt(1) == TextFormatFlag::Bold);
44+
FCITX_ASSERT(text.formatAt(2) == TextFormatFlag::Italic);
3645
}
3746

3847
void test_normalize() {

0 commit comments

Comments
 (0)