from django.template.defaultfilters import linebreaks_filter from django.test import SimpleTestCase from django.utils.safestring import mark_safe from ..utils import setup class LinebreaksTests(SimpleTestCase): """ The contents in "linebreaks" are escaped according to the current autoescape setting. """ @setup({'linebreaks01': '{{ a|linebreaks }} {{ b|linebreaks }}'}) def test_linebreaks01(self): output = self.engine.render_to_string('linebreaks01', {"a": "x&\ny", "b": mark_safe("x&\ny")}) self.assertEqual(output, "
x&
y
x&
y
x&
y
x&
y
line 1
') def test_newline(self): self.assertEqual(linebreaks_filter('line 1\nline 2'), 'line 1
line 2
line 1
line 2
line 1
line 2
123
') def test_autoescape(self): self.assertEqual( linebreaks_filter('foo\nbar\nbuz'), 'foo
<a>bar</a>
buz
foo
bar
buz