def test_rvalue_and_expr(self): expr = 'a + a- b ' \ 'and;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE)
def test_unary_operators(self): expr = ' -;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = 'not;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = '+;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = 'not ();' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = '(- );' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE)
def test_def_params_no_comma(self): fun_def = 'fun some_function (a b);' should_fail(self, fun_def, ErrorCode.UNEXPECTED_TOKEN, TokenType.RPAREN) fun_def = 'fun some_function (a + b);' should_fail(self, fun_def, ErrorCode.UNEXPECTED_TOKEN, TokenType.RPAREN)
def test_loop_no_statement(self): # actually pretty interesting # breaks here V loop = 'do while (1>0); ' should_fail(self, loop, ErrorCode.UNEXPECTED_TOKEN, TokenType.WHILE) loop = 'do fun function(a, b);' should_fail(self, loop, ErrorCode.EXPECTED_NOT_NONE)
def test_empty_condition(self): s = 'if ();' should_fail(self, s, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_IF_CONDITION) s = 'if ((((()))));' should_fail(self, s, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_IF_CONDITION)
def test_no_statement(self): s = 'if (c) else ;' should_fail(self, s, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_IF_BODY) s = 'if (c) expr; else' should_fail(self, s, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_ELSE_BODY)
def test_loop_no_statement(self): loop = 'while (1>0)' should_fail(self, loop, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_WHILE_BODY) loop = 'while (1>0){}' should_fail(self, loop, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_COMPOUND_STATEMENT)
def test_def_without_parentheses(self): fun_def = 'fun some_function 1+2;' should_fail(self, fun_def, ErrorCode.UNEXPECTED_TOKEN, TokenType.LPAREN) fun_def = 'fun some_function (a, b;' should_fail(self, fun_def, ErrorCode.UNEXPECTED_TOKEN, TokenType.RPAREN)
def test_rvalue_eq_expr(self): expr = '-5 == 2;' \ '3 ==;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = 'b != a;' \ 'b != ;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE)
def test_colon_index(self): s = 'm[:,];' should_fail(self, s, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_INDEX) s = 'm[::];' should_fail(self, s, ErrorCode.UNEXPECTED_TOKEN, TokenType.RBRACK) s = 'm[:,a+:];' should_fail(self, s, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) s = 'm[:,:+a];' should_fail(self, s, ErrorCode.UNEXPECTED_TOKEN, TokenType.RBRACK)
def test_nested_matrices(self): m = '[[[[]]]' should_fail(self, m, ErrorCode.UNEXPECTED_TOKEN, TokenType.RBRACK) m = '[' \ '[], [], [];' \ '];' should_fail(self, m, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_MTRX_ROW) m = '[' \ '[], [], [];' \ '[], [],' \ '];' should_fail(self, m, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_ITEM) m = '[' \ '[], [], [];' \ '[], []' \ '];' should_fail(self, m, ErrorCode.MTRX_ROW_LEN_MISMATCH) # maybe error is not so obvious # test for row length is executed # within matrix object creation m = '[' \ '[a], [a], [a];' \ '[a], []a, [a];' \ '[a], [a], [a]' \ '];' should_fail(self, m, ErrorCode.MTRX_ROW_LEN_MISMATCH)
def test_nested_matrices_without_semi(self): m = '[[[[]]]]' should_fail(self, m, ErrorCode.UNEXPECTED_TOKEN, TokenType.SEMI) m = '[[[]]]]' should_fail(self, m, ErrorCode.UNEXPECTED_TOKEN, TokenType.SEMI) m = '[' \ '[], [], []' \ ']' should_fail(self, m, ErrorCode.UNEXPECTED_TOKEN, TokenType.SEMI)
def test_one_row(self): m = '[a, ]' should_fail(self, m, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_ITEM) m = '[a, b, ' should_fail(self, m, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_ITEM) m = '[, b, ' should_fail(self, m, ErrorCode.UNEXPECTED_TOKEN, TokenType.RBRACK) m = '[a, b, c]' should_fail(self, m, ErrorCode.UNEXPECTED_TOKEN, TokenType.SEMI)
def test_def_no_parameters_but_comma(self): fun_def = 'fun some_function(a, );' should_fail(self, fun_def, ErrorCode.UNEXPECTED_TOKEN, TokenType.ID) fun_def = 'fun some_function(a, b, );' should_fail(self, fun_def, ErrorCode.UNEXPECTED_TOKEN, TokenType.ID) fun_def = 'fun some_function(, );' should_fail(self, fun_def, ErrorCode.UNEXPECTED_TOKEN, TokenType.ID)
def test_loop_empty_condition(self): loop = 'while () 1+2;' should_fail(self, loop, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_WHILE_CONDITION) loop = 'while (()) 1+2;' should_fail(self, loop, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_WHILE_CONDITION) loop = 'while ((())) 1+2;' should_fail(self, loop, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_WHILE_CONDITION)
def test_rvalue_relativ_expr(self): expr = '-4 <;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = 'a >=;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = 'c <=;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = 'a >;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE)
def test_rvalue_term(self): expr = 'a * b *;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = 'a - b div 5; b div;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = '80 mod b; 6 mod;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = 'b / a / b / a / b /;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE)
def test_def_no_statement(self): fun_def = 'fun some_function()' should_fail(self, fun_def, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_FUN_BODY) fun_def = 'fun some_function(){}' should_fail(self, fun_def, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_COMPOUND_STATEMENT) fun_def = 'fun some_function(){{;}{}}' should_fail(self, fun_def, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.EMPTY_COMPOUND_STATEMENT)
def test_rvalue_aexpr(self): expr = '-3 + 3 + +;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = '- a -;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE) expr = '-;' should_fail(self, expr, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_RVALUE)
def test_multiple_indices(self): s = 'm[a, b, c]' # expected two indices, got 3 should_fail(self, s, ErrorCode.UNEXPECTED_TOKEN, TokenType.RBRACK)
def test_rbrack_missing(self): m = '[' should_fail(self, m, ErrorCode.UNEXPECTED_TOKEN, TokenType.RBRACK)
def test_no_second_arg(self): f = 'a(a, );' should_fail(self, f, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_ARGUMENT)
def test_loop_no_semi_at_end(self): loop = 'do ; while (1)' should_fail(self, loop, ErrorCode.UNEXPECTED_TOKEN, TokenType.SEMI)
def test_loop_no_parentheses(self): loop = 'do {;} while 1>0;' should_fail(self, loop, ErrorCode.UNEXPECTED_TOKEN, TokenType.LPAREN) loop = 'do {;} while (1>0;' should_fail(self, loop, ErrorCode.UNEXPECTED_TOKEN, TokenType.RPAREN)
def test_loop_no_while_token(self): loop = 'do {;};' should_fail(self, loop, ErrorCode.UNEXPECTED_TOKEN, TokenType.WHILE) loop = 'do {1+3; 1+4; a= b= c = 4+2-6;}' should_fail(self, loop, ErrorCode.UNEXPECTED_TOKEN, TokenType.WHILE)
def test_no_first_arg(self): f = 'a(, a);' should_fail(self, f, ErrorCode.UNEXPECTED_TOKEN, TokenType.RPAREN)
def test_no_semi(self): s = 'if (c) expr' should_fail(self, s, ErrorCode.UNEXPECTED_TOKEN, TokenType.SEMI)
def test_rparen(self): f = 'a(' should_fail(self, f, ErrorCode.UNEXPECTED_TOKEN, TokenType.RPAREN)
def test_lparen(self): s = 'if ) ;' should_fail(self, s, ErrorCode.UNEXPECTED_TOKEN, TokenType.LPAREN)
def test_no_first_index(self): s = 'm[,a];' should_fail(self, s, ErrorCode.EXPECTED_NOT_NONE, None, ErrorDescription.NO_INDEX)