Esempio n. 1
0
def test_list_multiline_multiple_items_on_one_line():
    ret = parse('[\n' '    true, false,\n' '    false, true,\n' ']')
    expected = ast.Doc(
        head=(),
        val=ast.List(
            head=(ast.ListStart('['), ast.NL('\n')),
            items=(
                ast.ListItem(
                    head=(ast.Indent('    '), ),
                    val=ast.Bool(val=True, src='true'),
                    tail=(ast.Comma(','), ast.Space(' ')),
                ),
                ast.ListItem(
                    head=(),
                    val=ast.Bool(val=False, src='false'),
                    tail=(ast.Comma(','), ast.NL('\n')),
                ),
                ast.ListItem(
                    head=(ast.Indent('    '), ),
                    val=ast.Bool(val=False, src='false'),
                    tail=(ast.Comma(','), ast.Space(' ')),
                ),
                ast.ListItem(
                    head=(),
                    val=ast.Bool(val=True, src='true'),
                    tail=(ast.Comma(','), ast.NL('\n')),
                ),
            ),
            tail=(ast.ListEnd(']'), ),
        ),
        tail=(),
    )
    assert ret == expected
Esempio n. 2
0
def test_nested_list():
    ret = parse('[\n' '    [\n' '        1,\n' '    ],\n' ']')
    expected = ast.Doc(
        head=(),
        val=ast.List(
            head=(ast.ListStart('['), ast.NL('\n')),
            items=(ast.ListItem(head=(ast.Indent('    '), ),
                                val=ast.List(
                                    head=(ast.ListStart('['), ast.NL('\n')),
                                    items=(ast.ListItem(
                                        head=(ast.Indent('        '), ),
                                        val=ast.Int(val=1, src='1'),
                                        tail=(ast.Comma(','), ast.NL('\n')),
                                    ), ),
                                    tail=(ast.Indent('    '),
                                          ast.ListEnd(']')),
                                ),
                                tail=(ast.Comma(','), ast.NL('\n'))), ),
            tail=(ast.ListEnd(']'), ),
        ),
        tail=(),
    )
    assert ret == expected
Esempio n. 3
0
def test_list_multiline_trivial():
    ret = parse('[\n]')
    expected = ast.Doc(
        head=(),
        val=ast.List(
            head=(ast.ListStart('['), ast.NL('\n')),
            items=(),
            tail=(ast.ListEnd(']'), ),
        ),
        tail=(),
    )
    assert ret == expected
    assert ret.val.is_multiline
    assert not ret.val.is_top_level_style
Esempio n. 4
0
def test_list_one_value_inline():
    ret = parse('[true]')
    expected = ast.Doc(
        head=(),
        val=ast.List(
            head=(ast.ListStart('['), ),
            items=(ast.ListItem(
                head=(),
                val=ast.Bool(val=True, src='true'),
                tail=(),
            ), ),
            tail=(ast.ListEnd(']'), ),
        ),
        tail=(),
    )
    assert ret == expected
Esempio n. 5
0
def test_list_multiline_comments():
    ret = parse('[\n' '    # Comment\n' ']')
    expected = ast.Doc(
        head=(),
        val=ast.List(
            head=(
                ast.ListStart('['),
                ast.NL('\n'),
                ast.Indent('    '),
                ast.Comment('# Comment\n'),
            ),
            items=(),
            tail=(ast.ListEnd(']'), ),
        ),
        tail=(),
    )
    assert ret == expected
Esempio n. 6
0
def test_list_multiline_comment_before():
    ret = parse('[\n' '    # Hello\n' '    true,\n' ']')
    expected = ast.Doc(
        head=(),
        val=ast.List(
            head=(ast.ListStart('['), ast.NL('\n')),
            items=(ast.ListItem(
                head=(
                    ast.Indent('    '),
                    ast.Comment('# Hello\n'),
                    ast.Indent('    '),
                ),
                val=ast.Bool(val=True, src='true'),
                tail=(ast.Comma(','), ast.NL('\n')),
            ), ),
            tail=(ast.ListEnd(']'), ),
        ),
        tail=(),
    )
    assert ret == expected
Esempio n. 7
0
def test_list_several_values_inline():
    ret = parse('[true, false]')
    expected = ast.Doc(
        head=(),
        val=ast.List(
            head=(ast.ListStart('['), ),
            items=(
                ast.ListItem(
                    head=(),
                    val=ast.Bool(val=True, src='true'),
                    tail=(ast.Comma(','), ast.Space(' ')),
                ),
                ast.ListItem(
                    head=(),
                    val=ast.Bool(val=False, src='false'),
                    tail=(),
                ),
            ),
            tail=(ast.ListEnd(']'), ),
        ),
        tail=(),
    )
    assert ret == expected