<commit_before>import unittest
from autocode.parser import autocode_line

class ParserTest(unittest.TestCase):

    def test_parses_tape_statements(self):
        self.assertTrue(autocode_line.parse('line','TAPE') is not None)
        self.assertTrue(autocode_line.parse('line','n7 = TAPE') is not None)
        self.assertTrue(autocode_line.parse('line','n7 = TAPE n2') is not None)
        self.assertTrue(autocode_line.parse('line','n7 = TAPE *') is not None)
        self.assertTrue(autocode_line.parse('line','v3 = TAPE') is not None)
        self.assertTrue(autocode_line.parse('line','v3 = TAPE n2') is not None)
        self.assertTrue(autocode_line.parse('line','v3 = TAPE *') is not None)
        self.assertTrue(autocode_line.parse('line','n7 = TAPEB') is not None)

    def test_parses_integer_assignments(self):
        self.assertTrue(autocode_line.parse('line','n1 = 5') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = -5') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = n2') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = n2 + 5') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = n2 - 5') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = n2 x 5') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = n2 * 5') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = n2 + n7') is not None)

    def test_parses_print_statements(self):
        self.assertTrue(autocode_line.parse('line','PRINT v7, 4000') is not None)
        self.assertTrue(autocode_line.parse('line','PRINT n3, 4000') is not None)
        self.assertTrue(autocode_line.parse('line','PRINT v7, n3') is not None)
        self.assertTrue(autocode_line.parse('line','PRINT vn7, 3236') is not None)

    def test_parses_variable_assignments(self):
        self.assertTrue(autocode_line.parse('line','v1 = 5.0') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = -5.0') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = 5') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = v3') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = v3 + 5') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = v3 + 5') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = v3 x 5.0') is not None)

    def test_parses_mixed_assignments(self):
        self.assertTrue(autocode_line.parse('line','n1 = v2') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = -v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = n2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = n2/n3') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = 2/n3') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = 2/3') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = n2/3') is not None)


    def test_parses_modification(self):
        self.assertTrue(autocode_line.parse('line','vn7 = 323.6') is not None)
        self.assertTrue(autocode_line.parse('line','v(5+n7) = 323.6') is not None)
        self.assertTrue(autocode_line.parse('line','v(5+n7) = v(-7+n5) + v(3+n2)') is not None)
        self.assertTrue(autocode_line.parse('line','vn7 = vn1 + 323.6') is not None)
        self.assertTrue(autocode_line.parse('line','vn7 = vn1 + vn5') is not None)

    def test_parses_functions(self):
        self.assertTrue(autocode_line.parse('line','v1 = MOD v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = -MOD v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = INT 5.6') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = INT v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = -INT v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = FRAC v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = SQRT v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = SIN v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = COS v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = TAN v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = CSC v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = SEC v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = COT v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = ARCSIN v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = ARCCOS v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = ARCTAN v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = LOG v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = EXP v2') is not None)
        self.assertTrue(autocode_line.parse('line','v1 = EXPM v2') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = MOD n2') is not None)
        self.assertTrue(autocode_line.parse('line','n1 = -MOD n2') is not None)

    def test_parses_stop(self):
        self.assertTrue(autocode_line.parse('line','STOP') is not None)

   # using ^ instead of ->

    def test_parses_jump_instructions(self):
        self.assertTrue(autocode_line.parse('line','^0') is not None)
        self.assertTrue(autocode_line.parse('line','^n1') is not None)
        self.assertTrue(autocode_line.parse('line','^0, v2 > v3') is not None)
        self.assertTrue(autocode_line.parse('line','^0, v2 > 3.0') is not None)
        self.assertTrue(autocode_line.parse('line','^0, -v2 > 3.0') is not None)
        self.assertTrue(autocode_line.parse('line','^0, v2 > -3.0') is not None)
        self.assertTrue(autocode_line.parse('line','^0, n2 > -3') is not None)
        self.assertTrue(autocode_line.parse('line','^0, n2 = -3') is not None)
        self.assertTrue(autocode_line.parse('line','^0, n2 = -3') is not None)
        self.assertTrue(autocode_line.parse('line','^0, n2 = -3') is not None)
        self.assertTrue(autocode_line.parse('line','^0, n2 = -3') is not None)
        self.assertTrue(autocode_line.parse('line','^0, v1 =* v3') is not None)
        self.assertTrue(autocode_line.parse('line','^(-4 +n8), v1 =* v3') is not None)

    def test_processes_print_prefixes(self):
        self.assertTrue(autocode_line.parse('line','XP n1 = MOD n2') is not None)
        self.assertTrue(autocode_line.parse('line','X n1 = MOD n2') is not None)
        self.assertTrue(autocode_line.parse('line','SP n1 = MOD n2') is not None)
        self.assertTrue(autocode_line.parse('line','S n1 = MOD n2') is not None)

    def test_parses_bracketed_interludes(self):
        self.assertTrue(autocode_line.parse('line','(^0)') is not None)
        self.assertTrue(autocode_line.parse('line','^0)') is not None)
        self.assertTrue(autocode_line.parse('line','(v1 = 5.0') is not None)



<commit_msg>Refactored tests.<commit_after>import unittest
from autocode.parser import autocode_line


class ParserTest(unittest.TestCase):
    def try_to_parse(self, statement):
        self.assertTrue(autocode_line.parse('line',statement) is not None, 'cannot parse %s' % statement)

    def test_parses_tape_statements(self):
        self.try_to_parse('TAPE') 
        self.try_to_parse('n7 = TAPE') 
        self.try_to_parse('n7 = TAPE n2') 
        self.try_to_parse('n7 = TAPE *') 
        self.try_to_parse('v3 = TAPE') 
        self.try_to_parse('v3 = TAPE n2') 
        self.try_to_parse('v3 = TAPE *') 
        self.try_to_parse('n7 = TAPEB') 

    def test_parses_integer_assignments(self):
        self.try_to_parse('n1 = 5') 
        self.try_to_parse('n1 = -5') 
        self.try_to_parse('n1 = n2') 
        self.try_to_parse('n1 = n2 + 5') 
        self.try_to_parse('n1 = n2 - 5') 
        self.try_to_parse('n1 = n2 x 5') 
        self.try_to_parse('n1 = n2 * 5') 
        self.try_to_parse('n1 = n2 + n7') 

    def test_parses_print_statements(self):
        self.try_to_parse('PRINT v7, 4000') 
        self.try_to_parse('PRINT n3, 4000') 
        self.try_to_parse('PRINT v7, n3') 
        self.try_to_parse('PRINT vn7, 3236') 

    def test_parses_variable_assignments(self):
        self.try_to_parse('v1 = 5.0') 
        self.try_to_parse('v1 = -5.0') 
        self.try_to_parse('v1 = 5') 
        self.try_to_parse('v1 = v3') 
        self.try_to_parse('v1 = v3 + 5') 
        self.try_to_parse('v1 = v3 + 5') 
        self.try_to_parse('v1 = v3 x 5.0') 

    def test_parses_mixed_assignments(self):
        self.try_to_parse('n1 = v2') 
        self.try_to_parse('n1 = -v2') 
        self.try_to_parse('v1 = n2') 
        self.try_to_parse('v1 = n2/n3') 
        self.try_to_parse('v1 = 2/n3') 
        self.try_to_parse('v1 = 2/3') 
        self.try_to_parse('v1 = n2/3') 


    def test_parses_modification(self):
        self.try_to_parse('vn7 = 323.6') 
        self.try_to_parse('v(5+n7) = 323.6') 
        self.try_to_parse('v(5+n7) = v(-7+n5) + v(3+n2)') 
        self.try_to_parse('vn7 = vn1 + 323.6') 
        self.try_to_parse('vn7 = vn1 + vn5') 

    def test_parses_functions(self):
        self.try_to_parse('v1 = MOD v2') 
        self.try_to_parse('v1 = -MOD v2') 
        self.try_to_parse('v1 = INT 5.6') 
        self.try_to_parse('v1 = INT v2') 
        self.try_to_parse('v1 = -INT v2') 
        self.try_to_parse('v1 = FRAC v2') 
        self.try_to_parse('v1 = SQRT v2') 
        self.try_to_parse('v1 = SIN v2') 
        self.try_to_parse('v1 = COS v2') 
        self.try_to_parse('v1 = TAN v2') 
        self.try_to_parse('v1 = CSC v2') 
        self.try_to_parse('v1 = SEC v2') 
        self.try_to_parse('v1 = COT v2') 
        self.try_to_parse('v1 = ARCSIN v2') 
        self.try_to_parse('v1 = ARCCOS v2') 
        self.try_to_parse('v1 = ARCTAN v2') 
        self.try_to_parse('v1 = LOG v2') 
        self.try_to_parse('v1 = EXP v2') 
        self.try_to_parse('v1 = EXPM v2') 
        self.try_to_parse('n1 = MOD n2') 
        self.try_to_parse('n1 = -MOD n2') 

    def test_parses_stop(self):
        self.try_to_parse('STOP') 

   # using ^ instead of ->

    def test_parses_jump_instructions(self):
        self.try_to_parse('^0') 
        self.try_to_parse('^n1') 
        self.try_to_parse('^0, v2 > v3') 
        self.try_to_parse('^0, v2 > 3.0') 
        self.try_to_parse('^0, -v2 > 3.0') 
        self.try_to_parse('^0, v2 > -3.0') 
        self.try_to_parse('^0, n2 > -3') 
        self.try_to_parse('^0, n2 = -3') 
        self.try_to_parse('^0, n2 = -3') 
        self.try_to_parse('^0, n2 = -3') 
        self.try_to_parse('^0, n2 = -3') 
        self.try_to_parse('^0, v1 =* v3') 
        self.try_to_parse('^(-4 +n8), v1 =* v3') 

    def test_processes_print_prefixes(self):
        self.try_to_parse('XP n1 = MOD n2') 
        self.try_to_parse('X n1 = MOD n2') 
        self.try_to_parse('SP n1 = MOD n2') 
        self.try_to_parse('S n1 = MOD n2') 

    def test_parses_bracketed_interludes(self):
        self.try_to_parse('(^0)') 
        self.try_to_parse('^0)') 
        self.try_to_parse('(v1 = 5.0') 




{'fraction_non_alphanumeric': 0.15445703578120817, 'fraction_numerical': 0.03676273757473008, 'mean_word_length': 3.0652883569096843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4638201', 'n_tokens_mistral': 4385, 'n_tokens_neox': 4242, 'n_words': 754}