<commit_before>import textwrap

from bagel import ast, parser


class AssertEqualVisitor(object):
    def visit(self, node, arg):
        if node is not arg:
            node.visit(self, arg)

    def _visit_list(self, a1, a2):
        if a1 is not a2:
            assert len(a1) == len(a2)
            for a, b in zip(a1, a2):
                self.visit(a, b)

    def visit_module(self, node1, node2):
        self._visit_list(node1._declarations, node2._declarations)

    def visit_function(self, node1, node2):
        assert node1._name == node2._name
        assert node1._arguments == node2._arguments
        self.visit(node1._return_type, node2._return_type)
        self.visit(node1._body, node2._body)

    def visit_suite(self, node1, node2):
        self._visit_list(node1._body, node2._body)

    def visit_return(self, node1, node2):
        self.visit(node1._value, node2._value)

    def visit_assignment(self, node1, node2):
        self.visit(node1._target, node2._target)
        self.visit(node1._value, node2._value)

    def visit_match(self, node1, node2):
        self.visit(node1._condition, node2._condition)
        self._visit_list(node1._cases, node2._cases)

    def visit_match_case(self, node1, node2):
        self.visit(node1._matcher, node2._matcher)
        self.visit(node1._body, node2._body)

    def visit_class(self, node1, node2):
        assert node1._name == node2._name
        self._visit_list(node1._declarations, node2._declarations)

    def visit_attribute(self, node1, node2):
        assert node1._name == node2._name
        self.visit(node1._tp, node2._tp)

    def visit_enum(self, node1, node2):
        assert node1._name == node2._name
        self._visit_list(node1._cases, node2._cases)

    def visit_enum_case(self, node1, node2):
        assert node1._name == node2._name
        self._visit_list(node1._members, node2._members)

    def visit_name(self, node1, node2):
        assert node1._value == node2._value

    def visit_integer(self, node1, node2):
        assert node1._value == node2._value


def assert_parses(source, expected_ast):
    source = textwrap.dedent(source).lstrip()
    p = parser.Parser()
    actual_ast = p.parse(source)
    AssertEqualVisitor().visit(actual_ast, expected_ast)


class TestParser(object):
    def test_simple_function(self):<commit_msg>Added a test to verify there are no conflicts in the grammar<commit_after>import textwrap

from bagel import ast, parser


class AssertEqualVisitor(object):
    def visit(self, node, arg):
        if node is not arg:
            node.visit(self, arg)

    def _visit_list(self, a1, a2):
        if a1 is not a2:
            assert len(a1) == len(a2)
            for a, b in zip(a1, a2):
                self.visit(a, b)

    def visit_module(self, node1, node2):
        self._visit_list(node1._declarations, node2._declarations)

    def visit_function(self, node1, node2):
        assert node1._name == node2._name
        assert node1._arguments == node2._arguments
        self.visit(node1._return_type, node2._return_type)
        self.visit(node1._body, node2._body)

    def visit_suite(self, node1, node2):
        self._visit_list(node1._body, node2._body)

    def visit_return(self, node1, node2):
        self.visit(node1._value, node2._value)

    def visit_assignment(self, node1, node2):
        self.visit(node1._target, node2._target)
        self.visit(node1._value, node2._value)

    def visit_match(self, node1, node2):
        self.visit(node1._condition, node2._condition)
        self._visit_list(node1._cases, node2._cases)

    def visit_match_case(self, node1, node2):
        self.visit(node1._matcher, node2._matcher)
        self.visit(node1._body, node2._body)

    def visit_class(self, node1, node2):
        assert node1._name == node2._name
        self._visit_list(node1._declarations, node2._declarations)

    def visit_attribute(self, node1, node2):
        assert node1._name == node2._name
        self.visit(node1._tp, node2._tp)

    def visit_enum(self, node1, node2):
        assert node1._name == node2._name
        self._visit_list(node1._cases, node2._cases)

    def visit_enum_case(self, node1, node2):
        assert node1._name == node2._name
        self._visit_list(node1._members, node2._members)

    def visit_name(self, node1, node2):
        assert node1._value == node2._value

    def visit_integer(self, node1, node2):
        assert node1._value == node2._value


def assert_parses(source, expected_ast):
    source = textwrap.dedent(source).lstrip()
    p = parser.Parser()
    actual_ast = p.parse(source)
    AssertEqualVisitor().visit(actual_ast, expected_ast)


class TestParser(object):
    def test_no_conflicts(self):
        assert not parser.Parser._parser.lr_table.sr_conflicts
        assert not parser.Parser._parser.lr_table.rr_conflicts

    def test_simple_function(self):
{'fraction_non_alphanumeric': 0.10680008168266285, 'fraction_numerical': 0.03267306514192363, 'mean_word_length': 2.9659919028340083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3908690', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1597, 'n_words': 340}