Esempio n. 1
0
 def testFilterProperties(self):
     node = Node()
     node.properties['k1'] = 'v1'
     node.properties['k2'] = 'v2'
     self.assertTrue(any(xpath_filter(node, "/*[@k1='v1']")))
     self.assertTrue(any(xpath_filter(node, "/*[@k2='v2']")))
     self.assertFalse(any(xpath_filter(node, "/*[@k1='v2']")))
Esempio n. 2
0
 def testChildrenFile(self):
     root = self._parse_fixture().uast
     self.assertEqual(len(root.children), 10)
     n = Node()
     n.internal_type = 'child_node'
     root.children.append(n)
     self.assertEqual(len(root.children), 11)
     last = root.children[-1]
     self.assertDictEqual(last.get_dict(), n.internal_node)
Esempio n. 3
0
    def testChildren(self):
        n = Node()
        n.internal_type = 'root'
        c1 = {"@type": "child1"}
        n.properties["child1"] = c1
        self.assertDictEqual(n.children[0].get_dict(), c1)

        c2 = {"@type": "child2"}
        n.children.append(c2)
        self.assertDictEqual(n.children[1].get_dict(), c2)
        n.children.append(c2)
        self.assertDictEqual(n.children[2].get_dict(), c2)

        l = [{"@type": "list_child1"}, {"@type": "list_child2"}]
        n.properties["some_list"] = l
        self.assertDictEqual(n.children[3].get_dict(), l[0])
        self.assertDictEqual(n.children[4].get_dict(), l[1])
Esempio n. 4
0
 def testFilterInternalType(self):
     node = Node()
     node.internal_type = 'a'
     self.assertTrue(any(xpath_filter(node, "//a")))
     self.assertFalse(any(xpath_filter(node, "//b")))
Esempio n. 5
0
 def testAddToNode(self):
     n = Node()
     n.internal_node["foo"] = "bar"
     self.assertEqual(n.properties["foo"], "bar")
Esempio n. 6
0
    def _itTestTree():
        root = Node()
        root.internal_type = 'root'
        root.start_position.offset = 0

        son1 = Node()
        son1.internal_type = 'son1'
        son1.start_position.offset = 1

        son1_1 = Node()
        son1_1.internal_type = 'son1_1'
        son1_1.start_position.offset = 10

        son1_2 = Node()
        son1_2.internal_type = 'son1_2'
        son1_2.start_position.offset = 10

        son1.children.extend([son1_1, son1_2])

        son2 = Node()
        son2.internal_type = 'son2'
        son2.start_position.offset = 100

        son2_1 = Node()
        son2_1.internal_type = 'son2_1'
        son2_1.start_position.offset = 5

        son2_2 = Node()
        son2_2.internal_type = 'son2_2'
        son2_2.start_position.offset = 15

        son2.children.extend([son2_1, son2_2])
        root.children.extend([son1, son2])

        return root