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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:orgro/src/pages/editor/edits.dart';
import '../utils/editing.dart';
void main() {
group('Editing', () {
group('Bold', () {
test('Bold selection', () {
final result = makeBold(testValue('foo |bar|'));
expect(result, testValue('foo *bar|*'));
});
test('Bold empty selection', () {
final result = makeBold(testValue('foo bar|'));
expect(result, testValue('foo bar*|*'));
});
test('Bold empty', () {
final result = makeBold(testValue('|'));
expect(result, testValue('*|*'));
});
});
group('Italic', () {
test('Italic selection', () {
final result = makeItalic(testValue('foo |bar|'));
expect(result, testValue('foo /bar|/'));
});
test('Italic empty selection', () {
final result = makeItalic(testValue('foo bar|'));
expect(result, testValue('foo bar/|/'));
});
test('Italic empty', () {
final result = makeItalic(testValue('|'));
expect(result, testValue('/|/'));
});
});
group('Underline', () {
test('Underline selection', () {
final result = makeUnderline(testValue('foo |bar|'));
expect(result, testValue('foo _bar|_'));
});
test('Underline empty selection', () {
final result = makeUnderline(testValue('foo bar|'));
expect(result, testValue('foo bar_|_'));
});
test('Underline empty', () {
final result = makeUnderline(testValue('|'));
expect(result, testValue('_|_'));
});
});
group('Strikethrough', () {
test('Strikethrough selection', () {
final result = makeStrikethrough(testValue('foo |bar|'));
expect(result, testValue('foo +bar|+'));
});
test('Strikethrough empty selection', () {
final result = makeStrikethrough(testValue('foo bar|'));
expect(result, testValue('foo bar+|+'));
});
test('Strikethrough empty', () {
final result = makeStrikethrough(testValue('|'));
expect(result, testValue('+|+'));
});
});
group('Code', () {
test('Code selection', () {
final result = makeCode(testValue('foo |bar|'));
expect(result, testValue('foo ~bar|~'));
});
test('Code empty selection', () {
final result = makeCode(testValue('foo bar|'));
expect(result, testValue('foo bar~|~'));
});
test('Code empty', () {
final result = makeCode(testValue('|'));
expect(result, testValue('~|~'));
});
});
group('Subscript', () {
test('Subscript selection', () {
final result = makeSubscript(testValue('foo |bar|'));
expect(result, testValue('foo _{bar|}'));
});
test('Subscript empty selection', () {
final result = makeSubscript(testValue('foo bar|'));
expect(result, testValue('foo bar_{|}'));
});
test('Subscript empty', () {
final result = makeSubscript(testValue('|'));
expect(result, testValue('_{|}'));
});
});
group('Superscript', () {
test('Superscript selection', () {
final result = makeSuperscript(testValue('foo |bar|'));
expect(result, testValue('foo ^{bar|}'));
});
test('Superscript empty selection', () {
final result = makeSuperscript(testValue('foo bar|'));
expect(result, testValue('foo bar^{|}'));
});
test('Superscript empty', () {
final result = makeSuperscript(testValue('|'));
expect(result, testValue('^{|}'));
});
});
group('Link', () {
test('Link with URL selection', () async {
final result = await insertLink(
testValue('foo |https://example.com/|'),
null,
);
expect(result, testValue('foo [[https://example.com/][description|]]'));
});
test('Link with URL selection and clipboard URL', () async {
final result = await insertLink(
testValue('foo |https://example.com/|'),
'https://other.com/',
);
expect(result, testValue('foo [[https://example.com/][description|]]'));
});
test('Link with non-URL selection', () async {
final result = await insertLink(testValue('foo |bar|'), null);
expect(result, testValue('foo [[URL][bar|]]'));
});
test('Link with non-URL selection and clipboard URL', () async {
final result = await insertLink(
testValue('foo |bar|'),
'https://example.com/',
);
expect(result, testValue('foo [[https://example.com/][bar|]]'));
});
test('Link with empty selection with clipboard URL', () async {
final result = await insertLink(
testValue('foo bar|'),
'https://example.com/',
);
expect(
result,
testValue('foo bar[[https://example.com/][description|]]'),
);
});
test('Link with empty selection without clipboard URL', () async {
final result = await insertLink(testValue('foo bar|'), null);
expect(result, testValue('foo bar[[URL][description|]]'));
});
});
group('Date', () {
test('Date with selection', () async {
final result = await insertDate(
testValue('foo |bar|'),
false,
DateTime(2024, 6, 15),
null,
);
expect(result, testValue('foo [2024-06-15 Sat|]'));
});
test('Date with empty selection', () async {
final result = await insertDate(
testValue('foo bar|'),
false,
DateTime(2024, 6, 20),
null,
);
expect(result, testValue('foo bar[2024-06-20 Thu|]'));
});
test('Date empty', () async {
final result = await insertDate(
testValue('|'),
false,
DateTime(2024, 6, 20),
null,
);
expect(result, testValue('[2024-06-20 Thu|]'));
});
test('Date with time', () async {
final result = await insertDate(
testValue('foo |bar|'),
false,
DateTime(2024, 6, 15),
TimeOfDay(hour: 14, minute: 30),
);
expect(result, testValue('foo [2024-06-15 Sat 14:30|]'));
});
test('Active date with time', () async {
final result = await insertDate(
testValue('foo |bar|'),
true,
DateTime(2024, 6, 15),
TimeOfDay(hour: 14, minute: 30),
);
expect(result, testValue('foo <2024-06-15 Sat 14:30|>'));
});
});
group('Section', () {
group('Indentation', () {
test('Indent section', () {
final result = changeIndent(testValue('* foo |bar'), true);
expect(result, testValue('** foo |bar'));
});
test('Deindent section', () {
final result = changeIndent(testValue('*** foo |bar'), false);
expect(result, testValue('** foo |bar'));
});
test('Deindent base section', () {
final result = changeIndent(testValue('* foo |bar'), false);
expect(result, isNull);
});
});
});
});
}