Exemplo n.º 1
0
def test_booleans():
    data = [
        ('true', True),
        ('false', False),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Boolean)
Exemplo n.º 2
0
def test_invoking_functions_with_variables():
    data = [
        (['add', 'x', 'y'], 30),
        (['subtract', 'z', 'x'], 20),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Invocation)
Exemplo n.º 3
0
def test_strings():
    data = [
        ('"Hey"', "Hey"),
        ('"Hello there!"', "Hello there!"),
        ('"\n\n\n"', "\n\n\n"),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.String)
Exemplo n.º 4
0
def test_accessing_variables():
    data = [
        ('x', 10),
        ('y', 20),
        ('z', 30),
        ('foo', 100),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Symbol)
Exemplo n.º 5
0
def test_invoking_functions():
    data = [
        (['add', '1', '2'], 3),
        (['subtract', '10', '5'], 5),
        (['multiply', '2', '3', '5'], 30),
        (['return10'], 10),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Invocation)
Exemplo n.º 6
0
def test_decimal_integers():
    data = [
        ('0', 0),
        ('10', 10),
        ('23', 23),
        ('-4', -4),
        ('+4', +4),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Integer)
Exemplo n.º 7
0
def test_binary_integers():
    data = [
        ('0b0', 0b0),
        ('0b1', 0b1),
        ('0b101', 0b101),
        ('-0b1', -0b1),
        ('-0b111', -0b111),
        ('+0b10', +0b10),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Binary)
Exemplo n.º 8
0
def test_hexadecimal_integers():
    data = [
        ('0x0', 0x0),
        ('0x123', 0x123),
        ('0xDEADA55', 0xDEADA55),
        ('-0x1', -0x1),
        ('-0xBEEF', -0xBEEF),
        ('+0xB00B5', +0xB00B5),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Hexadecimal)
Exemplo n.º 9
0
def test_invoking_anonymous_functions():
    data = [
        ([['function', [], '0']], 0),
        ([['function', [], '4']], 4),
        ([['function', ['n'], 'n'], '0'], 0),
        ([['function', ['n'], 'n'], '9'], 9),
        ([['function', ['a', 'b'], ['+', 'a', 'b']], '10', '5'], 15),
        ([['function', ['a', 'b'], ['+', 'a', 'b']], '20', '0'], 20),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Invocation)
Exemplo n.º 10
0
def test_floats():
    data = [
        ('0', 0.0),
        ('0.5', 0.5),
        ('2.3', 2.3),
        ('1.23456789', 1.23456789),
        ('-2.5', -2.5),
        ('-60.12', -60.12),
        ('+20.3', +20.3),
    ]
    for contents, expected_value in data:
        yield Helpers.assert_form_evaluates_to(expected_value, contents,
                                               Types.Float)