Fix incorrect caching in syntax highlighter

the concrete broken case was for markdown with yaml

```md
---
x: y
---

(this one shouldn't be yaml highlighted)
---
x: y
---
```
This commit is contained in:
Anthony Sottile
2020-03-23 20:05:47 -07:00
parent c4e2f8e9cf
commit b529dde91a
2 changed files with 37 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ import pytest
from babi.color_manager import ColorManager
from babi.highlight import Grammars
from babi.hl.interface import HL
from babi.hl.syntax import Syntax
from babi.theme import Color
from babi.theme import Theme
@@ -149,3 +150,20 @@ def test_style_attributes_applied(stdscr, syntax):
style = THEME.select(('keyword.python',))
attr = syntax.blank_file_highlighter().attr(style)
assert attr == 2 << 8 | curses.A_BOLD
def test_syntax_highlight_cache_first_line(stdscr):
with FakeCurses.patch(n_colors=256, can_change_color=False):
grammars = Grammars([{
'scopeName': 'source.demo',
'fileTypes': ['demo'],
'patterns': [{'match': r'\Aint', 'name': 'keyword'}],
}])
syntax = Syntax(grammars, THEME, ColorManager.make())
syntax._init_screen(stdscr)
file_hl = syntax.file_highlighter('foo.demo', '')
file_hl.highlight_until(['int', 'int'], 2)
assert file_hl.regions == [
(HL(0, 3, curses.A_BOLD | 2 << 8),),
(),
]