def test_error_on_self_cycle(self): ir = _parse_snippet("struct Foo:\n" " 0 [+field1] UInt field1\n") struct = ir.module[0].type[0].structure self.assertEqual([[ error.error("m.emb", struct.field[0].source_location, "Dependency cycle\nfield1") ]], dependency_checker.find_dependency_cycles(ir))
def test_error_on_simple_enum_value_cycle(self): ir = _parse_snippet("enum Foo:\n" " XX = YY\n" " YY = XX\n") enum = ir.module[0].type[0].enumeration self.assertEqual([[ error.error("m.emb", enum.value[0].source_location, "Dependency cycle\nXX"), error.note("m.emb", enum.value[1].source_location, "YY") ]], dependency_checker.find_dependency_cycles(ir))
def test_error_on_virtual_field_cycle(self): ir = _parse_snippet("struct Foo:\n" " let x = y\n" " let y = x\n") struct = ir.module[0].type[0].structure self.assertEqual([[ error.error("m.emb", struct.field[0].source_location, "Dependency cycle\nx"), error.note("m.emb", struct.field[1].source_location, "y") ]], dependency_checker.find_dependency_cycles(ir))
def test_error_on_cycle_involving_subfield(self): ir = _parse_snippet("struct Bar:\n" " foo_b.x [+4] Foo foo_a\n" " foo_a.x [+4] Foo foo_b\n" "struct Foo:\n" " 0 [+4] UInt x\n") struct = ir.module[0].type[0].structure self.assertEqual([[ error.error("m.emb", struct.field[0].source_location, "Dependency cycle\nfoo_a"), error.note("m.emb", struct.field[1].source_location, "foo_b") ]], dependency_checker.find_dependency_cycles(ir))
def test_error_on_field_existence_cycle(self): ir = _parse_snippet("struct Foo:\n" " if y == 1:\n" " 0 [+1] UInt x\n" " if x == 0:\n" " 1 [+1] UInt y\n") struct = ir.module[0].type[0].structure self.assertEqual([[ error.error("m.emb", struct.field[0].source_location, "Dependency cycle\nx"), error.note("m.emb", struct.field[1].source_location, "y") ]], dependency_checker.find_dependency_cycles(ir))
def test_error_on_complex_field_cycle(self): ir = _parse_snippet("struct Foo:\n" " 0 [+field2] UInt field1\n" " 0 [+field3+field4] UInt field2\n" " 0 [+field1] UInt field3\n" " 0 [+field2] UInt field4\n") struct = ir.module[0].type[0].structure self.assertEqual([[ error.error("m.emb", struct.field[0].source_location, "Dependency cycle\nfield1"), error.note("m.emb", struct.field[1].source_location, "field2"), error.note("m.emb", struct.field[2].source_location, "field3"), error.note("m.emb", struct.field[3].source_location, "field4"), ]], dependency_checker.find_dependency_cycles(ir))
def test_error_on_import_cycle(self): ir, unused_debug_info, errors = glue.parse_emboss_file( "m.emb", test_util.dict_file_reader({ "m.emb": 'import "n.emb" as n\n', "n.emb": 'import "m.emb" as m\n' }), stop_before_step="find_dependency_cycles") assert not errors self.assertEqual([[ error.error("m.emb", ir.module[0].source_location, "Import dependency cycle\nm.emb"), error.note("n.emb", ir.module[2].source_location, "n.emb") ]], dependency_checker.find_dependency_cycles(ir))
def test_error_on_import_cycle_and_field_cycle(self): ir, unused_debug_info, errors = glue.parse_emboss_file( "m.emb", test_util.dict_file_reader({ "m.emb": 'import "n.emb" as n\n' "struct Foo:\n" " 0 [+field1] UInt field1\n", "n.emb": 'import "m.emb" as m\n' }), stop_before_step="find_dependency_cycles") assert not errors struct = ir.module[0].type[0].structure self.assertEqual( [[ error.error("m.emb", ir.module[0].source_location, "Import dependency cycle\nm.emb"), error.note("n.emb", ir.module[2].source_location, "n.emb") ], [ error.error("m.emb", struct.field[0].source_location, "Dependency cycle\nfield1") ]], dependency_checker.find_dependency_cycles(ir))
def test_no_error_on_no_cycle(self): ir = _parse_snippet("enum Foo:\n" " XX = 0\n" " YY = XX\n") self.assertEqual([], dependency_checker.find_dependency_cycles(ir))