mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Formatter: adapt to unittest
This commit is contained in:
parent
13b66e2875
commit
825f6e3b15
2 changed files with 21 additions and 6 deletions
|
@ -26,11 +26,17 @@ CLOSING_TOKENS = ["}", "]"]
|
||||||
|
|
||||||
NEWLINE_AFTER = [";"] + OPENING_TOKENS + CLOSING_TOKENS
|
NEWLINE_AFTER = [";"] + OPENING_TOKENS + CLOSING_TOKENS
|
||||||
|
|
||||||
NO_WHITESPACE_BEFORE = [",", ":", ";", ")", "."]
|
NO_WHITESPACE_BEFORE = [",", ":", "::", ";", ")", ".", ">"]
|
||||||
NO_WHITESPACE_AFTER = ["C_", "_", "("]
|
NO_WHITESPACE_AFTER = ["C_", "_", "("]
|
||||||
|
|
||||||
WHITESPACE_AFTER = [":", ","]
|
# NO_WHITESPACE_BEFORE takes precedence over WHITESPACE_AFTER
|
||||||
WHITESPACE_BEFORE = ["{"]
|
WHITESPACE_AFTER = [
|
||||||
|
":",
|
||||||
|
",",
|
||||||
|
">",
|
||||||
|
")",
|
||||||
|
]
|
||||||
|
WHITESPACE_BEFORE = ["{", "$"]
|
||||||
|
|
||||||
|
|
||||||
class LineType(Enum):
|
class LineType(Enum):
|
||||||
|
@ -77,7 +83,11 @@ class Format:
|
||||||
if item.type != tokenizer.TokenType.WHITESPACE:
|
if item.type != tokenizer.TokenType.WHITESPACE:
|
||||||
str_item = str(item)
|
str_item = str(item)
|
||||||
if item.type == tokenizer.TokenType.QUOTED and str_item.startswith('"'):
|
if item.type == tokenizer.TokenType.QUOTED and str_item.startswith('"'):
|
||||||
str_item = ("'" + str_item[1:-1] + "'").replace('\\"', '"')
|
str_item = (
|
||||||
|
"'"
|
||||||
|
+ str_item[1:-1].replace('\\"', '"').replace("'", "\\'")
|
||||||
|
+ "'"
|
||||||
|
)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
str_item in WHITESPACE_BEFORE
|
str_item in WHITESPACE_BEFORE
|
||||||
|
@ -117,7 +127,10 @@ class Format:
|
||||||
|
|
||||||
indent_levels += 1
|
indent_levels += 1
|
||||||
commit_current_line(
|
commit_current_line(
|
||||||
1 if prev_line_type == LineType.CHILD_TYPE else 2,
|
1
|
||||||
|
if prev_line_type == LineType.CHILD_TYPE
|
||||||
|
or tokenized_str.strip()[-1] == "{"
|
||||||
|
else 2,
|
||||||
LineType.BLOCK_OPEN,
|
LineType.BLOCK_OPEN,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@ Overlay {
|
||||||
Button {
|
Button {
|
||||||
notify::icon-name => $on_icon_name_changed (label) swapped;
|
notify::icon-name => $on_icon_name_changed (label) swapped;
|
||||||
|
|
||||||
styles ['destructive']
|
styles [
|
||||||
|
'destructive'
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
visible: bind $isVisible (label.visible, my-menu) as <bool>;
|
visible: bind $isVisible (label.visible, my-menu) as <bool>;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue