Skip to content

Commit

Permalink
mangle: Fix removing (%) flags that are disabled
Browse files Browse the repository at this point in the history
Closes: #43
Signed-off-by: Michał Górny <mgorny@gentoo.org>
  • Loading branch information
mgorny committed Sep 22, 2023
1 parent cdc6082 commit e7135e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions flaggie/mangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,21 @@ class shared:
matched = False

def filter_by_full(flag: str) -> bool:
if flag == full_name:
if flag.lstrip("-") == full_name:
logging.debug(f"Removing {flag}")
shared.matched = True
return False
return True

def filter_by_prefix(flag: str) -> bool:
if flag.startswith(f"{prefix_lc}_"):
if flag.lstrip("-").startswith(f"{prefix_lc}_"):
logging.debug(f"Removing {flag}")
shared.matched = True
return False
return True

def filter_by_name(flag: str) -> bool:
if flag == name:
if flag.lstrip("-") == name:
logging.debug(f"Removing {prefix}: {flag}")
shared.matched = True
return False
Expand Down
16 changes: 8 additions & 8 deletions test/test_mangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ def test_remove_flag(package):
"",
f"{package} foo bar GROUP: foo",
"dev-foo/bar foo",
f"{package} baz foo group_foo",
f"{package} foo",
f"{package} baz -foo group_foo",
f"{package} -foo",
])
remove_flag(config, package, None, "foo")
assert get_modified_line_nos(config[0]) == {2, 4}
Expand All @@ -396,10 +396,10 @@ def test_remove_flag(package):
def test_remove_flag_in_group(package):
config = get_config(["*/* foo GROUP: foo",
"",
f"{package} foo bar GROUP: foo bar GROUP: foo",
f"{package} foo bar GROUP: foo bar GROUP: -foo",
"dev-foo/bar foo",
f"{package} baz foo group_foo",
f"{package} group_foo GROUP: foo",
f"{package} -group_foo GROUP: foo",
])
remove_flag(config, package, "group", "foo")
assert get_modified_line_nos(config[0]) == {2, 4}
Expand All @@ -416,7 +416,7 @@ def test_remove_flag_in_group(package):
def test_remove_all_in_group(package):
config = get_config(["*/* foo GROUP: foo",
"",
f"{package} foo bar GROUP: foo bar GROUP: foo",
f"{package} foo bar GROUP: foo -bar GROUP: foo",
"dev-foo/bar foo",
f"{package} baz foo group_foo",
f"{package} group_foo GROUP: foo",
Expand All @@ -436,10 +436,10 @@ def test_remove_all_in_group(package):
def test_remove_all(package):
config = get_config(["*/* foo GROUP: foo",
"",
f"{package} foo bar GROUP: foo bar GROUP: foo",
f"{package} foo -bar GROUP: foo bar GROUP: foo",
"dev-foo/bar foo",
f"{package} baz foo group_foo",
f"{package} group_foo GROUP: foo",
f"{package} baz -foo group_foo",
f"{package} group_foo GROUP: -foo",
])
remove_flag(config, package, None, None)
assert get_modified_line_nos(config[0]) == set()
Expand Down

0 comments on commit e7135e9

Please sign in to comment.