File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,11 @@ def test_truthiness(self):
138
138
test_program .clear ()
139
139
self .assertEqual (bool (test_program ), True )
140
140
141
+ def test_hex (self ):
142
+ test_program = TIEntry .open ("tests/data/var/Program.8xp" )
143
+ self .assertEqual (f"{ test_program } " , "setDate(1" )
144
+ self .assertEqual (f"{ test_program :-2X:} " , "0300:EF00:31" )
145
+
141
146
142
147
class TokenizationTests (unittest .TestCase ):
143
148
def test_load_from_file (self ):
Original file line number Diff line number Diff line change @@ -431,19 +431,24 @@ def __format__(self, format_spec: str) -> str:
431
431
:return: A string representation of this entry
432
432
"""
433
433
434
- if match := re .fullmatch (r"(?P<sep>\D )?(?P<width>\d+)?x " , format_spec ):
434
+ if match := re .fullmatch (r"(?P<width>[+-]?\d+ )?(?P<case>[xX])(?P<sep>\D)? " , format_spec ):
435
435
match match ["sep" ], match ["width" ]:
436
436
case None , None :
437
- return self .calc_data .hex ()
437
+ string = self .calc_data .hex ()
438
438
439
439
case sep , None :
440
- return self .calc_data .hex (sep )
440
+ string = self .calc_data .hex (sep )
441
441
442
442
case None , width :
443
- return self .calc_data .hex (" " , int (width ))
443
+ string = self .calc_data .hex (" " , int (width ))
444
444
445
445
case sep , width :
446
- return self .calc_data .hex (sep , int (width ))
446
+ string = self .calc_data .hex (sep , int (width ))
447
+
448
+ return string if match ["case" ] == "x" else string .upper ()
449
+
450
+ elif not format_spec :
451
+ return super ().__str__ ()
447
452
448
453
else :
449
454
raise TypeError (f"unsupported format string passed to { type (self )} .__format__" )
You can’t perform that action at this time.
0 commit comments