Skip to content

Commit 683126c

Browse files
committed
More tests
1 parent 7e7a7b2 commit 683126c

File tree

1 file changed

+66
-70
lines changed

1 file changed

+66
-70
lines changed

tests/yup_gui/yup_TextEditor.cpp

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
==============================================================================
2020
*/
2121

22-
#if 0
23-
2422
#include <gtest/gtest.h>
2523

2624
#include <yup_gui/yup_gui.h>
@@ -29,16 +27,16 @@ using namespace yup;
2927

3028
namespace
3129
{
32-
constexpr auto kTestText = "Hello World";
33-
constexpr auto kMultilineText = "Line 1\nLine 2\nLine 3";
34-
}
30+
constexpr auto kTestText = "Hello World";
31+
constexpr auto kMultilineText = "Line 1\nLine 2\nLine 3";
32+
} // namespace
3533

3634
class TextEditorTests : public ::testing::Test
3735
{
3836
protected:
3937
void SetUp() override
4038
{
41-
editor = std::make_unique<TextEditor>("testEditor");
39+
editor = std::make_unique<TextEditor> ("testEditor");
4240
}
4341

4442
void TearDown() override
@@ -49,125 +47,123 @@ class TextEditorTests : public ::testing::Test
4947
std::unique_ptr<TextEditor> editor;
5048
};
5149

52-
TEST_F(TextEditorTests, ConstructorInitializesCorrectly)
50+
TEST_F (TextEditorTests, ConstructorInitializesCorrectly)
5351
{
54-
EXPECT_TRUE(editor->getText().isEmpty());
55-
EXPECT_EQ(0, editor->getCaretPosition());
56-
EXPECT_FALSE(editor->hasSelection());
57-
EXPECT_FALSE(editor->isMultiLine());
58-
EXPECT_FALSE(editor->isReadOnly());
52+
EXPECT_TRUE (editor->getText().isEmpty());
53+
EXPECT_EQ (0, editor->getCaretPosition());
54+
EXPECT_FALSE (editor->hasSelection());
55+
EXPECT_FALSE (editor->isMultiLine());
56+
EXPECT_FALSE (editor->isReadOnly());
5957
}
6058

61-
TEST_F(TextEditorTests, SetTextUpdatesContent)
59+
TEST_F (TextEditorTests, SetTextUpdatesContent)
6260
{
63-
editor->setText(kTestText);
64-
EXPECT_EQ(String(kTestText), editor->getText());
65-
EXPECT_EQ(0, editor->getCaretPosition());
61+
editor->setText (kTestText);
62+
EXPECT_EQ (String (kTestText), editor->getText());
63+
EXPECT_EQ (0, editor->getCaretPosition());
6664
}
6765

68-
TEST_F(TextEditorTests, CaretPositionHandling)
66+
TEST_F (TextEditorTests, CaretPositionHandling)
6967
{
70-
editor->setText(kTestText);
68+
editor->setText (kTestText);
7169

72-
editor->setCaretPosition(5);
73-
EXPECT_EQ(5, editor->getCaretPosition());
70+
editor->setCaretPosition (5);
71+
EXPECT_EQ (5, editor->getCaretPosition());
7472

7573
// Test bounds checking
76-
editor->setCaretPosition(-1);
77-
EXPECT_EQ(0, editor->getCaretPosition());
74+
editor->setCaretPosition (-1);
75+
EXPECT_EQ (0, editor->getCaretPosition());
7876

79-
editor->setCaretPosition(1000);
80-
EXPECT_EQ(editor->getText().length(), editor->getCaretPosition());
77+
editor->setCaretPosition (1000);
78+
EXPECT_EQ (editor->getText().length(), editor->getCaretPosition());
8179
}
8280

83-
TEST_F(TextEditorTests, SelectionHandling)
81+
TEST_F (TextEditorTests, SelectionHandling)
8482
{
85-
editor->setText(kTestText);
83+
editor->setText (kTestText);
8684

8785
// Test setting selection
88-
editor->setSelection(Range<int>(2, 5));
89-
EXPECT_TRUE(editor->hasSelection());
90-
EXPECT_EQ(String("llo W"), editor->getSelectedText());
86+
editor->setSelection (Range<int> (2, 7));
87+
EXPECT_TRUE (editor->hasSelection());
88+
EXPECT_EQ (String ("llo W"), editor->getSelectedText());
9189

9290
// Test select all
9391
editor->selectAll();
94-
EXPECT_EQ(String(kTestText), editor->getSelectedText());
92+
EXPECT_EQ (String (kTestText), editor->getSelectedText());
9593

9694
// Test clearing selection
97-
editor->setCaretPosition(3);
98-
EXPECT_FALSE(editor->hasSelection());
95+
editor->setCaretPosition (3);
96+
EXPECT_FALSE (editor->hasSelection());
9997
}
10098

