Skip to content

Commit

Permalink
Fix corner case in transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberiaResurrection committed Nov 20, 2024
1 parent 99520ba commit 06bd76b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions PyRoute/Inputs/BaseTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,21 @@ def trim_raw_string(self, tree):
self.raw = self.raw[index:]

def _square_up_parsed_zero(self, rawstring, parsed):
from PyRoute.Inputs.ParseStarInput import ParseStarInput
bitz = [item for item in rawstring.split(' ') if '' != item]
if 3 == len(bitz) and bitz[0] == parsed['nobles'] and bitz[1] == parsed['base'] and bitz[2] == parsed['zone']:
return parsed
if 2 == len(bitz) and "" == parsed['zone']:
if 2 < len(bitz[0]): # bitz[0] can only possibly be nobles, so return
return parsed
if 1 < len(bitz[1]): # if bitz[1] is more than one char, it can't be a trade zone, so return
return parsed
non_noble = [item for item in bitz[0] if item not in ParseStarInput.valid_nobles]
if 0 < len(non_noble): # If one or more chars in bitz[0] is not a valid noble call, then we have a base code and trade zone
parsed['zone'] = parsed['base']
parsed['base'] = parsed['nobles']
parsed['nobles'] = ''
return parsed
if 3 == len(bitz):
parsed['nobles'] = bitz[0]
parsed['base'] = bitz[1]
Expand Down
4 changes: 3 additions & 1 deletion PyRoute/Inputs/ParseStarInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class ParseStarInput:
station_parser = None
station_transformer = None
deep_space = {}
valid_zone = 'arufgbARUFGB-'
valid_nobles = 'BCcDEeFfGH-'

@staticmethod
def parse_line_into_star_core(star, line, sector, pop_code, ru_calc, fix_pop=False):
Expand Down Expand Up @@ -84,7 +86,7 @@ def parse_line_into_star_core(star, line, sector, pop_code, ru_calc, fix_pop=Fal
if ('' == star.baseCode) or ('-' != star.baseCode and 1 == len(star.baseCode) and not star.baseCode.isalpha()):
star.baseCode = '-'
star.zone = data[13].strip()
if not star.zone or star.zone not in 'arufgbARUFGB-':
if not star.zone or star.zone not in ParseStarInput.valid_zone:
star.zone = '-'
star.zone = star.zone.upper()
star.ggCount = 0 if (len(data[14]) < 3 or not data[14][2] or data[14][2] in 'X?') else int(data[14][2], 16)
Expand Down
1 change: 1 addition & 0 deletions Tests/Hypothesis/testStar.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def setUp(self) -> None:
@example('0101 000000000000000 ???????-? 0000000000000 0 0 B - A 000 00')
@example('0101 000000000000000 ???????-? 000000000000000 {-0} (000-0) - * A 000 00')
@example('0101 000000000000000 ???????-? 000000000000000 {-0} (000-0) - - - A 000 00')
@example("0101 000000000000000 ?000000-0 {3 } (7TG-1) [2IBt] EHEG - 569 9 C5'")
def test_parse_line_to_star(self, s):
hyp_line = "Hypothesis input: " + s
sector = Sector('# Core', '# 0, 0')
Expand Down

0 comments on commit 06bd76b

Please sign in to comment.