Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Dec 10, 2024
1 parent 3267a9c commit 6153e70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/textual/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def score(search: _Search) -> float:
(2.0 if offset in first_letters else 1.0) for offset in search.offsets
)
# Divide by the number of groups
# 1 group no change, 2 groups score is halved etc
# 1 group no change, 2 groups score is halved etc.
score /= search.groups
return score

Expand Down
26 changes: 9 additions & 17 deletions tests/test_fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,20 @@
from textual.fuzzy import Matcher


def test_match():
matcher = Matcher("foo.bar")

# No match
assert matcher.match("egg") == 0
assert matcher.match("") == 0

# Perfect match
assert matcher.match("foo.bar") == 1.0
# Perfect match (with superfluous characters)
assert matcher.match("foo.bar sdf") == 1.0
assert matcher.match("xz foo.bar sdf") == 1.0
def test_no_match():
"""Check non matching score of zero."""
matcher = Matcher("x")
assert matcher.match("foo") == 0

# Partial matches
# 2 Groups
assert matcher.match("foo egg.bar") == 1.0 - 1 / 11

# 3 Groups
assert matcher.match("foo .ba egg r") == 1.0 - 2 / 13
def test_match_single_group():
"""Check that single groups rang higher."""
matcher = Matcher("abc")
assert matcher.match("foo abc bar") > matcher.match("fooa barc")


def test_boosted_matches():
"""Check first word matchers rank higher."""
matcher = Matcher("ss")

# First word matchers should score higher
Expand Down

0 comments on commit 6153e70

Please sign in to comment.