@@ -348,3 +348,44 @@ def test_sublime_configgen_with_registers(self):
348
348
self .assertIsFile (package_fp )
349
349
350
350
shutil .rmtree (test_destination_dir )
351
+
352
+ def test_sublime_escaping_of_names (self ):
353
+ # goal of this test is to ensure that entity names sourced from the ISA config are properly escaped
354
+ # in the generated language configuration files, notablye the syntax highlighting configuration file.
355
+ # for example, if an instruction mnemonic is 'ad.r', the generated regex should be '\\bad\\.r\\b'
356
+ # where the '.' is escaped to '\.' and the whole string is wrapped in '\\b' to ensure it is a word boundary.
357
+ test_destination_dir = tempfile .mkdtemp ()
358
+ test_tmp_dir = tempfile .mkdtemp ()
359
+ config_file = pkg_resources .files (config_files ).joinpath ('test_instructions_with_periods.yaml' )
360
+ configgen = SublimeConfigGenerator (
361
+ str (config_file ),
362
+ 0 ,
363
+ str (test_destination_dir ),
364
+ None ,
365
+ None ,
366
+ 'asmtest' ,
367
+ )
368
+ self .assertEqual (configgen .model .isa_name , 'test_instructions_with_periods' , 'name should be in ISA config' )
369
+ # generate the files to inspect their content
370
+ configgen ._generate_files_in_dir (test_tmp_dir )
371
+
372
+ syntax_fp = os .path .join (test_tmp_dir , 'test_instructions_with_periods.sublime-syntax' )
373
+ self .assertIsFile (syntax_fp )
374
+ with open (syntax_fp ) as yaml_file :
375
+ syntax_dict = yaml .safe_load (yaml_file )
376
+
377
+ for instr_dict in syntax_dict ['contexts' ]['instructions' ]:
378
+ if instr_dict ['scope' ] == 'variable.function.instruction' :
379
+ self ._assert_grouped_item_list (
380
+ instr_dict ['match' ],
381
+ [
382
+ '\\ bnop\\ b' ,
383
+ '\\ bma\\ .hl\\ b' , # note the escaped '.'
384
+ ],
385
+ 'instructions'
386
+ )
387
+ elif instr_dict ['scope' ] == 'variable.function.macro' :
388
+ self .fail ('There should be no macros defined in this list' )
389
+
390
+ # clean up
391
+ shutil .rmtree (test_tmp_dir )
0 commit comments