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