|
| 1 | +# coding=utf-8 |
| 2 | +"""Tests for core ``sopel.irc.utils``""" |
| 3 | +from __future__ import absolute_import, division, print_function, unicode_literals |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from sopel.irc import utils |
| 8 | + |
| 9 | + |
| 10 | +def test_safe(): |
| 11 | + text = 'some text' |
| 12 | + assert utils.safe(text + '\r\n') == text |
| 13 | + assert utils.safe(text + '\n') == text |
| 14 | + assert utils.safe(text + '\r') == text |
| 15 | + assert utils.safe('\r\n' + text) == text |
| 16 | + assert utils.safe('\n' + text) == text |
| 17 | + assert utils.safe('\r' + text) == text |
| 18 | + assert utils.safe('some \r\ntext') == text |
| 19 | + assert utils.safe('some \ntext') == text |
| 20 | + assert utils.safe('some \rtext') == text |
| 21 | + |
| 22 | + |
| 23 | +def test_safe_empty(): |
| 24 | + text = '' |
| 25 | + assert utils.safe(text) == text |
| 26 | + |
| 27 | + |
| 28 | +def test_safe_null(): |
| 29 | + with pytest.raises(TypeError): |
| 30 | + utils.safe(None) |
| 31 | + |
| 32 | + |
| 33 | +def test_safe_bytes(): |
| 34 | + text = b'some text' |
| 35 | + assert utils.safe(text) == text.decode('utf-8') |
| 36 | + assert utils.safe(text + b'\r\n') == text.decode('utf-8') |
| 37 | + assert utils.safe(text + b'\n') == text.decode('utf-8') |
| 38 | + assert utils.safe(text + b'\r') == text.decode('utf-8') |
| 39 | + assert utils.safe(b'\r\n' + text) == text.decode('utf-8') |
| 40 | + assert utils.safe(b'\n' + text) == text.decode('utf-8') |
| 41 | + assert utils.safe(b'\r' + text) == text.decode('utf-8') |
| 42 | + assert utils.safe(b'some \r\ntext') == text.decode('utf-8') |
| 43 | + assert utils.safe(b'some \ntext') == text.decode('utf-8') |
| 44 | + assert utils.safe(b'some \rtext') == text.decode('utf-8') |
0 commit comments