def __test(typename, width): tree = _build_node_tree("""namespace n{ struct s { f : %s; } } """ % typename) _compute_structure_sizes(tree) check_field(tree.find('.n.s.f'), typename, width, 0)
def test_single_structure_is_parsed_correctly(): tree = _build_node_tree("""namespace foo{ struct Bar { fieldA : u8 : 2; fieldB : i64 : 33; } } """) _compute_structure_sizes(tree) assert_equal({".foo", ".foo.Bar", ".foo.Bar.fieldB", ".foo.Bar.fieldA"}, tree.symbols()) check_struct(tree.find(".foo.Bar"), 35, 5) check_field(tree.find(".foo.Bar.fieldA"), "u8", 2, 0) check_field(tree.find(".foo.Bar.fieldB"), "i64", 33, 2)
def test_multi_vector_builtin_types_are_correct(): tree = _build_node_tree("""namespace foo{ archive A { resourceA : multivector< 33, T >; } } """) res = tree.find(".foo.A.resourceA") assert_equal(33, res.width) assert_equal(1, len(res.builtins)) index_type = res.builtins[0] _compute_structure_sizes(index_type) assert_equal({"IndexType33", "IndexType33.value"}, index_type.symbols()) check_struct(index_type, 33, 5) check_field(index_type.find("IndexType33.value"), "u64", 33, 0)
def test_two_structures_are_parsed_correctly(): tree = _build_node_tree("""namespace foo{ struct Bar { fieldA : u8 : 2; } struct Baz { fieldB : u32 : 17; } } """) _compute_structure_sizes(tree) assert_equal( {".foo", ".foo.Baz", ".foo.Baz.fieldB", ".foo.Bar", ".foo.Bar.fieldA"}, tree.symbols()) check_struct(tree.find(".foo.Bar"), 2, 1) check_struct(tree.find(".foo.Baz"), 17, 3)
def test_enumeration(): tree = _build_node_tree(""" namespace n { enum A : u16 { VALUE_1, VALUE_2 = 4, VALUE_3, VALUE_4 = 0x10 } struct B { f1 : A; } } """) resolve_references(tree) _update_field_type_references(tree) _compute_structure_sizes(tree) assert_equal( { ".n", ".n.A", ".n.A.VALUE_1", ".n.A.VALUE_2", ".n.A.VALUE_3", ".n.A.VALUE_4", ".n.B", ".n.B.f1", ".n.B.f1.@@n@A" }, tree.symbols()) check_struct(tree.find(".n.B"), 16, 2)