mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-23 17:13:54 +08:00

Instead we're going to move back to standard exceptions. Using a custom Result class has created far far more problems - The Stacktraces aren't always right - Sometimes one forgets to check the Result error - All other exception throwing code needing to be converted to Results - Non idiomatic Dart code I think it's better to just go back to exceptions. They have their problems, but overall, I think it's a better approach.
80 lines
2.0 KiB
Dart
80 lines
2.0 KiB
Dart
/*
|
|
* SPDX-FileCopyrightText: 2019-2021 Vishesh Handa <me@vhanda.in>
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
import 'dart:io' as io;
|
|
|
|
import 'package:dart_git/utils/date_time.dart';
|
|
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
|
import 'package:gitjournal/core/markdown/md_yaml_doc.dart';
|
|
import 'package:gitjournal/core/markdown/md_yaml_doc_loader.dart';
|
|
import 'package:path/path.dart' as p;
|
|
import 'package:test/test.dart';
|
|
|
|
import 'lib.dart';
|
|
|
|
void main() {
|
|
setUpAll(gjSetupAllTests);
|
|
|
|
test('Equality', () {
|
|
var now = GDateTime(const Duration(hours: 1), 2010, 1, 2, 3, 4, 5);
|
|
|
|
var aProps = IMap<String, dynamic>({
|
|
'a': 1,
|
|
'title': 'Foo',
|
|
'list': const <dynamic>["Foo", "Bar", 1].lock,
|
|
'map': const <String, dynamic>{'a': 5}.lock,
|
|
'date': now,
|
|
});
|
|
|
|
var bProps = IMap<String, dynamic>({
|
|
'a': 1,
|
|
'title': 'Foo',
|
|
'list': const <dynamic>["Foo", "Bar", 1].lock,
|
|
'map': const <String, dynamic>{'a': 5}.lock,
|
|
'date': now,
|
|
});
|
|
|
|
var a = MdYamlDoc(body: "a", props: aProps);
|
|
var b = MdYamlDoc(body: "a", props: bProps);
|
|
expect(a, b);
|
|
|
|
expect(
|
|
a.props['list'],
|
|
MdYamlDoc.fromProtoBuf(a.toProtoBuf()).props['list'],
|
|
);
|
|
expect(
|
|
a.props['map'],
|
|
MdYamlDoc.fromProtoBuf(a.toProtoBuf()).props['map'],
|
|
);
|
|
expect(a.props, MdYamlDoc.fromProtoBuf(a.toProtoBuf()).props);
|
|
expect(a, MdYamlDoc.fromProtoBuf(a.toProtoBuf()));
|
|
});
|
|
|
|
test("Equality 2", () async {
|
|
// Load from file
|
|
var content = """---
|
|
bar: Foo
|
|
modified: 2017-02-15T22:41:19+01:00
|
|
tags: ['A', 'B']
|
|
---
|
|
|
|
Hello
|
|
""";
|
|
|
|
var tempDir = io.Directory.systemTemp.createTempSync();
|
|
var repoPath = tempDir.path + p.separator;
|
|
|
|
var noteFullPath = p.join(repoPath, "note.md");
|
|
io.File(noteFullPath).writeAsStringSync(content);
|
|
|
|
final mdYamlDocLoader = MdYamlDocLoader();
|
|
var doc1 = await mdYamlDocLoader.loadDoc(noteFullPath);
|
|
var doc2 = await mdYamlDocLoader.loadDoc(noteFullPath);
|
|
|
|
expect(doc1, doc2);
|
|
});
|
|
}
|