Skip to content

Commit 80950cd

Browse files
committed
fix: add tests for finding tags with partial versions
1 parent 68cf533 commit 80950cd

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/test_tags.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,67 @@ def test_find_tag_for_full_version_remains_exact():
3535

3636
assert found is not None
3737
assert found.name == "1.2.1"
38+
39+
40+
def test_find_tag_for_partial_version_with_prereleases_prefers_latest_version():
41+
tags = [
42+
_git_tag("1.2.0b1"),
43+
_git_tag("1.2.0"),
44+
_git_tag("1.2.1b1"),
45+
]
46+
47+
rules = TagRules()
48+
49+
found = rules.find_tag_for(tags, "1.2")
50+
51+
assert found is not None
52+
# 1.2.1b1 > 1.2.0 so it should be selected
53+
assert found.name == "1.2.1b1"
54+
55+
56+
def test_find_tag_for_partial_version_respects_tag_format():
57+
tags = [
58+
_git_tag("v1.2.0"),
59+
_git_tag("v1.2.1"),
60+
_git_tag("v1.3.0"),
61+
]
62+
63+
rules = TagRules(tag_format="v$version")
64+
65+
found = rules.find_tag_for(tags, "1.2")
66+
67+
assert found is not None
68+
assert found.name == "v1.2.1"
69+
70+
found = rules.find_tag_for(tags, "1")
71+
72+
assert found is not None
73+
assert found.name == "v1.3.0"
74+
75+
76+
def test_find_tag_for_partial_version_returns_none_when_no_match():
77+
tags = [
78+
_git_tag("2.0.0"),
79+
_git_tag("2.1.0"),
80+
]
81+
82+
rules = TagRules()
83+
84+
found = rules.find_tag_for(tags, "1.2")
85+
86+
assert found is None
87+
88+
89+
def test_find_tag_for_partial_version_ignores_invalid_tags():
90+
tags = [
91+
_git_tag("not-a-version"),
92+
_git_tag("1.2.0"),
93+
_git_tag("1.2.1"),
94+
]
95+
96+
rules = TagRules()
97+
98+
found = rules.find_tag_for(tags, "1.2")
99+
100+
assert found is not None
101+
assert found.name == "1.2.1"

0 commit comments

Comments
 (0)