def test_file_ending_in_several_comments(): ret = parse('true\n# hello\n# there\n') expected = ast.Doc( head=(), val=ast.Bool(val=True, src='true'), tail=( ast.NL('\n'), ast.Comment('# hello\n'), ast.Comment('# there\n'), ), ) assert ret == expected
def test_file_ending_in_comment_no_nl(): ret = parse('true # ohai') expected = ast.Doc( head=(), val=ast.Bool(val=True, src='true'), tail=(ast.Space(' '), ast.Comment('# ohai')), ) assert ret == expected
def test_file_starting_with_comments(): ret = parse('# hello\ntrue') expected = ast.Doc( head=(ast.Comment('# hello\n'), ), val=ast.Bool(val=True, src='true'), 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_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_comment_at_start_of_multiline_json(): ret = parse('{ # bar\n' ' true: false,\n' '}') expected = ast.Doc( head=(), val=ast.Map( head=( ast.MapStart('{'), ast.Space(' '), ast.Space(' '), ast.Comment('# bar\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