コード例 #1
0
ファイル: test_syntaxtree.py プロジェクト: jecki/DHParser
    def test_deepcopy(self):
        tree = RootNode(parse_sxpr('(a (b c) (d (e f) (h i)))'))
        tree.with_pos(0)
        tree_copy = copy.deepcopy(tree)

        assert tree.equals(tree_copy)
        assert tree.as_sxpr() == parse_sxpr(
            '(a (b c) (d (e f) (h i)))').as_sxpr()
        assert tree_copy.as_sxpr() == parse_sxpr(
            '(a (b c) (d (e f) (h i)))').as_sxpr()

        tree.add_error(tree, Error('Test Error', 0))
        assert not tree_copy.errors
        assert tree.as_sxpr() != parse_sxpr(
            '(a (b c) (d (e f) (h i)))').as_sxpr()
        assert tree_copy.as_sxpr() == parse_sxpr(
            '(a (b c) (d (e f) (h i)))').as_sxpr()

        tree['d'].result = "x"
        assert not tree.equals(tree_copy)
        assert tree_copy.equals(parse_sxpr('(a (b c) (d (e f) (h i)))'))
        #print(tree.as_sxpr())
        #print(tree.attr)
        assert tree.equals(parse_sxpr('(a (b c) (d x))'))

        # this also checks for errors equality...
        assert parse_sxpr('(a (b c) (d x))').as_sxpr() != tree.as_sxpr()
コード例 #2
0
ファイル: test_syntaxtree.py プロジェクト: jecki/DHParser
 def test_copy_errors(self):
     tree = RootNode(parse_sxpr('(A (B "1") (C "2"))').with_pos(0))
     tree.add_error(tree['C'], Error('error', 1))
     tree.add_error(None, Error('unspecific error', 2))
     save = tree.as_sxpr()
     tree_copy = copy.deepcopy(tree)
     compare = tree_copy.as_sxpr()
     assert compare == save  # is the error message still included?