Skip to content

Commit

Permalink
Improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
walles committed Mar 11, 2024
1 parent ce58f72 commit 7c97323
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
10 changes: 8 additions & 2 deletions px/px_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
PERL_BIN = re.compile("^perl[.0-9]*$")


def get_coalesce_candidate(so_far: str) -> Optional[str]:
def get_trailing_absolute_path(so_far: str) -> Optional[str]:
"""
Extract a potential file path from the end of a string.
The coalescing logic will then base decisions on whether this file path
exists or not.
"""
start_index = -1
if so_far.startswith("/"):
start_index = 0
Expand Down Expand Up @@ -64,7 +70,7 @@ def should_coalesce(
return False

coalesced = " ".join(parts)
candidate = get_coalesce_candidate(coalesced)
candidate = get_trailing_absolute_path(coalesced)
if not candidate:
# This is not a candidate for coalescing
return False
Expand Down
14 changes: 7 additions & 7 deletions tests/px_commandline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@


def test_get_coalesce_candidate():
assert px_commandline.get_coalesce_candidate("/hello") == "/hello"
assert px_commandline.get_coalesce_candidate("/hello:/baloo") == "/baloo"
assert px_commandline.get_trailing_absolute_path("/hello") == "/hello"
assert px_commandline.get_trailing_absolute_path("/hello:/baloo") == "/baloo"

assert px_commandline.get_coalesce_candidate("-Dx=/hello") == "/hello"
assert px_commandline.get_coalesce_candidate("-Dx=/hello:/baloo") == "/baloo"
assert px_commandline.get_trailing_absolute_path("-Dx=/hello") == "/hello"
assert px_commandline.get_trailing_absolute_path("-Dx=/hello:/baloo") == "/baloo"

assert px_commandline.get_coalesce_candidate("hello") is None
assert px_commandline.get_coalesce_candidate("hello:/baloo") is None
assert px_commandline.get_trailing_absolute_path("hello") is None
assert px_commandline.get_trailing_absolute_path("hello:/baloo") is None

assert (
px_commandline.get_coalesce_candidate(
px_commandline.get_trailing_absolute_path(
"/A/IntelliJ IDEA.app/C/p/mm/lib/mm.jar:/A/IntelliJ IDEA.app/C/p/ms/lib/ms.jar:/A/IntelliJ"
)
== "/A/IntelliJ"
Expand Down

0 comments on commit 7c97323

Please sign in to comment.