1- """Tests for the karma regex pattern matching ."""
1+ """Tests for the karma regex pattern and _count_minus helper ."""
22
3- from src .cogs .commands .karma import KARMA_PATTERN
3+ from src .cogs .commands .karma import KARMA_PATTERN , _count_minus
44
55
6+ # ── Pattern matching ─────────────────────────────────────────────
7+
68def test_matches_user_plus ():
79 matches = KARMA_PATTERN .findall ("<@123456> +++" )
810 assert len (matches ) == 1
@@ -38,9 +40,12 @@ def test_no_match_single_plus():
3840 assert len (matches ) == 0
3941
4042
41- def test_no_match_single_minus ():
43+ def test_single_minus_matches_but_filtered_by_count ():
44+ """Single hyphen matches the regex, but _count_minus returns 1 (< 2 min), so
45+ _resolve_targets will skip it."""
4246 matches = KARMA_PATTERN .findall ("<@123456> -" )
43- assert len (matches ) == 0
47+ assert len (matches ) == 1 # regex matches
48+ assert _count_minus (matches [0 ][1 ]) < 2 # but below minimum
4449
4550
4651def test_multiple_mentions ():
@@ -57,18 +62,65 @@ def test_mixed_plus_minus():
5762 assert matches [1 ] == ("222" , "---" )
5863
5964
60- def test_matches_em_dash ():
65+ def test_matches_single_em_dash ():
66+ """Single em dash = 2 units, should match."""
6167 matches = KARMA_PATTERN .findall ("<@123456> \u2014 " )
6268 assert len (matches ) == 1
63- assert matches [0 ] == ("123456" , "\u2014 " )
6469
6570
6671def test_matches_multiple_em_dashes ():
6772 matches = KARMA_PATTERN .findall ("<@123456> \u2014 \u2014 \u2014 " )
6873 assert len (matches ) == 1
69- assert matches [0 ] == ("123456" , "\u2014 \u2014 \u2014 " )
74+
75+
76+ def test_matches_em_dash_plus_hyphen ():
77+ """— followed by - should match as one group."""
78+ matches = KARMA_PATTERN .findall ("<@123456> \u2014 -" )
79+ assert len (matches ) == 1
80+
81+
82+ def test_matches_hyphen_plus_em_dash ():
83+ """- followed by — should match as one group."""
84+ matches = KARMA_PATTERN .findall ("<@123456> -\u2014 " )
85+ assert len (matches ) == 1
86+
87+
88+ def test_matches_hyphens_plus_em_dash ():
89+ """-- followed by — should match as one group."""
90+ matches = KARMA_PATTERN .findall ("<@123456> --\u2014 " )
91+ assert len (matches ) == 1
7092
7193
7294def test_no_match_plain_text ():
7395 matches = KARMA_PATTERN .findall ("hello world" )
7496 assert len (matches ) == 0
97+
98+
99+ # ── _count_minus helper ─────────────────────────────────────────
100+
101+ def test_count_minus_hyphens ():
102+ assert _count_minus ("---" ) == 3
103+
104+
105+ def test_count_minus_em_dashes ():
106+ assert _count_minus ("\u2014 \u2014 " ) == 4
107+
108+
109+ def test_count_minus_mixed_em_hyphen ():
110+ """— followed by - = 2 + 1 = 3."""
111+ assert _count_minus ("\u2014 -" ) == 3
112+
113+
114+ def test_count_minus_mixed_hyphen_em ():
115+ """- followed by — = 1 + 2 = 3."""
116+ assert _count_minus ("-\u2014 " ) == 3
117+
118+
119+ def test_count_minus_single_em_dash ():
120+ """Single em dash = 2."""
121+ assert _count_minus ("\u2014 " ) == 2
122+
123+
124+ def test_count_minus_single_hyphen ():
125+ """Single hyphen = 1."""
126+ assert _count_minus ("-" ) == 1
0 commit comments