def test_cas01(self): # create cas source_filepath = self._src_file_path("LineNumberTest.bas") cas_file = self._get_named_temp_file( prefix="test_cas01", suffix=".cas", delete=False ) convert(source_filepath, cas_file.name, self.cfg) # create bas from created cas file destination_filepath = self._dst_file_path("unittest_cas01.bas") convert(cas_file.name, destination_filepath, self.cfg) # filename 'LINENUMB' used in CSAVE: destination_filepath = self._dst_file_path("unittest_cas01_LINENUMB.bas") dest_content = self._get_and_delete_dst(destination_filepath) self.assertMultiLineEqual(dest_content, ( '1 PRINT "LINE NUMBER TEST"\n' '10 PRINT 10\n' '100 PRINT 100\n' '1000 PRINT 1000\n' '10000 PRINT 10000\n' '32768 PRINT 32768\n' '63999 PRINT "END";63999\n' ))
def test_bas2cas01(self): # create cas source_filepath = self._src_file_path("HelloWorld1.bas") destination_filepath = self._dst_file_path("unittest_HelloWorld1.cas") cfg = configs.Dragon32Config() cfg.LEAD_BYTE_LEN = 35 convert(source_filepath, destination_filepath, cfg) dest_content = self._get_and_delete_dst(destination_filepath) # print repr(dest_content) cas = ( ("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "35x Leadin bytes 0x55"), ("<", "Sync byte 0x3C"), ("\x00", "block type: filename block (0x00)"), ("\x0b", "block length (11Bytes)"), ("HELLOWOR", "filename"), ("\x00", "File type: BASIC programm (0x00)"), ("\xff", "format: ASCII BASIC (0xff)"), ("\xff", "gap flag (00=no gaps, FF=gaps)"), ("u", "block checksum"), ("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "35x Leadin bytes 0x55"), ("<", "Sync byte 0x3C"), ("\x01", "block type: data block (0x01)"), ("8", "block length 0x38 (56Bytes)"), ( '\r10 FOR I = 1 TO 10\r20 PRINT I;"HELLO WORLD!"\r30 NEXT I\r', "Basic code in ASCII format" ), ("\x8f", "block checksum"), ("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "35x Leadin bytes 0x55"), ("<", "Sync byte 0x3C"), ("\xff", "block type: end-of-file block (0xff)"), ("\x00", "block length (0Bytes)"), ("\xff", "block checksum"), ) dest_content = iter(dest_content) for no, data in enumerate(cas): part, desc = data part_len = len(part) dest_part = "".join(tuple(itertools.islice(dest_content, part_len))) self.assertEqual(part, dest_part, msg="Error in part %i '%s': %s != %s" % (no, desc, repr(part), repr(dest_part)) )
def test_wav2bas02(self): source_filepath = self._src_file_path("HelloWorld1 origin.wav") destination_filepath = self._dst_file_path("unittest_wav2bas02.bas") convert(source_filepath, destination_filepath, self.cfg) # no filename used in CSAVE: destination_filepath = self._dst_file_path("unittest_wav2bas02_.bas") dest_content = self._get_and_delete_dst(destination_filepath) self.assertEqual(dest_content, ( '10 FOR I = 1 TO 10\n' '20 PRINT I;"HELLO WORLD!"\n' '30 NEXT I\n' ))
def test_case_convert02(self): """ lowercase from .bas to UPPERCASE .cas """ source = self._get_named_temp_file(suffix=".bas", delete=False) source.write('10 print "lowercase?"') source.close() dest = self._get_named_temp_file(suffix=".cas", delete=False) dest.close() cfg = configs.Dragon32Config() cfg.case_convert = True convert(source.name, dest.name, cfg) dest_content = self._get_and_delete_dst(dest.name) dest_content = dest_content.replace("U", "") # "remove" LeadInByte self.assertIn('\r10 PRINT "LOWERCASE?"\r' , dest_content)
def test_wav2bas04(self): source_filepath = self._src_file_path("LineNumber Test 02.wav") destination_filepath = self._dst_file_path("unittest_wav2bas03.bas") convert(source_filepath, destination_filepath, self.cfg) # filename 'LINENO02' used in CSAVE: destination_filepath = self._dst_file_path("unittest_wav2bas03_LINENO02.bas") dest_content = self._get_and_delete_dst(destination_filepath) self.assertEqual(dest_content, ( '1 PRINT "LINE NUMBER TEST"\n' '10 PRINT 10\n' '100 PRINT 100\n' '1000 PRINT 1000\n' '10000 PRINT 10000\n' '32768 PRINT 32768\n' '63999 PRINT "END";63999\n' ))
def test_case_convert01(self): """ UPPERCASE from wave to lowercase .bas """ source_filepath = self._src_file_path("HelloWorld1 xroar.wav") destination_filepath = self._dst_file_path("unittest_case_convert01.bas") cfg = configs.Dragon32Config() cfg.case_convert = True convert(source_filepath, destination_filepath, cfg) # no filename used in CSAVE: destination_filepath = self._dst_file_path("unittest_case_convert01_.bas") dest_content = self._get_and_delete_dst(destination_filepath) lowcase_content = ( '10 for i = 1 to 10\n' '20 print i;"hello world!"\n' '30 next i\n' ) self.assertMultiLineEqual(dest_content, lowcase_content)
def test_bas2ascii_wav(self): # create wav source_filepath = self._src_file_path("HelloWorld1.bas") destination_filepath = self._dst_file_path("unittest_HelloWorld1.wav") cfg = configs.Dragon32Config() cfg.LEAD_BYTE_LEN = 128 convert(source_filepath, destination_filepath, cfg) # read wave and compare source_filepath = self._dst_file_path("unittest_HelloWorld1.wav") destination_filepath = self._dst_file_path("unittest_bas2ascii_wav.bas") convert(source_filepath, destination_filepath, self.cfg) # filename 'HELLOWOR' used in CSAVE: destination_filepath = self._dst_file_path("unittest_bas2ascii_wav_HELLOWOR.bas") dest_content = self._get_and_delete_dst(destination_filepath) self.assertEqual(dest_content, ( '10 FOR I = 1 TO 10\n' '20 PRINT I;"HELLO WORLD!"\n' '30 NEXT I\n' ))