Example #1
0
def create_tree_with_topological_ordering():
    return SyntaxTree(
        Node("ns").insert(
            Node("S0"),
            Node("A0").insert(
                Node("R0").insert(refs.TypeReference("ns.A1")),
                Node("R1").insert(refs.TypeReference("ns.S0"))), Node("A1")))
Example #2
0
def test_insertion_returns_self():
    n = Node("n")
    assert_equal(n, n.insert(Node("S")))
Example #3
0
def test_reparanting_of_symbol_trows():
    n = Node("foo")
    s = Node("Baz")
    n.insert(s)
    a = Node("bar")
    assert_raises(RuntimeError, a.insert, s)
Example #4
0
def test_nodes_are_named():
    v = Node(name="abc")
    assert_equal("abc", v.name)
Example #5
0
def test_get_with_default_returns_default_if_not_found():
    n = Node("foo")
    s = Node("Bar")
    n.insert(s)
    assert_is_none(n.get("foo.Baz", None))
Example #6
0
def test_path_of_detached_node_is_just_its_name():
    root = Node("foo")
    assert_equal("foo", root.path)
Example #7
0
def create_tree_with_cycle():
    return SyntaxTree(
        Node("a").insert(
            Node("b").insert(Structure("c").insert(refs.TypeReference("a.d"))),
            Node("d").insert(refs.TypeReference("a.b"))))
Example #8
0
def create_basic_tree():
    return SyntaxTree(
        Node("a").insert(
            Node("b").insert(Node("c"), Node("d"), Node("e")),
            Node("f").insert(Node("g").insert(Node("h")))))
Example #9
0
def test_insertion_works_with_lookup():
    n = Node("foo")
    s = Node("Bar")
    n.insert(s)
    assert_equal("Bar", n.find("foo.Bar").name)
Example #10
0
def test_set_name_resets_the_node_name():
    n = Node("foo")
    n.set_name("bar")
    assert_equal("bar", n.name)
Example #11
0
def test_find_child_throws_if_not_found():
    n = Node("foo")
    assert_raises(RuntimeError, n.find_relative, "Bar")
Example #12
0
def test_find_child_returns_child_if_found():
    n = Node("foo")
    s = Node("Bar")
    n.insert(s)
    assert_equal("Bar", n.find_relative("Bar").name)
Example #13
0
def test_insertion_returns_parent_node():
    n = Node("foo")
    assert_equal(n, n.insert(Node("Bar")))
Example #14
0
def test_path_contains_fully_path_with():
    root = Node("foo")
    s = Node("Dig")
    root.insert(Node("bar").insert(Node("baz").insert(s)))
    assert_equal("foo.bar.baz.Dig", s.path)
Example #15
0
def test_lookup_by_path():
    root = Node("foo")
    root.insert(Node("bar").insert(Node("baz").insert(Node("Dig"))))
    assert_equal("Dig", root.find("foo.bar.baz.Dig").name)
Example #16
0
def test_node_is_looked_up_by_its_path():
    root = Node("foo")
    s = Node("Dig")
    root.insert(Node("bar").insert(Node("baz").insert(s)))
    assert_equal(s, root.find(s.path))
Example #17
0
def test_lookup_of_nonexistent_symbol_throws():
    n = Node("foo")
    s = Node("Bar")
    n.insert(s)
    assert_raises(RuntimeError, n.find, "baz")
Example #18
0
def create_tree_with_type_refs():
    return SyntaxTree(
        Node("a").insert(
            Node("b").insert(Node("d"), refs.TypeReference("a.c.e")),
            Node("c").insert(Node("e"), refs.TypeReference("a.b.d"))))
Example #19
0
def test_insertion_of_symbol_with_duplicate_name_trows():
    n = Node("foo")
    s = Node("Bar")
    n.insert(s)
    assert_raises(SymbolRedefinition, n.insert, Node("Bar"))
Example #20
0
def test_get_with_default_returns_value_if_found():
    n = Node("foo")
    s = Node("Bar")
    n.insert(s)
    assert_equal(s, n.get("foo.Bar", None))
Example #21
0
def test_children_returns_children():
    n = Node("foo")
    s = Node("Bar")
    n.insert(s)
    assert_equal([s], n.children)