Ejemplo n.º 1
0
    def test_while_statement_machine(self, interpret_statement_list,
                                     is_truthy):
        cond = IntegerLiteral(1)
        body = StatementList()

        elihw = While(None, children=[cond, body])

        # While loop executes 3 times
        is_truthy.side_effect = [True, True, True, False]
        interpret_statement(None, elihw, {})
        is_truthy.assert_called_with(cond, {})
Ejemplo n.º 2
0
    def test_while(self, interpret_statement_list, is_truthy):
        cond = IntegerLiteral(1)
        body = StatementList()

        elihw = While(None, children=[cond, body])

        # While loop executes 0 times
        is_truthy.side_effect = [False]
        interpret_while(None, elihw, {})
        is_truthy.assert_called_with(cond, {})
        self.assertFalse(interpret_statement_list.called)

        # While loop executes 1 time
        is_truthy.side_effect = [True, False]
        interpret_while(None, elihw, {})
        is_truthy.assert_called_with(cond, {})
        interpret_statement_list.assert_called_once_with(None, body, {})

        # While loop executes 2 times
        is_truthy.side_effect = [True, True, False]
        interpret_while(None, elihw, {})
        is_truthy.assert_called_with(cond, {})
        interpret_statement_list.assert_has_calls([call(None, body, {})]*2)

        # While loop executes 3 times
        is_truthy.side_effect = [True, True, True, False]
        interpret_while(None, elihw, {})
        is_truthy.assert_called_with(cond, {})
        interpret_statement_list.assert_has_calls([call(None, body, {})]*3)