This repository was archived by the owner on Apr 4, 2024. It is now read-only.
forked from diffplug/selfie
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlineReaderTest.py
42 lines (35 loc) · 1.73 KB
/
lineReaderTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from selfie_lib import LineReader
def test_should_find_unix_separator_from_binary():
reader = LineReader.for_binary(b"This is a new line\n")
assert reader.unix_newlines() == True
assert reader.read_line() == "This is a new line"
def test_should_find_windows_separator_from_binary():
reader = LineReader.for_binary(b"This is a new line\r\n")
assert reader.unix_newlines() == False
assert reader.read_line() == "This is a new line"
def test_should_find_unix_separator_from_string():
reader = LineReader.for_string("This is a new line\n")
assert reader.unix_newlines() == True
assert reader.read_line() == "This is a new line"
def test_should_find_windows_separator_from_string():
reader = LineReader.for_string("This is a new line\r\n")
assert reader.unix_newlines() == False
assert reader.read_line() == "This is a new line"
def test_should_get_unix_line_separator_when_there_is_none():
reader = LineReader.for_binary(b"This is a new line")
assert reader.unix_newlines() == True
assert reader.read_line() == "This is a new line"
def test_should_read_next_line_without_problem():
reader = LineReader.for_binary(b"First\r\nSecond\r\n")
assert reader.unix_newlines() == False
assert reader.read_line() == "First"
assert reader.unix_newlines() == False
assert reader.read_line() == "Second"
assert reader.unix_newlines() == False
def test_should_use_first_line_separator_and_ignore_next():
reader = LineReader.for_binary(b"First\r\nAnother separator\n")
assert reader.unix_newlines() == False
assert reader.read_line() == "First"
assert reader.unix_newlines() == False
assert reader.read_line() == "Another separator"
assert reader.unix_newlines() == False