blob: 539451ad0ffb48b886d2d0ead00cd753d238dec2 (
plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
from pocketbook.note import Note
class TestNoteSerialisation:
def test_round_trip(self):
note = Note(title="Shopping", body="Milk\nEggs\nBread")
content = note.to_file_content()
restored = Note.from_file_content(content)
assert restored.title == note.title
assert restored.body == note.body
def test_empty_body(self):
note = Note(title="Empty", body="")
content = note.to_file_content()
restored = Note.from_file_content(content)
assert restored.title == "Empty"
assert restored.body == ""
def test_empty_title(self):
note = Note(title="", body="some body")
content = note.to_file_content()
restored = Note.from_file_content(content)
assert restored.title == ""
assert restored.body == "some body"
def test_unicode(self):
note = Note(title="日本語タイトル", body="Ünïcödé bödý 🎉")
content = note.to_file_content()
restored = Note.from_file_content(content)
assert restored.title == "日本語タイトル"
assert restored.body == "Ünïcödé bödý 🎉"
def test_multiline_body(self):
body = "Line 1\nLine 2\n\nLine 4\n"
note = Note(title="Multi", body=body)
content = note.to_file_content()
restored = Note.from_file_content(content)
assert restored.body == body
def test_file_content_format(self):
"""Title on line 1, blank line, then body."""
note = Note(title="Title", body="Body text")
content = note.to_file_content()
assert content == "Title\n\nBody text"
def test_from_file_content_no_blank_line(self):
"""Gracefully handle files without a blank separator."""
restored = Note.from_file_content("JustTitle")
assert restored.title == "JustTitle"
assert restored.body == ""
class TestNoteFilename:
def test_generate_filename(self):
note = Note(title="Test", body="")
filename = note.generate_filename(order=1)
assert filename.startswith("0001-")
assert filename.endswith(".txt")
# Format: 0001-YYYYMMDD-HHMMSS-shortid.txt
parts = filename.split("-")
assert len(parts) == 4
assert len(parts[0]) == 4 # order
assert len(parts[1]) == 8 # date
# parts[2] = HHMMSS + shortid.txt combined via split on -
# Actually: 0001-20260225-143012-abc12.txt has 4 parts
def test_parse_order_from_filename(self):
assert Note.parse_order("0005-20260101-120000-abc12.txt") == 5
assert Note.parse_order("0001-20260101-120000-xyz99.txt") == 1
|