Skip to content

Commit

Permalink
Copmlete tests for command parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-n committed Sep 22, 2023
1 parent 8602959 commit fda84a7
Show file tree
Hide file tree
Showing 8 changed files with 666 additions and 240 deletions.
15 changes: 4 additions & 11 deletions poethepoet/helpers/command/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import re
from glob import escape
from typing import (
IO,
TYPE_CHECKING,
Dict,
Generic,
Expand All @@ -14,15 +13,14 @@
Tuple,
Type,
TypeVar,
Union,
cast,
)

if TYPE_CHECKING:
from .ast import Line, ParseConfig


def parse_poe_cmd(source: Union[IO[str], str], config: Optional["ParseConfig"] = None):
def parse_poe_cmd(source: str, config: Optional["ParseConfig"] = None):
from .ast import Glob, ParseConfig, ParseCursor, PythonGlob, Script

if not config:
Expand All @@ -31,12 +29,7 @@ def parse_poe_cmd(source: Union[IO[str], str], config: Optional["ParseConfig"] =
# python standard library glob module can support
config = ParseConfig(substitute_nodes={Glob: PythonGlob}, line_seperators=";")

if isinstance(source, str):
cursor = ParseCursor(((char for char in source)))
else:
cursor = ParseCursor.from_file(source)

return Script(cursor, config)
return Script(ParseCursor.from_string(source), config)


def resolve_command_tokens(
Expand Down Expand Up @@ -97,7 +90,7 @@ def finalize_token(token_parts):
yield finalize_token(token_parts)

param_words = (
(word, bool(glob_pattern.match(word)))
(word, bool(glob_pattern.search(word)))
for word in param_value.split()
)

Expand All @@ -106,7 +99,7 @@ def finalize_token(token_parts):
for param_word in param_words:
if token_parts:
yield finalize_token(token_parts)
token_parts.append(next(param_words))
token_parts.append(param_word)

if param_value[-1].isspace() and token_parts:
# param_value ends with a word break
Expand Down
Loading

0 comments on commit fda84a7

Please sign in to comment.