Skip to content

Commit

Permalink
Merge pull request #19 from Cyerunix/patch-1
Browse files Browse the repository at this point in the history
Update parser.py
  • Loading branch information
angelhof authored Jul 26, 2024
2 parents fd11d76 + c0703e7 commit 2c06fb4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pash_annotations/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def parse(command) -> CommandInvocationInitial:
i = 1
while i < len(parsed_elements_list):
potential_flag_or_option = parsed_elements_list[i]
if potential_flag_or_option == '': # empty string counts as an operand
break
if potential_flag_or_option in set_of_all_flags:
flag_name_as_string: str = dict_flag_to_primary_repr.get(potential_flag_or_option, potential_flag_or_option)
flag: Flag = Flag(flag_name_as_string)
Expand Down
24 changes: 24 additions & 0 deletions pash_annotations/parser/tests/test_parser_empty_str.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''This is solely to test whether commands with the empty string as an operand
such as echo "" function properly'''

from pash_annotations.datatypes.CommandInvocationInitial import CommandInvocationInitial
from pash_annotations.parser.parser import parse
from pash_annotations.datatypes.BasicDatatypes import Operand

def test_empty_str_1():
parser_result = parse('echo ""')

args = []
operands = [Operand("")]
expected_result = CommandInvocationInitial("echo", args, operands)

assert expected_result == parser_result

def test_empty_str_2():
parser_result = parse('cat ""')

args = []
operands = [Operand("")]
expected_result = CommandInvocationInitial("cat", args, operands)

assert expected_result == parser_result

0 comments on commit 2c06fb4

Please sign in to comment.