@@ -371,6 +371,88 @@ def test_annotate(self):
371371highest protocol among opcodes = 0
372372''' , annotate = 20 )
373373
374+ def test_string (self ):
375+ self .check_dis (b"S'abc'\n ." , '''\
376+ 0: S STRING 'abc'
377+ 7: . STOP
378+ highest protocol among opcodes = 0
379+ ''' )
380+ self .check_dis (b'S"abc"\n .' , '''\
381+ 0: S STRING 'abc'
382+ 7: . STOP
383+ highest protocol among opcodes = 0
384+ ''' )
385+ self .check_dis (b"S'\xc3 \xb5 '\n ." , '''\
386+ 0: S STRING '\\ xc3\\ xb5'
387+ 6: . STOP
388+ highest protocol among opcodes = 0
389+ ''' )
390+
391+ def test_string_without_quotes (self ):
392+ self .check_dis_error (b"Sabc'\n ." , '' ,
393+ 'no string quotes around b"abc\' "' )
394+ self .check_dis_error (b'Sabc"\n .' , '' ,
395+ "no string quotes around b'abc\" '" )
396+ self .check_dis_error (b"S'abc\n ." , '' ,
397+ '''strinq quote b"'" not found at both ends of b"'abc"''' )
398+ self .check_dis_error (b'S"abc\n .' , '' ,
399+ r"""strinq quote b'"' not found at both ends of b'"abc'""" )
400+ self .check_dis_error (b"S'abc\" \n ." , '' ,
401+ r"""strinq quote b"'" not found at both ends of b'\\'abc"'""" )
402+ self .check_dis_error (b"S\" abc'\n ." , '' ,
403+ r"""strinq quote b'"' not found at both ends of b'"abc\\''""" )
404+
405+ def test_binstring (self ):
406+ self .check_dis (b"T\x03 \x00 \x00 \x00 abc." , '''\
407+ 0: T BINSTRING 'abc'
408+ 8: . STOP
409+ highest protocol among opcodes = 1
410+ ''' )
411+ self .check_dis (b"T\x02 \x00 \x00 \x00 \xc3 \xb5 ." , '''\
412+ 0: T BINSTRING '\\ xc3\\ xb5'
413+ 7: . STOP
414+ highest protocol among opcodes = 1
415+ ''' )
416+
417+ def test_short_binstring (self ):
418+ self .check_dis (b"U\x03 abc." , '''\
419+ 0: U SHORT_BINSTRING 'abc'
420+ 5: . STOP
421+ highest protocol among opcodes = 1
422+ ''' )
423+ self .check_dis (b"U\x02 \xc3 \xb5 ." , '''\
424+ 0: U SHORT_BINSTRING '\\ xc3\\ xb5'
425+ 4: . STOP
426+ highest protocol among opcodes = 1
427+ ''' )
428+
429+ def test_global (self ):
430+ self .check_dis (b"cmodule\n name\n ." , '''\
431+ 0: c GLOBAL 'module name'
432+ 13: . STOP
433+ highest protocol among opcodes = 0
434+ ''' )
435+ self .check_dis (b"cm\xc3 \xb6 dule\n n\xc3 \xa4 me\n ." , '''\
436+ 0: c GLOBAL 'm\xf6 dule n\xe4 me'
437+ 15: . STOP
438+ highest protocol among opcodes = 0
439+ ''' )
440+
441+ def test_inst (self ):
442+ self .check_dis (b"(imodule\n name\n ." , '''\
443+ 0: ( MARK
444+ 1: i INST 'module name' (MARK at 0)
445+ 14: . STOP
446+ highest protocol among opcodes = 0
447+ ''' )
448+
449+ def test_persid (self ):
450+ self .check_dis (b"Pabc\n ." , '''\
451+ 0: P PERSID 'abc'
452+ 5: . STOP
453+ highest protocol among opcodes = 0
454+ ''' )
455+
374456
375457class MiscTestCase (unittest .TestCase ):
376458 def test__all__ (self ):
0 commit comments