Handle empty checklists

If there were no items we were ignoring the checklist. Added some extra
tests as well.

Fixes #148
This commit is contained in:
Vishesh Handa
2020-05-26 13:42:31 +02:00
parent 0d3648768c
commit bcbf54106f
2 changed files with 34 additions and 2 deletions

View File

@ -91,8 +91,6 @@ class Checklist {
} }
Note get note { Note get note {
if (_lines.isEmpty) return _note;
for (var item in items) { for (var item in items) {
_lines[item.lineNo] = item.toString(); _lines[item.lineNo] = item.toString();
} }

View File

@ -238,5 +238,39 @@ Booga Wooga
note = checklist.note; note = checklist.note;
expect(note.body, "- [X] One\n- [ ] Two"); expect(note.body, "- [X] One\n- [ ] Two");
}); });
test('Empty Checklist', () async {
var content = "[X] One\n";
var notePath = p.join(tempDir.path, "note449.md");
await File(notePath).writeAsString(content);
var parentFolder = NotesFolderFS(null, tempDir.path);
var note = Note(parentFolder, notePath);
await note.load();
var checklist = Checklist(note);
checklist.removeAt(0);
note = checklist.note;
expect(note.body, "\n");
});
test('Checklist Header only', () async {
var content = "#Title\n[X] One\n";
var notePath = p.join(tempDir.path, "note429.md");
await File(notePath).writeAsString(content);
var parentFolder = NotesFolderFS(null, tempDir.path);
var note = Note(parentFolder, notePath);
await note.load();
var checklist = Checklist(note);
checklist.removeAt(0);
note = checklist.note;
expect(note.body, "#Title\n");
});
}); });
} }