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
def _multiline(val, settings, container_settings): ret = [container_settings.start, ast.NL('\n')] for item in container_settings.to_iter(val): ret.append(ast.Indent(' ' * (settings.indented.indent))) ret.extend(container_settings.item_func(item, settings.indented)) ret.extend((ast.Comma(','), ast.NL('\n'))) if settings.indent > 0: ret.append(ast.Indent(' ' * settings.indent)) ret.append(container_settings.end) return ret
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
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
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
def test_map_multiline_one_element(): ret = parse('{\n' ' true: false,\n' '}') expected = ast.Doc( head=(), val=ast.Map( head=(ast.MapStart('{'), ast.NL('\n')), items=(ast.MapItem( head=(ast.Indent(' '), ), key=ast.Bool(val=True, src='true'), inner=(ast.Colon(':'), ast.Space(' ')), val=ast.Bool(val=False, src='false'), tail=(ast.Comma(','), ast.NL('\n')), ), ), tail=(ast.MapEnd('}'), ), ), tail=(), ) assert ret == expected