Allow YAML tags to be a string

This commit is contained in:
Vishesh Handa
2020-08-19 10:12:07 +02:00
parent 6be1c22496
commit 9380f3cc06
2 changed files with 29 additions and 0 deletions

View File

@ -190,6 +190,8 @@ class NoteSerializer implements NoteSerializerInterface {
note.tags = tags.map((t) => t.toString()).toSet();
} else if (tags is List) {
note.tags = tags.map((t) => t.toString()).toSet();
} else if (tags is String) {
note.tags = {tags};
} else {
Log.e("Note Tags Decoding Failed: $tags");
}

View File

@ -122,5 +122,32 @@ void main() {
expect(doc.props['title'], 'Why not?');
expect(doc.props['draft'], true);
});
test('Test Non list Tag', () {
var props = LinkedHashMap<String, dynamic>.from(<String, dynamic>{
"title": "Why not?",
"draft": true,
"tags": "foo",
});
var doc = MdYamlDoc("body", props);
var serializer = NoteSerializer.raw();
serializer.settings.saveTitleAsH1 = false;
var note = Note(parent, "file-path-not-important");
serializer.decode(doc, note);
expect(note.body, "body");
expect(note.title, "Why not?");
expect(note.extraProps, <String, dynamic>{"draft": true});
expect(note.tags, <String>{"foo"});
serializer.encode(note, doc);
expect(doc.body, "body");
expect(doc.props['title'], 'Why not?');
expect(doc.props['draft'], true);
expect(doc.props['tags'], ['foo']);
expect(doc.props.length, 3);
});
});
}