def _link_binding(self): compiler = Compiler(self.root, self.source) module_obj = compiler.compile(self.module) binding_obj = compiler.compile(self.binding) linker = Linker(self.root) linked_binding = linker.link(self.binding, { self.binding: binding_obj, self.module: module_obj, }, compiler) return linked_binding
def test_compile_Trefvs(self): file = self.write_text(r'\Trefvs[target]{v}{a}{l}{u}{e}') compiler = Compiler(self.root, self.source) obj = compiler.compile(file) self.assertEqual(obj.diagnostics.diagnostics, []) self.assertTupleEqual(('target', ), obj.references[0].name) self.assertTupleEqual(('target', 'v-a-l-u-e'), obj.references[1].name)
def test_compile_defi_name_oarg(self): file = self.write_binding( r'\adefv[name=value]{ignored}{this}{value}{will}{be}{ignored}') compiler = Compiler(self.root, self.source) obj = compiler.compile(file) self.assertEqual(len(obj.references), 2) self.assertEqual(obj.references[0].name, (self.module_name, )) self.assertEqual(obj.references[1].name, (self.module_name, 'value'))
def test_compile_trefi(self): file = self.write_binding(r'\trefi{value}') compiler = Compiler(self.root, self.source) obj = compiler.compile(file) self.assertEqual(obj.diagnostics.diagnostics, []) self.assertEqual(len(obj.references), 2) self.assertTupleEqual((self.module_name, ), obj.references[0].name) self.assertTupleEqual((self.module_name, 'value'), obj.references[1].name)
def test_compile_aDefiiis(self): file = self.write_binding( r'\aDefiiis{this value is ignored}{actual}{defi}{value}') compiler = Compiler(self.root, self.source) obj = compiler.compile(file) self.assertEqual(len(obj.references), 2) self.assertEqual(obj.references[0].name, (self.module_name, )) self.assertEqual(obj.references[1].name, (self.module_name, 'actual-defi-value')) self.assertListEqual(obj.diagnostics.diagnostics, [])
def test_compile_atrefiii(self): file = self.write_text( r'\atrefiii[target]{this value is ignored}{a}{referenced}{value}') compiler = Compiler(self.root, self.source) obj = compiler.compile(file) self.assertEqual(len(obj.references), 2) self.assertTupleEqual(('target', ), obj.references[0].name) self.assertTupleEqual(('target', 'a-referenced-value'), obj.references[1].name) self.assertEqual(obj.diagnostics.diagnostics, [])
def test_compile_mTrefiv(self): file = self.write_text( r'\mTrefiv[target?value]{ignored}{by}{optional}{arguments}') compiler = Compiler(self.root, self.source) obj = compiler.compile(file) self.assertEqual(len(obj.references), 2) self.assertTupleEqual(('target', ), obj.references[0].name) self.assertTupleEqual(('target', 'value'), obj.references[1].name) self.assertEqual(len(obj.diagnostics.diagnostics), 1) self.assertEqual(obj.diagnostics.diagnostics[0].code, DiagnosticCodeName.MTREF_DEPRECATION_CHECK.value)
def test_compile_defi(self): file = self.write_binding(r'\defi{value}') compiler = Compiler(self.root, self.source) obj = compiler.compile(file) self.assertEqual(len(obj.references), 2) self.assertEqual(obj.references[0].name, (self.module_name, )) self.assertEqual(obj.references[1].name, (self.module_name, 'value')) self.assertEqual(len(obj.dependencies), 1) self.assertEqual(obj.dependencies[0].module_name, self.module_name) self.assertEqual(obj.dependencies[0].module_type_hint, ModuleType.MODSIG) self.assertEqual(len(obj.symbol_table.children), 1) self.assertEqual(obj.symbol_table.children[self.module_name][0].name, self.module_name) self.assertListEqual(obj.diagnostics.diagnostics, [])
def test_compile_mhmodnl(self): file = self.write_binding('') compiler = Compiler(self.root, self.source) obj = compiler.compile(file) self.assertEqual(obj.diagnostics.diagnostics, []) self.assertEqual(len(obj.references), 1) self.assertTupleEqual((self.module_name, ), obj.references[0].name) self.assertEqual(len(obj.dependencies), 1) self.assertEqual(obj.dependencies[0].module_name, self.module_name) self.assertEqual(obj.dependencies[0].module_type_hint, ModuleType.MODSIG) self.assertEqual(len(obj.symbol_table.children), 1) self.assertEqual(len(obj.symbol_table.children[self.module_name]), 1) module = obj.symbol_table.children[self.module_name][0] self.assertTupleEqual((self.module_name, ), module.qualified)
def test_missing_dependency(self): self.write_binding(r''' Reference symi: \trefi{value} Define symi: \defi{value}''') compiler = Compiler(self.root, self.source) binding_obj = compiler.compile(self.binding) linker = Linker(self.root) linked_binding = linker.link( self.binding, { self.binding: binding_obj, # self.module: module_obj, # Do not include module }, compiler) file_not_found, = linked_binding.diagnostics.diagnostics self.assertEqual(DiagnosticCodeName.FILE_NOT_FOUND.value, file_not_found.code) self.assertIn(str(self.module), file_not_found.message)