๐Ÿ“ฆ amake / orgro

๐Ÿ“„ analysis_test.dart ยท 99 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99import 'package:flutter_test/flutter_test.dart';
import 'package:org_flutter/org_flutter.dart';
import 'package:orgro/src/components/document_provider.dart';

void main() {
  group('Analysis', () {
    test('Boring document', () {
      final doc = OrgDocument.parse('* foo');
      final analysis = DocumentAnalysis.of(doc, canResolveRelativeLinks: true);
      expect(analysis.hasRemoteImages, isFalse);
      expect(analysis.hasRelativeLinks, isFalse);
      expect(analysis.hasEncryptedContent, isFalse);
      expect(analysis.needsEncryption, isFalse);
    });
    test('Remote images', () {
      final doc = OrgDocument.parse('https://example.com/image.png');
      final analysis = DocumentAnalysis.of(doc, canResolveRelativeLinks: true);
      expect(analysis.hasRemoteImages, isTrue);
      expect(analysis.hasRelativeLinks, isFalse);
      expect(analysis.hasEncryptedContent, isFalse);
      expect(analysis.needsEncryption, isFalse);
    });
    test('Relative links', () {
      final doc = OrgDocument.parse('[[./foo.org][foo]]');
      final analysis = DocumentAnalysis.of(doc, canResolveRelativeLinks: true);
      expect(analysis.hasRemoteImages, isFalse);
      expect(analysis.hasRelativeLinks, isTrue);
      expect(analysis.hasEncryptedContent, isFalse);
      expect(analysis.needsEncryption, isFalse);
    });
    test('Encrypted content', () {
      final doc = OrgDocument.parse('''
* foo :crypt:

-----BEGIN PGP MESSAGE-----

jA0ECQMI05i+dd7lsRry0joBcGZQ4m+N9M/Z3I2Xw7SSn2uPMRpWbH9UIRkzPTXU
28y0FO/Aug4JaE/n+wqbmgY0b37dZzWI2BWi
=uuok
-----END PGP MESSAGE-----
''');
      final analysis = DocumentAnalysis.of(doc, canResolveRelativeLinks: true);
      expect(analysis.hasRemoteImages, isFalse);
      expect(analysis.hasRelativeLinks, isFalse);
      expect(analysis.hasEncryptedContent, isTrue);
      expect(analysis.needsEncryption, isFalse);
    });
    test('Needs encryption', () {
      final doc = OrgDocument.parse('''
* foo :crypt:

bar

-----BEGIN PGP MESSAGE-----

jA0ECQMI05i+dd7lsRry0joBcGZQ4m+N9M/Z3I2Xw7SSn2uPMRpWbH9UIRkzPTXU
28y0FO/Aug4JaE/n+wqbmgY0b37dZzWI2BWi
=uuok
-----END PGP MESSAGE-----
''');
      final analysis = DocumentAnalysis.of(doc, canResolveRelativeLinks: true);
      expect(analysis.hasRemoteImages, isFalse);
      expect(analysis.hasRelativeLinks, isFalse);
      expect(analysis.hasEncryptedContent, isTrue);
      expect(analysis.needsEncryption, isTrue);
    });
    test('Keywords', () {
      final doc = OrgDocument.parse('''
* TODO foo
* DONE bar
''');
      final analysis = DocumentAnalysis.of(doc, canResolveRelativeLinks: true);
      expect(analysis.keywords, ['TODO', 'DONE']);
      expect(analysis.tags, isEmpty);
      expect(analysis.priorities, isEmpty);
    });
    test('Tags', () {
      final doc = OrgDocument.parse('''
* foo :tag1:tag2:
* bar :tag3:
''');
      final analysis = DocumentAnalysis.of(doc, canResolveRelativeLinks: true);
      expect(analysis.keywords, isEmpty);
      expect(analysis.tags, ['tag1', 'tag2', 'tag3']);
      expect(analysis.priorities, isEmpty);
    });
    test('Priorities', () {
      final doc = OrgDocument.parse('''
* [#A] foo
* [#B] bar
''');
      final analysis = DocumentAnalysis.of(doc, canResolveRelativeLinks: true);
      expect(analysis.keywords, isEmpty);
      expect(analysis.tags, isEmpty);
      expect(analysis.priorities, ['A', 'B']);
    });
  });
}