Esempio n. 1
0
 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
Esempio n. 2
0
 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)
Esempio n. 3
0
 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
Esempio n. 4
0
    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)
Esempio n. 5
0
 def create_node(self, value='1', type='nuber'):
     return ast_nodes.OperandNode(
         f_token(tvalue=value, ttype='operand', tsubtype=type))
Esempio n. 6
0
 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) %')
Esempio n. 7
0
 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)')
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)