diffs: fixed case of bogus files diff rendering

- adds safe placehodler so we never crush more in this cases at it's 2nd time this happens
- fixes #5528
- references #5422
This commit is contained in:
Marcin Lulek 2019-01-31 13:52:30 +01:00
parent ed7e61efb5
commit 6fec084754
2 changed files with 54 additions and 21 deletions

View file

@ -81,8 +81,9 @@ class TestTokenizeString(object):
class TestSplitTokenStream(object):
def test_split_token_stream(self):
lines = list(split_token_stream(
[('type1', 'some\ntext'), ('type2', 'more\n')]))
tokens = [('type1', 'some\ntext'), ('type2', 'more\n')]
content = [x + y for x, y in tokens]
lines = list(split_token_stream(tokens, content))
assert lines == [
[('type1', u'some')],
@ -91,18 +92,18 @@ class TestSplitTokenStream(object):
]
def test_split_token_stream_single(self):
lines = list(split_token_stream(
[('type1', '\n')]))
tokens = [('type1', '\n')]
content = [x + y for x, y in tokens]
lines = list(split_token_stream(tokens, content))
assert lines == [
[('type1', '')],
[('type1', '')],
]
def test_split_token_stream_single_repeat(self):
lines = list(split_token_stream(
[('type1', '\n\n\n')]))
tokens = [('type1', '\n\n\n')]
content = [x + y for x, y in tokens]
lines = list(split_token_stream(tokens, content))
assert lines == [
[('type1', '')],
[('type1', '')],
@ -111,9 +112,10 @@ class TestSplitTokenStream(object):
]
def test_split_token_stream_multiple_repeat(self):
lines = list(split_token_stream(
[('type1', '\n\n'), ('type2', '\n\n')]))
tokens = [('type1', '\n\n'), ('type2', '\n\n')]
content = [x + y for x, y in tokens]
lines = list(split_token_stream(tokens, content))
assert lines == [
[('type1', '')],
[('type1', '')],
@ -122,6 +124,27 @@ class TestSplitTokenStream(object):
[('type2', '')],
]
def test_no_tokens_by_content(self):
tokens = []
content = u'\ufeff'
lines = list(split_token_stream(tokens, content))
assert lines == [
[('', content)],
]
def test_no_tokens_by_valid_content(self):
from pygments.lexers.css import CssLexer
content = u'\ufeff table.dataTable'
tokens = tokenize_string(content, CssLexer())
lines = list(split_token_stream(tokens, content))
assert lines == [
[('', u' '),
('nt', u'table'),
('p', u'.'),
('nc', u'dataTable')],
]
class TestRollupTokens(object):