File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,9 +84,9 @@ const (
8484// Pre-compiled regexes for detecting point operations with targets
8585var (
8686 // User mention pattern: <@U123456> ++ (captures user ID and operator)
87- userOperationPattern = regexp .MustCompile (`<@([A-Z0-9]+)>[ ]*(\+\+|-{2}|={2})` )
87+ userOperationPattern = regexp .MustCompile (`<@([A-Z0-9]+)>[ ]*(\+\+|-{2}|={2})[ ]*($|\n) ` )
8888 // Emoji pattern: :emoji: ++ (captures emoji name and operator)
89- emojiOperationPattern = regexp .MustCompile (`:([a-zA-Z0-9_+-]+):[ ]*(\+\+|-{2}|={2})` )
89+ emojiOperationPattern = regexp .MustCompile (`:([a-zA-Z0-9_+-]+):[ ]*(\+\+|-{2}|={2})[ ]*($|\n) ` )
9090)
9191
9292// parseOperator converts an operator string to a PointOperation
Original file line number Diff line number Diff line change @@ -383,6 +383,70 @@ func TestDetectOperationAndTarget(t *testing.T) {
383383 wantTarget : "U123456" ,
384384 wantIsUser : true ,
385385 },
386+ // Operator must be at end of line or followed by newline
387+ {
388+ name : "Emoji operator followed by text" ,
389+ text : ":nya-nya: -- Settings" ,
390+ wantOp : NoOperation ,
391+ wantTarget : "" ,
392+ wantIsUser : false ,
393+ },
394+ {
395+ name : "Emoji operator followed by text (plus)" ,
396+ text : ":neko: ++ foo" ,
397+ wantOp : NoOperation ,
398+ wantTarget : "" ,
399+ wantIsUser : false ,
400+ },
401+ {
402+ name : "Emoji operator followed by text (equals)" ,
403+ text : ":neko: == foo" ,
404+ wantOp : NoOperation ,
405+ wantTarget : "" ,
406+ wantIsUser : false ,
407+ },
408+ {
409+ name : "Emoji operator followed by trailing spaces" ,
410+ text : ":neko: ++ " ,
411+ wantOp : PointUp ,
412+ wantTarget : "neko" ,
413+ wantIsUser : false ,
414+ },
415+ {
416+ name : "Emoji operator followed by newline" ,
417+ text : ":neko: ++\n " ,
418+ wantOp : PointUp ,
419+ wantTarget : "neko" ,
420+ wantIsUser : false ,
421+ },
422+ {
423+ name : "Emoji operator followed by newline and text" ,
424+ text : ":neko: ++\n some text" ,
425+ wantOp : PointUp ,
426+ wantTarget : "neko" ,
427+ wantIsUser : false ,
428+ },
429+ {
430+ name : "User operator followed by text" ,
431+ text : "<@U123456> ++ foo" ,
432+ wantOp : NoOperation ,
433+ wantTarget : "" ,
434+ wantIsUser : false ,
435+ },
436+ {
437+ name : "User operator followed by trailing spaces" ,
438+ text : "<@U123456> ++ " ,
439+ wantOp : PointUp ,
440+ wantTarget : "U123456" ,
441+ wantIsUser : true ,
442+ },
443+ {
444+ name : "User operator followed by newline and text" ,
445+ text : "<@U123456> ++\n some text" ,
446+ wantOp : PointUp ,
447+ wantTarget : "U123456" ,
448+ wantIsUser : true ,
449+ },
386450 }
387451
388452 for _ , tt := range tests {
You can’t perform that action at this time.
0 commit comments