Beispiel #1
0
def test_archive_member_schemas_references_dependent_types():
    root = _build_node_tree("""namespace n{
        struct T { t : u8 : 7; }
        struct U { u : u8 : 7; }
        struct V { v : u8 : 7; }
        archive A {
            a : T;
            b : vector< V >;
            c : multivector< 17, U, V >;
        }
        }
        """)
    resolve_references(root)
    assert_equal(
        SyntaxTree.schema(root.find(".n.A.a")),
        "namespace n { struct T { t : u8 : 7; } }\n"
        "namespace n { a : T; }")
    assert_equal(
        SyntaxTree.schema(root.find(".n.A.b")),
        "namespace n { struct V { v : u8 : 7; } }\n"
        "namespace n { b : vector< V >; }")
    assert_equal(
        SyntaxTree.schema(root.find(".n.A.c")),
        "namespace n { struct U { u : u8 : 7; } }\n"
        "namespace n { struct V { v : u8 : 7; } }\n"
        "namespace n { c : multivector< 17, U, V >; }")
Beispiel #2
0
def test_archive_schema_preserves_references():
    root = _build_node_tree("""namespace foo{
/// T Comment
struct T { /* fieldA comment*/ fieldA : u8 : 7; }
/**
 * Archive comment
 */
archive A {
    /// resource comment
    resourceA : T;
}
}
        """)
    resolve_references(root)
    expected = """namespace foo {
struct T
{
    fieldA : u8 : 7;
}
}

namespace foo {
archive A
{
    resourceA : .foo.T;
}
}

"""
    assert_equal(SyntaxTree.schema(root.find(".foo.A")), expected)
Beispiel #3
0
def test_archive_schemas_include_constants():
    root = build_ast("""namespace foo{
const u8 C = 42;
struct T { f : u8 : 7; }
archive A {
    resourceA : T;
}
}
        """)
    resolve_references(root)
    expected = """namespace foo {
struct T
{
    f : u8 : 7;
}
}

namespace foo {
const u8 C = 42;
}

namespace foo {
archive A
{
    resourceA : .foo.T;
}
}

"""
    actual = SyntaxTree.schema(root.find(".foo.A"))
    assert_equal(actual, expected)
Beispiel #4
0
def test_schemas_are_not_duplicated_if_several_type_references_occur():
    root = _build_node_tree("""namespace foo{
/// T Comment
struct T { /* fieldA comment*/ fieldA : u8 : 7; }
/**
 * Archive comment
 */
archive A {
    resourceA : T;
    resourceB : T;
}
}
        """)
    resolve_references(root)
    expected = """namespace foo {
struct T
{
    fieldA : u8 : 7;
}
}

namespace foo {
archive A
{
    resourceA : .foo.T;
    resourceB : .foo.T;
}
}

"""
    actual = SyntaxTree.schema(root.find(".foo.A"))
    assert_equal(actual, expected)