mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-15 07:56:11 +08:00

It all just makes far more since when each Note has a fileName. Though we don't save the fileName in the YAML header. It seems quite redundant to do that. Another advantage of this is that if we can read any file ending with a '.md' in a git repo. It doesn't need to be named exactly how we want it, and we will still save the details correctly.
36 lines
911 B
Dart
36 lines
911 B
Dart
import 'package:journal/note.dart';
|
|
import 'package:journal/storage/serializers.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
DateTime nowWithoutMicro() {
|
|
var dt = DateTime.now();
|
|
return DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
|
|
}
|
|
|
|
main() {
|
|
group('Serializers', () {
|
|
var note = Note(
|
|
fileName: "2", body: "This is the body", created: nowWithoutMicro());
|
|
|
|
test('JSON Serializer', () {
|
|
var serializer = new JsonNoteSerializer();
|
|
var str = serializer.encode(note);
|
|
var note2 = serializer.decode(str);
|
|
|
|
expect(note2, note);
|
|
});
|
|
|
|
test('Markdown Serializer', () {
|
|
var serializer = new MarkdownYAMLSerializer();
|
|
var str = serializer.encode(note);
|
|
var note2 = serializer.decode(str);
|
|
|
|
// The YAML seriazlier loses the fileName by design
|
|
note2.fileName = note.fileName;
|
|
|
|
expect(note2, note);
|
|
});
|
|
});
|
|
}
|