mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-09 20:12:20 +08:00

With this I'm not accepting any of the Link's field to be an empty string. In that case it's better for it to be null, as the compiler will force me to deal with an empty value.
109 lines
3.5 KiB
Dart
109 lines
3.5 KiB
Dart
import 'package:test/test.dart';
|
|
|
|
import 'package:gitjournal/core/links_loader.dart';
|
|
|
|
void main() {
|
|
group('LinksLoader', () {
|
|
var contents = """[[GitJournal]]
|
|
|
|
[GitJournal](./gitjournal.md)
|
|
[GitJournal](gitjournal.md)
|
|
[GitJournal](gitjournal "alt-text")
|
|
|
|
[Google](https://google.com)
|
|
|
|
[Google's Homepage][Google]
|
|
|
|
[Google]: https://www.google.com/
|
|
""";
|
|
|
|
test('Should load links', () async {
|
|
var loader = LinksLoader();
|
|
var links = await loader.parseLinks(
|
|
body: contents,
|
|
filePath: "/tmp/foo/file.md",
|
|
);
|
|
|
|
expect(links[0].filePath, isNull);
|
|
expect(links[0].headingID, isNull);
|
|
expect(links[0].alt, isNull);
|
|
expect(links[0].publicTerm, isNull);
|
|
expect(links[0].wikiTerm, "GitJournal");
|
|
expect(links[0].isWikiLink, true);
|
|
|
|
expect(links[1].filePath, "/tmp/foo/gitjournal.md");
|
|
expect(links[1].publicTerm, "GitJournal");
|
|
expect(links[1].alt, isNull);
|
|
expect(links[1].wikiTerm, isNull);
|
|
|
|
expect(links[2].filePath, "/tmp/foo/gitjournal.md");
|
|
expect(links[2].publicTerm, "GitJournal");
|
|
expect(links[2].alt, isNull);
|
|
expect(links[2].wikiTerm, isNull);
|
|
|
|
expect(links[3].filePath, "/tmp/foo/gitjournal");
|
|
expect(links[3].publicTerm, "GitJournal");
|
|
expect(links[3].alt, "alt-text");
|
|
expect(links[3].wikiTerm, isNull);
|
|
|
|
/*
|
|
expect(links[4].filePath, "/tmp/foam.md");
|
|
expect(links[4].publicTerm, "Foam");
|
|
expect(links[4].alt, "foam");
|
|
expect(links[4].wikiTerm.isEmpty, true);
|
|
*/
|
|
|
|
expect(links.length, 4);
|
|
});
|
|
|
|
test('Foam Documentation', () async {
|
|
var contents = """
|
|
[](#contributors-)
|
|
|
|
3. Use Foam's shortcuts and autocompletions to link your thoughts together with `[[wiki-links]]`, and navigate between them to explore your knowledge graph.
|
|
4. the [[Graph Visualisation](https://foambubble.github.io/foam/graph-visualisation)], of [[Backlinking](https://foambubble.github.io/foam/backlinking)].
|
|
|
|

|
|
|
|
Foam is licensed under the [MIT license](license).
|
|
|
|
[//begin]: # "Autogenerated link references for markdown compatibility"
|
|
[wiki-links]: wiki-links "Wiki Links"
|
|
[//end]: # "Autogenerated link references"
|
|
""";
|
|
|
|
var links = parseLinks(contents, "/tmp/foo.md");
|
|
expect(links.length, 5);
|
|
|
|
expect(links[0].filePath, "/tmp/foo.md");
|
|
expect(links[0].alt, isNull);
|
|
expect(links[0].headingID, "#contributors-");
|
|
expect(links[0].publicTerm, isNull);
|
|
|
|
expect(links[1].filePath, "/tmp/license");
|
|
expect(links[1].alt, isNull);
|
|
expect(links[1].headingID, isNull);
|
|
expect(links[1].publicTerm, "MIT license");
|
|
|
|
expect(links[2].filePath, "/tmp/foo.md");
|
|
expect(links[2].publicTerm, '//begin');
|
|
expect(links[2].headingID, "#");
|
|
expect(links[2].alt,
|
|
"Autogenerated link references for markdown compatibility");
|
|
|
|
// FIXME: link-references for wiki Links
|
|
// expect(links[3].filePath.isEmpty, true);
|
|
// expect(links[3].isWikiLink, true);
|
|
expect(links[3].headingID, isNull);
|
|
expect(links[3].alt, "Wiki Links");
|
|
|
|
expect(links[4].filePath, "/tmp/foo.md");
|
|
expect(links[4].publicTerm, '//end');
|
|
expect(links[4].headingID, "#");
|
|
expect(links[4].alt, "Autogenerated link references");
|
|
});
|
|
});
|
|
|
|
// Add a test for linking to a header in another Note
|
|
}
|