101-
TEST_F(TextEditorTests, TextInsertion)
99+
TEST_F (TextEditorTests, TextInsertion)
102100
{
103-
editor->setText("Hello");
104-
editor->setCaretPosition(5);
105-
editor->insertText(" World");
101+
editor->setText ("Hello");
102+
editor->setCaretPosition (5);
103+
editor->insertText (" World");
106104

107-
EXPECT_EQ(String("Hello World"), editor->getText());
108-
EXPECT_EQ(11, editor->getCaretPosition());
105+
EXPECT_EQ (String ("Hello World"), editor->getText());
106+
EXPECT_EQ (11, editor->getCaretPosition());
109107
}
110108

111-
TEST_F(TextEditorTests, TextDeletion)
109+
TEST_F (TextEditorTests, TextDeletion)
112110
{
113-
editor->setText(kTestText);
114-
editor->setSelection(Range<int>(6, 5)); // Select "World"
111+
editor->setText (kTestText);
112+
editor->setSelection (Range<int> (6, 11)); // Select "World"
115113
editor->deleteSelectedText();
116114

117-
EXPECT_EQ(String("Hello "), editor->getText());
118-
EXPECT_EQ(6, editor->getCaretPosition());
119-
EXPECT_FALSE(editor->hasSelection());
115+
EXPECT_EQ (String ("Hello "), editor->getText());
116+
EXPECT_EQ (6, editor->getCaretPosition());
117+
EXPECT_FALSE (editor->hasSelection());
120118
}
121119

122-
TEST_F(TextEditorTests, MultiLineMode)
120+
TEST_F (TextEditorTests, MultiLineMode)
123121
{
124-
editor->setMultiLine(true);
125-
EXPECT_TRUE(editor->isMultiLine());
122+
editor->setMultiLine (true);
123+
EXPECT_TRUE (editor->isMultiLine());
126124

127-
editor->setText(kMultilineText);
128-
EXPECT_EQ(String(kMultilineText), editor->getText());
125+
editor->setText (kMultilineText);
126+
EXPECT_EQ (String (kMultilineText), editor->getText());
129127
}
130128

131-
TEST_F(TextEditorTests, ReadOnlyMode)
129+
TEST_F (TextEditorTests, ReadOnlyMode)
132130
{
133-
editor->setText(kTestText);
134-
editor->setReadOnly(true);
135-
EXPECT_TRUE(editor->isReadOnly());
131+
editor->setText (kTestText);
132+
editor->setReadOnly (true);
133+
EXPECT_TRUE (editor->isReadOnly());
136134

137135
// Text insertion should be ignored
138-
editor->insertText(" Extra");
139-
EXPECT_EQ(String(kTestText), editor->getText());
136+
editor->insertText (" Extra");
137+
EXPECT_EQ (String (kTestText), editor->getText());
140138

141139
// Selection deletion should be ignored
142140
editor->selectAll();
143141
editor->deleteSelectedText();
144-
EXPECT_EQ(String(kTestText), editor->getText());
142+
EXPECT_EQ (String (kTestText), editor->getText());
145143
}
146144

147-
TEST_F(TextEditorTests, FontHandling)
145+
TEST_F (TextEditorTests, FontHandling)
148146
{
149147
// Test default font
150-
EXPECT_FALSE(editor->getFont().has_value());
148+
EXPECT_FALSE (editor->getFont().has_value());
151149

152150
// Test setting custom font
153151
Font customFont;
154-
editor->setFont(customFont);
155-
EXPECT_TRUE(editor->getFont().has_value());
152+
editor->setFont (customFont);
153+
EXPECT_TRUE (editor->getFont().has_value());
156154

157155
// Test resetting font
158156
editor->resetFont();
159-
EXPECT_FALSE(editor->getFont().has_value());
157+
EXPECT_FALSE (editor->getFont().has_value());
160158
}
161159

162-
TEST(TextEditorStaticTests, ColorIdentifiersExist)
160+
TEST (TextEditorStaticTests, ColorIdentifiersExist)
163161
{
164162
// Verify that color identifiers are properly defined
165-
EXPECT_FALSE(TextEditor::Colors::backgroundColorId.toString().isEmpty());
166-
EXPECT_FALSE(TextEditor::Colors::textColorId.toString().isEmpty());
167-
EXPECT_FALSE(TextEditor::Colors::caretColorId.toString().isEmpty());
168-
EXPECT_FALSE(TextEditor::Colors::selectionColorId.toString().isEmpty());
169-
EXPECT_FALSE(TextEditor::Colors::outlineColorId.toString().isEmpty());
170-
EXPECT_FALSE(TextEditor::Colors::focusedOutlineColorId.toString().isEmpty());
163+
EXPECT_FALSE (TextEditor::Style::backgroundColorId.toString().isEmpty());
164+
EXPECT_FALSE (TextEditor::Style::textColorId.toString().isEmpty());
165+
EXPECT_FALSE (TextEditor::Style::caretColorId.toString().isEmpty());
166+
EXPECT_FALSE (TextEditor::Style::selectionColorId.toString().isEmpty());
167+
EXPECT_FALSE (TextEditor::Style::outlineColorId.toString().isEmpty());
168+
EXPECT_FALSE (TextEditor::Style::focusedOutlineColorId.toString().isEmpty());
171169
}
172-
173-
#endif

0 commit comments

Comments
 (0)