Fix one edge case with comma scopes

This commit is contained in:
Anthony Sottile
2020-03-17 11:53:23 -07:00
parent 08638f990c
commit e32e5b8c05
2 changed files with 15 additions and 2 deletions

View File

@@ -116,8 +116,9 @@ class Theme(NamedTuple):
scopes = ['']
elif isinstance(rule['scope'], str):
scopes = [
# some themes have a buggy trailing comma
s.strip() for s in rule['scope'].strip(',').split(',')
s.strip()
# some themes have a buggy trailing/leading comma
for s in rule['scope'].strip().strip(',').split(',')
]
else:
scopes = rule['scope']

View File

@@ -72,6 +72,18 @@ def test_theme_scope_split_by_commas():
assert theme.select(('c',)).i is True
def test_theme_scope_comma_at_beginning_and_end():
theme = Theme.from_dct({
'colors': {'foreground': '#cccccc', 'background': '#333333'},
'tokenColors': [
{'scope': '\n,a,b,\n', 'settings': {'fontStyle': 'italic'}},
],
})
assert theme.select(('d',)).i is False
assert theme.select(('a',)).i is True
assert theme.select(('b',)).i is True
def test_theme_scope_as_A_list():
theme = Theme.from_dct({
'colors': {'foreground': '#cccccc', 'background': '#333333'},