mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
runtime(python): Highlight f-strings in Python
fixes: #10734 fixes: #14033 closes: #17767 Signed-off-by: Rob B <github@0x7e.net> Signed-off-by: Zvezdan Petkovic <zpetkovic@acm.org> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
97501afda3
commit
b7fc24d3a3
@@ -27,37 +27,6 @@ test = R"""Raw string with quotes ' and "
|
||||
and literal \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605"""
|
||||
|
||||
# Bytes
|
||||
test = b'Bytes with escapes \' and \" and \t'
|
||||
test = B"Bytes with escapes \040 and \xFF"
|
||||
test = b'Bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
|
||||
test = B"Bytes with escaped \\ backslash and ignored \
|
||||
newline"
|
||||
test = b'''Bytes with quotes ' and "
|
||||
and escapes \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605'''
|
||||
test = B"""Bytes with quotes ' and "
|
||||
and escapes \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605"""
|
||||
|
||||
# Raw bytes
|
||||
test = br'Raw bytes with literal \' and \" and \t'
|
||||
test = bR"Raw bytes with literal \040 and \xFF"
|
||||
test = Br'Raw bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
|
||||
test = BR"Raw bytes with literal \\ backslashes and literal \
|
||||
newline"
|
||||
test = rb'Raw bytes with literal \' and \" and \t'
|
||||
test = rB"Raw bytes with literal \040 and \xFF"
|
||||
test = Rb'Raw bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
|
||||
test = RB"Raw bytes with literal \\ backslashes and literal \
|
||||
newline"
|
||||
test = br'''Raw bytes with quotes ' and "
|
||||
and literal \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605'''
|
||||
test = RB"""Raw bytes with quotes ' and "
|
||||
and literal \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605"""
|
||||
|
||||
# Unicode literals: Prefix is allowed but ignored (https://peps.python.org/pep-0414)
|
||||
test = u'String with escapes \' and \" and \t'
|
||||
test = U"String with escapes \040 and \xFF"
|
||||
@@ -88,3 +57,75 @@ and \u00A1 and \U00010605'''
|
||||
test = RU"""Invalid string with ' and "
|
||||
and \t and \040 and \xFF
|
||||
and \u00A1 and \U00010605"""
|
||||
|
||||
# Formatted string literals (f-strings)
|
||||
# https://docs.python.org/3/reference/lexical_analysis.html#f-strings
|
||||
test = f'F-string with escapes \' and \" and \t and fields {foo} and {bar}'
|
||||
test = F"F-string with escapes \040 and \xFF and fields {foo} and {bar}"
|
||||
test = f'F-string with escapes \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK} and fields {foo} and {bar}'
|
||||
test = F"F-string with literal {{field}} and fields {foo} and {bar}"
|
||||
test = f'''F-string with quotes ' and "
|
||||
and escapes \t and \040 and \xFF
|
||||
and escapes \u00A1 and \U00010605
|
||||
and fields {1}, {2} and {1
|
||||
+
|
||||
2}'''
|
||||
test = F"""F-string with quotes ' and "
|
||||
and escapes \t and \040 and \xFF
|
||||
and escapes \u00A1 and \U00010605
|
||||
and fields {1}, {2} and {1
|
||||
+
|
||||
2}"""
|
||||
|
||||
# Raw formatted string literals
|
||||
test = fr'Raw f-string with literal \' and \" and \t and fields {foo} and {bar}'
|
||||
test = fR"Raw f-string with literal \040 and \xFF and fields {foo} and {bar}"
|
||||
test = Fr'Raw f-string with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK} and fields {foo} and {bar}'
|
||||
test = FR"Raw f-string with literal {{field}} and fields {foo} and {bar}"
|
||||
test = rf'Raw f-string with literal \' and \" and \t and fields {foo} and {bar}'
|
||||
test = rF"Raw f-string with literal \040 and \xFF and fields {foo} and {bar}"
|
||||
test = Rf'Raw f-string with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK} and fields {foo} and {bar}'
|
||||
test = RF"Raw f-string with literal {{field}} and fields {foo} and {bar}"
|
||||
test = fr'''Raw f-string with quotes ' and "
|
||||
and literal \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605
|
||||
and fields {1}, {2} and {1
|
||||
+
|
||||
2}'''
|
||||
test = RF"""Raw f-string with quotes ' and "
|
||||
and literal \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605
|
||||
and fields {1}, {2} and {1
|
||||
+
|
||||
2}"""
|
||||
|
||||
# Bytes
|
||||
test = b'Bytes with escapes \' and \" and \t'
|
||||
test = B"Bytes with escapes \040 and \xFF"
|
||||
test = b'Bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
|
||||
test = B"Bytes with escaped \\ backslash and ignored \
|
||||
newline"
|
||||
test = b'''Bytes with quotes ' and "
|
||||
and escapes \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605'''
|
||||
test = B"""Bytes with quotes ' and "
|
||||
and escapes \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605"""
|
||||
|
||||
# Raw bytes
|
||||
test = br'Raw bytes with literal \' and \" and \t'
|
||||
test = bR"Raw bytes with literal \040 and \xFF"
|
||||
test = Br'Raw bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
|
||||
test = BR"Raw bytes with literal \\ backslashes and literal \
|
||||
newline"
|
||||
test = rb'Raw bytes with literal \' and \" and \t'
|
||||
test = rB"Raw bytes with literal \040 and \xFF"
|
||||
test = Rb'Raw bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
|
||||
test = RB"Raw bytes with literal \\ backslashes and literal \
|
||||
newline"
|
||||
test = br'''Raw bytes with quotes ' and "
|
||||
and literal \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605'''
|
||||
test = RB"""Raw bytes with quotes ' and "
|
||||
and literal \t and \040 and \xFF
|
||||
and literal \u00A1 and \U00010605"""
|
||||
|
Reference in New Issue
Block a user