<commit_before>from redux.parser import parse
from nose.tools import eq_
from redux.ast import *


def test_valid_parses():
    valid_parses = [
        ("a = 1", Block([Assignment(VarRef("a"), Constant(1))])),
        ("a = \"abc\"", Block([Assignment(VarRef("a"), Constant("abc"))])),
        ("a = a + b", Block([Assignment(VarRef("a"), AddOp(VarRef("a"), VarRef("b")))])),
        ("a = f()", Block([Assignment(VarRef("a"), FunctionCall("f", []))])),
        ("a = f(1, 2)", Block([Assignment(VarRef("a"), FunctionCall("f", [Constant(1), Constant(2)]))])),
        ("if a == 0 end", Block([IfStmt(EqualToOp(VarRef("a"), Constant(0)), Block([]))])),
        ("if a == 0 else end", Block([IfStmt(EqualToOp(VarRef("a"), Constant(0)), Block([]), Block([]))])),
        ("if a == 0 elif b == 0 else end", Block([IfStmt(EqualToOp(VarRef('a'), Constant(0)), Block([]), Block([IfStmt(EqualToOp(VarRef('b'), Constant(0)), Block([]), Block([]))]))])),
        ("`PERFORM RAND;`", Block([CodeLiteral("PERFORM RAND;")])),
        ("while a > 0 end", Block([WhileStmt(GreaterThanOp(VarRef("a"), Constant(0)), Block([]))])),
        ("break", Block([BreakStmt()])),
        ("def f() return 1 end", Block([FunctionDefinition("f", [], Block([ReturnStmt(Constant(1))]))])),
        ("def f(a, b) end", Block([FunctionDefinition("f", ["a", "b"], Block([]))])),
        ("a = (b)", Block([Assignment(VarRef("a"), VarRef("b"))])),
        ("bitfield A x : 8 y : 8 end", Block([BitfieldDefinition("A", [("x", 8), ("y", 8)])])),
    ]

    for code, ast_ in valid_parses:
        yield check_valid_parse, code, ast_


def check_valid_parse(code, ast_):
    compiled_ast, errors = parse(code)
    assert not errors<commit_msg>Add test for parsing logical not<commit_after>from redux.parser import parse
from nose.tools import eq_
from redux.ast import *


def test_valid_parses():
    valid_parses = [
        ("a = 1", Block([Assignment(VarRef("a"), Constant(1))])),
        ("a = \"abc\"", Block([Assignment(VarRef("a"), Constant("abc"))])),
        ("a = a + b", Block([Assignment(VarRef("a"), AddOp(VarRef("a"), VarRef("b")))])),
        ("a = f()", Block([Assignment(VarRef("a"), FunctionCall("f", []))])),
        ("a = f(1, 2)", Block([Assignment(VarRef("a"), FunctionCall("f", [Constant(1), Constant(2)]))])),
        ("if a == 0 end", Block([IfStmt(EqualToOp(VarRef("a"), Constant(0)), Block([]))])),
        ("if a == 0 else end", Block([IfStmt(EqualToOp(VarRef("a"), Constant(0)), Block([]), Block([]))])),
        ("if a == 0 elif b == 0 else end", Block([IfStmt(EqualToOp(VarRef('a'), Constant(0)), Block([]), Block([IfStmt(EqualToOp(VarRef('b'), Constant(0)), Block([]), Block([]))]))])),
        ("`PERFORM RAND;`", Block([CodeLiteral("PERFORM RAND;")])),
        ("while a > 0 end", Block([WhileStmt(GreaterThanOp(VarRef("a"), Constant(0)), Block([]))])),
        ("break", Block([BreakStmt()])),
        ("def f() return 1 end", Block([FunctionDefinition("f", [], Block([ReturnStmt(Constant(1))]))])),
        ("def f(a, b) end", Block([FunctionDefinition("f", ["a", "b"], Block([]))])),
        ("a = (b)", Block([Assignment(VarRef("a"), VarRef("b"))])),
        ("bitfield A x : 8 y : 8 end", Block([BitfieldDefinition("A", [("x", 8), ("y", 8)])])),
        ("a = not a", Block([Assignment(VarRef("a"), LogicalNotOp(VarRef("a")))])),
    ]

    for code, ast_ in valid_parses:
        yield check_valid_parse, code, ast_


def check_valid_parse(code, ast_):
    compiled_ast, errors = parse(code)
    assert not errors
{'fraction_non_alphanumeric': 0.2608695652173913, 'fraction_numerical': 0.01250355214549588, 'mean_word_length': 4.5, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2941534', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1204, 'n_words': 273}