def create_node(self):
     node = ast_nodes.OperatorNode(
         f_token(tvalue='+', ttype='operator-infix', tsubtype='math'))
     node.left = ast_nodes.OperandNode(
         f_token(tvalue='1', ttype='operand', tsubtype='number'))
     node.right = ast_nodes.OperandNode(
         f_token(tvalue='2', ttype='operand', tsubtype='number'))
     return node
 def test_eval_expr_var_positional(self):
     node = ast_nodes.FunctionNode(
         f_token(tvalue='AND', ttype='function', tsubtype='start'))
     node.args = [
         ast_nodes.OperandNode(
             f_token(tvalue='3', ttype='operand', tsubtype='number')),
         ast_nodes.OperandNode(
             f_token(tvalue='2', ttype='operand', tsubtype='number')),
     ]
     self.assertEqual(node.eval(context('A1')), True)
 def create_node(self):
     node = ast_nodes.FunctionNode(
         f_token(tvalue='MOD', ttype='function', tsubtype='start'))
     node.args = [
         ast_nodes.OperandNode(
             f_token(tvalue='3', ttype='operand', tsubtype='number')),
         ast_nodes.OperandNode(
             f_token(tvalue='2', ttype='operand', tsubtype='number')),
     ]
     return node
    def test_eval_expr(self):
        cond_node = ast_nodes.OperatorNode(
            f_token(tvalue='>', ttype='operator-infix', tsubtype='math'))
        cond_node.left = ast_nodes.OperandNode(
            f_token(tvalue='1', ttype='operand', tsubtype='number'))
        cond_node.right = ast_nodes.OperandNode(
            f_token(tvalue='0', ttype='operand', tsubtype='number'))

        node = ast_nodes.FunctionNode(
            f_token(tvalue='IF', ttype='function', tsubtype='start'))
        node.args = [
            cond_node,
            ast_nodes.OperandNode(
                f_token(tvalue='3', ttype='operand', tsubtype='number')),
            ast_nodes.OperandNode(
                f_token(tvalue='2', ttype='operand', tsubtype='number')),
        ]
        self.assertEqual(node.eval(context('A1')), 3)
 def create_node(self, value='1', type='nuber'):
     return ast_nodes.OperandNode(
         f_token(tvalue=value, ttype='operand', tsubtype=type))
 def test_str_postfix(self):
     node = ast_nodes.OperatorNode(
         f_token(tvalue='%', ttype='operator-postfix', tsubtype='math'))
     node.left = ast_nodes.OperandNode(
         f_token(tvalue='1', ttype='operand', tsubtype='number'))
     self.assertEqual(str(node), '(1) %')
 def test_str_prefix(self):
     node = ast_nodes.OperatorNode(
         f_token(tvalue='-', ttype='operator-prefix', tsubtype='math'))
     node.right = ast_nodes.OperandNode(
         f_token(tvalue='1', ttype='operand', tsubtype='number'))
     self.assertEqual(str(node), '- (1)')
 def test_eval_postfix(self):
     node = ast_nodes.OperatorNode(
         f_token(tvalue='%', ttype='operator-postfix', tsubtype='math'))
     node.left = ast_nodes.OperandNode(
         f_token(tvalue='1', ttype='operand', tsubtype='number'))
     self.assertEqual(node.eval(context('A1')), 0.01)
 def test_eval_prefix(self):
     node = ast_nodes.OperatorNode(
         f_token(tvalue='-', ttype='operator-prefix', tsubtype='math'))
     node.right = ast_nodes.OperandNode(
         f_token(tvalue='1', ttype='operand', tsubtype='number'))
     self.assertEqual(node.eval(context('A1')), -1)