@@ -98,6 +98,7 @@ void main() {
9898
9999 MentionAutocompleteQuery mention (String raw) => MentionAutocompleteQuery (raw, silent: false );
100100 MentionAutocompleteQuery silentMention (String raw) => MentionAutocompleteQuery (raw, silent: true );
101+ ChannelLinkAutocompleteQuery channelLink (String raw) => ChannelLinkAutocompleteQuery (raw);
101102 EmojiAutocompleteQuery emoji (String raw) => EmojiAutocompleteQuery (raw);
102103
103104 doTest ('' , null );
@@ -182,6 +183,83 @@ void main() {
182183 doTest ('If @chris is around, please ask him.^' , null ); // @ sign is too far away from cursor
183184 doTest ('If @_chris is around, please ask him.^' , null ); // @ sign is too far away from cursor
184185
186+ // #channel link.
187+
188+ doTest ('^#' , null );
189+ doTest ('^#abc' , null );
190+ doTest ('#abc' , null ); // (no cursor)
191+
192+ doTest ('~#^' , channelLink ('' ));
193+ doTest ('~#abc^' , channelLink ('abc' ));
194+ doTest ('~#abc ^' , channelLink ('abc ' ));
195+ doTest ('~#abc def^' , channelLink ('abc def' ));
196+
197+ // Accept space before channel link syntax.
198+ doTest (' ~#abc^' , channelLink ('abc' ));
199+ doTest ('xyz ~#abc^' , channelLink ('abc' ));
200+
201+ // Accept punctuations before channel link syntax.
202+ doTest ('#~#abc^' , channelLink ('abc' ));
203+ doTest ('@~#abc^' , channelLink ('abc' ));
204+ doTest (':~#abc^' , channelLink ('abc' ));
205+ doTest ('!~#abc^' , channelLink ('abc' ));
206+ doTest (',~#abc^' , channelLink ('abc' ));
207+ doTest ('.~#abc^' , channelLink ('abc' ));
208+ doTest ('(~#abc^' , channelLink ('abc' )); doTest (')~#abc^' , channelLink ('abc' ));
209+ doTest ('{~#abc^' , channelLink ('abc' )); doTest ('}~#abc^' , channelLink ('abc' ));
210+ doTest ('[~#abc^' , channelLink ('abc' )); doTest (']~#abc^' , channelLink ('abc' ));
211+ // … and other punctuations.
212+
213+ // Avoid other characters before channel link syntax.
214+ doTest ('\$ #abc^' , null );
215+ doTest ('+#abc^' , null );
216+ doTest ('=#abc^' , null );
217+ doTest ('XYZ#abc^' , null );
218+ doTest ('xyz#abc^' , null );
219+ // … but
220+ doTest ('~#xyz#abc^' , channelLink ('xyz#abc' ));
221+
222+ // Avoid leading space character in query.
223+ doTest ('# ^' , null );
224+ doTest ('# abc^' , null );
225+
226+ // Avoid line-break characters in query.
227+ doTest ('#\n ^' , null ); doTest ('#a\n ^' , null ); doTest ('#\n a^' , null ); doTest ('#a\n b^' , null );
228+ doTest ('#\r ^' , null ); doTest ('#a\r ^' , null ); doTest ('#\r a^' , null ); doTest ('#a\r b^' , null );
229+ doTest ('#\r\n ^' , null ); doTest ('#a\r\n ^' , null ); doTest ('#\r\n a^' , null ); doTest ('#a\r\n b^' , null );
230+
231+ // Allow all other sorts of characters in query.
232+ doTest ('~#\u 0000^' , channelLink ('\u 0000' )); // control
233+ doTest ('~#\u 061C^' , channelLink ('\u 061C' )); // format character
234+ doTest ('~#\u 0600^' , channelLink ('\u 0600' )); // format
235+ doTest ('~#\u D834^' , channelLink ('\u D834' )); // leading surrogate
236+ doTest ('~#`^' , channelLink ('`' )); doTest ('~#a`b^' , channelLink ('a`b' ));
237+ doTest ('~#\\ ^' , channelLink ('\\ ' )); doTest ('~#a\\ b^' , channelLink ('a\\ b' ));
238+ doTest ('~#"^' , channelLink ('"' )); doTest ('~#a"b^' , channelLink ('a"b' ));
239+ doTest ('~#>^' , channelLink ('>' )); doTest ('~#a>b^' , channelLink ('a>b' ));
240+ doTest ('~#&^' , channelLink ('&' )); doTest ('~#a&b^' , channelLink ('a&b' ));
241+ doTest ('~#_^' , channelLink ('_' )); doTest ('~#a_b^' , channelLink ('a_b' ));
242+ doTest ('~#*^' , channelLink ('*' )); doTest ('~#a*b^' , channelLink ('a*b' ));
243+
244+ // Two leading stars ('**') in query are omitted.
245+ doTest ('~#**^' , channelLink ('' ));
246+ doTest ('~#**abc^' , channelLink ('abc' ));
247+ doTest ('~#**abc ^' , channelLink ('abc ' ));
248+ doTest ('~#**abc def^' , channelLink ('abc def' ));
249+ doTest ('#** ^' , null );
250+ doTest ('#** abc^' , null );
251+ doTest ('~#**abc*^' , channelLink ('abc*' ));
252+
253+ // Query with leading '**' should not contain other '**'.
254+ doTest ('#**abc**^' , null );
255+ doTest ('#**abc** ^' , null );
256+ doTest ('#**abc** def^' , null );
257+
258+ // Query without leading '**' can contain other '**'.
259+ doTest ('~#abc**^' , channelLink ('abc**' ));
260+ doTest ('~#abc** ^' , channelLink ('abc** ' ));
261+ doTest ('~#abc** def^' , channelLink ('abc** def' ));
262+
185263 // Emoji (":smile:").
186264
187265 // Basic positive examples, to contrast with all the negative examples below.
0 commit comments