@@ -32,37 +32,35 @@ namespace TerminalAppLocalTests
32
32
{
33
33
auto result = RunOnUIThread ([]() {
34
34
const auto paletteItem{ winrt::make<winrt::TerminalApp::implementation::CommandLinePaletteItem>(L" AAAAAABBBBBBCCC" ) };
35
+ const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
36
+
35
37
{
36
38
Log::Comment (L" Testing command name segmentation with no filter" );
37
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
38
- auto segments = filteredCommand->_computeHighlightedName ().Segments ();
39
+ auto segments = filteredCommand->HighlightedName ().Segments ();
39
40
VERIFY_ARE_EQUAL (segments.Size (), 1u );
40
41
VERIFY_ARE_EQUAL (segments.GetAt (0 ).TextSegment (), L" AAAAAABBBBBBCCC" );
41
42
VERIFY_IS_FALSE (segments.GetAt (0 ).IsHighlighted ());
42
43
}
43
44
{
44
45
Log::Comment (L" Testing command name segmentation with empty filter" );
45
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
46
- filteredCommand->_Filter = L" " ;
47
- auto segments = filteredCommand->_computeHighlightedName ().Segments ();
46
+ filteredCommand->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" " )));
47
+ auto segments = filteredCommand->HighlightedName ().Segments ();
48
48
VERIFY_ARE_EQUAL (segments.Size (), 1u );
49
49
VERIFY_ARE_EQUAL (segments.GetAt (0 ).TextSegment (), L" AAAAAABBBBBBCCC" );
50
50
VERIFY_IS_FALSE (segments.GetAt (0 ).IsHighlighted ());
51
51
}
52
52
{
53
53
Log::Comment (L" Testing command name segmentation with filter equal to the string" );
54
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
55
- filteredCommand->_Filter = L" AAAAAABBBBBBCCC" ;
56
- auto segments = filteredCommand->_computeHighlightedName ().Segments ();
54
+ filteredCommand->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" AAAAAABBBBBBCCC" )));
55
+ auto segments = filteredCommand->HighlightedName ().Segments ();
57
56
VERIFY_ARE_EQUAL (segments.Size (), 1u );
58
57
VERIFY_ARE_EQUAL (segments.GetAt (0 ).TextSegment (), L" AAAAAABBBBBBCCC" );
59
58
VERIFY_IS_TRUE (segments.GetAt (0 ).IsHighlighted ());
60
59
}
61
60
{
62
61
Log::Comment (L" Testing command name segmentation with filter with first character matching" );
63
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
64
- filteredCommand->_Filter = L" A" ;
65
- auto segments = filteredCommand->_computeHighlightedName ().Segments ();
62
+ filteredCommand->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" A" )));
63
+ auto segments = filteredCommand->HighlightedName ().Segments ();
66
64
VERIFY_ARE_EQUAL (segments.Size (), 2u );
67
65
VERIFY_ARE_EQUAL (segments.GetAt (0 ).TextSegment (), L" A" );
68
66
VERIFY_IS_TRUE (segments.GetAt (0 ).IsHighlighted ());
@@ -71,9 +69,8 @@ namespace TerminalAppLocalTests
71
69
}
72
70
{
73
71
Log::Comment (L" Testing command name segmentation with filter with other case" );
74
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
75
- filteredCommand->_Filter = L" a" ;
76
- auto segments = filteredCommand->_computeHighlightedName ().Segments ();
72
+ filteredCommand->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" a" )));
73
+ auto segments = filteredCommand->HighlightedName ().Segments ();
77
74
VERIFY_ARE_EQUAL (segments.Size (), 2u );
78
75
VERIFY_ARE_EQUAL (segments.GetAt (0 ).TextSegment (), L" A" );
79
76
VERIFY_IS_TRUE (segments.GetAt (0 ).IsHighlighted ());
@@ -82,24 +79,20 @@ namespace TerminalAppLocalTests
82
79
}
83
80
{
84
81
Log::Comment (L" Testing command name segmentation with filter matching several characters" );
85
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
86
- filteredCommand->_Filter = L" ab" ;
87
- auto segments = filteredCommand->_computeHighlightedName ().Segments ();
88
- VERIFY_ARE_EQUAL (segments.Size (), 4u );
89
- VERIFY_ARE_EQUAL (segments.GetAt (0 ).TextSegment (), L" A" );
90
- VERIFY_IS_TRUE (segments.GetAt (0 ).IsHighlighted ());
91
- VERIFY_ARE_EQUAL (segments.GetAt (1 ).TextSegment (), L" AAAAA" );
92
- VERIFY_IS_FALSE (segments.GetAt (1 ).IsHighlighted ());
93
- VERIFY_ARE_EQUAL (segments.GetAt (2 ).TextSegment (), L" B" );
94
- VERIFY_IS_TRUE (segments.GetAt (2 ).IsHighlighted ());
95
- VERIFY_ARE_EQUAL (segments.GetAt (3 ).TextSegment (), L" BBBBBCCC" );
96
- VERIFY_IS_FALSE (segments.GetAt (3 ).IsHighlighted ());
82
+ filteredCommand->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" ab" )));
83
+ auto segments = filteredCommand->HighlightedName ().Segments ();
84
+ VERIFY_ARE_EQUAL (segments.Size (), 3u );
85
+ VERIFY_ARE_EQUAL (segments.GetAt (0 ).TextSegment (), L" AAAAA" );
86
+ VERIFY_IS_FALSE (segments.GetAt (0 ).IsHighlighted ());
87
+ VERIFY_ARE_EQUAL (segments.GetAt (1 ).TextSegment (), L" AB" );
88
+ VERIFY_IS_TRUE (segments.GetAt (1 ).IsHighlighted ());
89
+ VERIFY_ARE_EQUAL (segments.GetAt (2 ).TextSegment (), L" BBBBBCCC" );
90
+ VERIFY_IS_FALSE (segments.GetAt (2 ).IsHighlighted ());
97
91
}
98
92
{
99
93
Log::Comment (L" Testing command name segmentation with non matching filter" );
100
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
101
- filteredCommand->_Filter = L" abcd" ;
102
- auto segments = filteredCommand->_computeHighlightedName ().Segments ();
94
+ filteredCommand->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" abcd" )));
95
+ auto segments = filteredCommand->HighlightedName ().Segments ();
103
96
VERIFY_ARE_EQUAL (segments.Size (), 1u );
104
97
VERIFY_ARE_EQUAL (segments.GetAt (0 ).TextSegment (), L" AAAAAABBBBBBCCC" );
105
98
VERIFY_IS_FALSE (segments.GetAt (0 ).IsHighlighted ());
@@ -113,53 +106,37 @@ namespace TerminalAppLocalTests
113
106
{
114
107
auto result = RunOnUIThread ([]() {
115
108
const auto paletteItem{ winrt::make<winrt::TerminalApp::implementation::CommandLinePaletteItem>(L" AAAAAABBBBBBCCC" ) };
116
- {
117
- Log::Comment (L" Testing weight of command with no filter" );
118
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
119
- filteredCommand->_HighlightedName = filteredCommand->_computeHighlightedName ();
120
- auto weight = filteredCommand->_computeWeight ();
121
- VERIFY_ARE_EQUAL (weight, 0 );
122
- }
123
- {
124
- Log::Comment (L" Testing weight of command with empty filter" );
125
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
126
- filteredCommand->_Filter = L" " ;
127
- filteredCommand->_HighlightedName = filteredCommand->_computeHighlightedName ();
128
- auto weight = filteredCommand->_computeWeight ();
129
- VERIFY_ARE_EQUAL (weight, 0 );
130
- }
131
- {
132
- Log::Comment (L" Testing weight of command with filter equal to the string" );
133
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
134
- filteredCommand->_Filter = L" AAAAAABBBBBBCCC" ;
135
- filteredCommand->_HighlightedName = filteredCommand->_computeHighlightedName ();
136
- auto weight = filteredCommand->_computeWeight ();
137
- VERIFY_ARE_EQUAL (weight, 30 ); // 1 point for the first char and 2 points for the 14 consequent ones + 1 point for the beginning of the word
138
- }
139
- {
140
- Log::Comment (L" Testing weight of command with filter with first character matching" );
141
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
142
- filteredCommand->_Filter = L" A" ;
143
- filteredCommand->_HighlightedName = filteredCommand->_computeHighlightedName ();
144
- auto weight = filteredCommand->_computeWeight ();
145
- VERIFY_ARE_EQUAL (weight, 2 ); // 1 point for the first char match + 1 point for the beginning of the word
146
- }
147
- {
148
- Log::Comment (L" Testing weight of command with filter with other case" );
149
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
150
- filteredCommand->_Filter = L" a" ;
151
- filteredCommand->_HighlightedName = filteredCommand->_computeHighlightedName ();
152
- auto weight = filteredCommand->_computeWeight ();
153
- VERIFY_ARE_EQUAL (weight, 2 ); // 1 point for the first char match + 1 point for the beginning of the word
154
- }
155
- {
156
- Log::Comment (L" Testing weight of command with filter matching several characters" );
157
- const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
158
- filteredCommand->_Filter = L" ab" ;
159
- filteredCommand->_HighlightedName = filteredCommand->_computeHighlightedName ();
160
- auto weight = filteredCommand->_computeWeight ();
161
- VERIFY_ARE_EQUAL (weight, 3 ); // 1 point for the first char match + 1 point for the beginning of the word + 1 point for the match of "b"
162
- }
109
+ const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
110
+
111
+ const auto weigh = [&](const wchar_t * str) {
112
+ std::shared_ptr<fzf::matcher::Pattern> pattern;
113
+ if (str)
114
+ {
115
+ pattern = std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (str));
116
+ }
117
+ filteredCommand->UpdateFilter (std::move (pattern));
118
+ return filteredCommand->Weight ();
119
+ };
120
+
121
+ const auto null = weigh (nullptr );
122
+ const auto empty = weigh (L" " );
123
+ const auto full = weigh (L" AAAAAABBBBBBCCC" );
124
+ const auto firstChar = weigh (L" A" );
125
+ const auto otherCase = weigh (L" a" );
126
+ const auto severalChars = weigh (L" ab" );
127
+
128
+ VERIFY_ARE_EQUAL (null, 0 );
129
+ VERIFY_ARE_EQUAL (empty, 0 );
130
+ VERIFY_IS_GREATER_THAN (full, 100 );
131
+
132
+ VERIFY_IS_GREATER_THAN (firstChar, 0 );
133
+ VERIFY_IS_LESS_THAN (firstChar, full);
134
+
135
+ VERIFY_IS_GREATER_THAN (otherCase, 0 );
136
+ VERIFY_IS_LESS_THAN (otherCase, full);
137
+
138
+ VERIFY_IS_GREATER_THAN (severalChars, otherCase);
139
+ VERIFY_IS_LESS_THAN (severalChars, full);
163
140
});
164
141
165
142
VERIFY_SUCCEEDED (result);
@@ -181,31 +158,23 @@ namespace TerminalAppLocalTests
181
158
{
182
159
Log::Comment (L" Testing comparison of commands with empty filter" );
183
160
const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
184
- filteredCommand->_Filter = L" " ;
185
- filteredCommand->_HighlightedName = filteredCommand->_computeHighlightedName ();
186
- filteredCommand->_Weight = filteredCommand->_computeWeight ();
161
+ filteredCommand->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" " )));
187
162
188
163
const auto filteredCommand2 = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem2);
189
- filteredCommand2->_Filter = L" " ;
190
- filteredCommand2->_HighlightedName = filteredCommand2->_computeHighlightedName ();
191
- filteredCommand2->_Weight = filteredCommand2->_computeWeight ();
164
+ filteredCommand2->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" " )));
192
165
193
166
VERIFY_ARE_EQUAL (filteredCommand->Weight (), filteredCommand2->Weight ());
194
167
VERIFY_IS_TRUE (winrt::TerminalApp::implementation::FilteredCommand::Compare (*filteredCommand, *filteredCommand2));
195
168
}
196
169
{
197
170
Log::Comment (L" Testing comparison of commands with different weights" );
198
171
const auto filteredCommand = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem);
199
- filteredCommand->_Filter = L" B" ;
200
- filteredCommand->_HighlightedName = filteredCommand->_computeHighlightedName ();
201
- filteredCommand->_Weight = filteredCommand->_computeWeight ();
172
+ filteredCommand->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" B" )));
202
173
203
174
const auto filteredCommand2 = winrt::make_self<winrt::TerminalApp::implementation::FilteredCommand>(paletteItem2);
204
- filteredCommand2->_Filter = L" B" ;
205
- filteredCommand2->_HighlightedName = filteredCommand2->_computeHighlightedName ();
206
- filteredCommand2->_Weight = filteredCommand2->_computeWeight ();
175
+ filteredCommand2->UpdateFilter (std::make_shared<fzf::matcher::Pattern>(fzf::matcher::ParsePattern (L" B" )));
207
176
208
- VERIFY_IS_TRUE (filteredCommand->Weight () < filteredCommand2->Weight ()); // Second command gets more points due to the beginning of the word
177
+ VERIFY_IS_LESS_THAN (filteredCommand->Weight (), filteredCommand2->Weight ()); // Second command gets more points due to the beginning of the word
209
178
VERIFY_IS_FALSE (winrt::TerminalApp::implementation::FilteredCommand::Compare (*filteredCommand, *filteredCommand2));
210
179
}
211
180
});
0 commit comments