@@ -3,6 +3,7 @@ local api = require('orgmode.api')
3
3
local Date = require (' orgmode.objects.date' )
4
4
local OrgId = require (' orgmode.org.id' )
5
5
local orgmode = require (' orgmode' )
6
+ local config = require (' orgmode.config' )
6
7
7
8
describe (' Api' , function ()
8
9
--- @return OrgApiFile
@@ -109,7 +110,7 @@ describe('Api', function()
109
110
assert .is .True (vim .fn .getline (5 ):match (' :PERSONAL:HEALTH:$' ) ~= nil )
110
111
end )
111
112
112
- it (' should toggle priority up and down ' , function ()
113
+ it (' should cycle upwards through priorities, starting with default ' , function ()
113
114
helpers .create_file ({
114
115
' #TITLE: First file' ,
115
116
' ' ,
@@ -125,24 +126,123 @@ describe('Api', function()
125
126
local current_file = cur_file ()
126
127
local headline = current_file .headlines [2 ]
127
128
assert .are .same (' ' , headline .priority )
128
- headline : priority_up (): wait ( )
129
- assert .are .same (' C ' , cur_file (). headlines [ 2 ]. priority )
130
- assert . is . True ( vim . fn . getline ( 5 ): match ( ' %[#C%] ' ) ~= nil )
129
+ assert . are . same ( true , config . org_priority_start_cycle_with_default )
130
+ assert .are .same (' B ' , config . org_priority_default )
131
+
131
132
headline :priority_up ():wait ()
132
133
assert .are .same (' B' , cur_file ().headlines [2 ].priority )
133
134
assert .is .True (vim .fn .getline (5 ):match (' %[#B%]' ) ~= nil )
134
135
headline :priority_up ():wait ()
135
136
assert .are .same (' A' , cur_file ().headlines [2 ].priority )
136
137
assert .is .True (vim .fn .getline (5 ):match (' %[#A%]' ) ~= nil )
137
138
headline :priority_up ():wait ()
138
- assert .are .same (' ' , cur_file ().headlines [2 ].priority )
139
- assert .is .True (vim .fn .getline (5 ):match (' %[.*%]' ) == nil )
139
+ assert .are .same (' C' , cur_file ().headlines [2 ].priority )
140
+ assert .is .True (vim .fn .getline (5 ):match (' %[#C%]' ) ~= nil )
141
+ headline :priority_up ():wait ()
142
+ assert .are .same (' B' , cur_file ().headlines [2 ].priority )
143
+ assert .is .True (vim .fn .getline (5 ):match (' %[#B%]' ) ~= nil )
144
+ end )
145
+
146
+ it (' should cycle downwards through priorities, starting with default' , function ()
147
+ helpers .create_file ({
148
+ ' #TITLE: First file' ,
149
+ ' ' ,
150
+ ' * TODO Test orgmode :WORK:OFFICE:' ,
151
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
152
+ ' ** TODO Second level :NESTEDTAG:' ,
153
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
154
+ ' * DONE Some task' ,
155
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
156
+ })
157
+
158
+ assert .is .True (# api .load () > 1 )
159
+ local current_file = cur_file ()
160
+ local headline = current_file .headlines [2 ]
161
+ assert .are .same (' ' , headline .priority )
162
+ assert .are .same (true , config .org_priority_start_cycle_with_default )
163
+ assert .are .same (' B' , config .org_priority_default )
164
+
165
+ headline :priority_down ():wait ()
166
+ assert .are .same (' B' , cur_file ().headlines [2 ].priority )
167
+ assert .is .True (vim .fn .getline (5 ):match (' %[#B%]' ) ~= nil )
168
+ headline :priority_down ():wait ()
169
+ assert .are .same (' C' , cur_file ().headlines [2 ].priority )
170
+ assert .is .True (vim .fn .getline (5 ):match (' %[#C%]' ) ~= nil )
140
171
headline :priority_down ():wait ()
141
172
assert .are .same (' A' , cur_file ().headlines [2 ].priority )
142
173
assert .is .True (vim .fn .getline (5 ):match (' %[#A%]' ) ~= nil )
143
174
headline :priority_down ():wait ()
144
175
assert .are .same (' B' , cur_file ().headlines [2 ].priority )
145
176
assert .is .True (vim .fn .getline (5 ):match (' %[#B%]' ) ~= nil )
177
+ end )
178
+
179
+ it (' should enable priority at default + 1' , function ()
180
+ helpers .create_file ({
181
+ ' #TITLE: First file' ,
182
+ ' ' ,
183
+ ' * TODO Test orgmode :WORK:OFFICE:' ,
184
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
185
+ ' ** TODO Second level :NESTEDTAG:' ,
186
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
187
+ ' * DONE Some task' ,
188
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
189
+ })
190
+
191
+ assert .is .True (# api .load () > 1 )
192
+ local current_file = cur_file ()
193
+ local headline = current_file .headlines [2 ]
194
+ assert .are .same (' ' , headline .priority )
195
+ assert .are .same (' B' , config .org_priority_default )
196
+ config .org_priority_start_cycle_with_default = false
197
+
198
+ headline :priority_up ():wait ()
199
+ assert .are .same (' A' , cur_file ().headlines [2 ].priority )
200
+ assert .is .True (vim .fn .getline (5 ):match (' %[#A%]' ) ~= nil )
201
+ end )
202
+
203
+ it (' should enable priority at default + 1' , function ()
204
+ helpers .create_file ({
205
+ ' #TITLE: First file' ,
206
+ ' ' ,
207
+ ' * TODO Test orgmode :WORK:OFFICE:' ,
208
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
209
+ ' ** TODO Second level :NESTEDTAG:' ,
210
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
211
+ ' * DONE Some task' ,
212
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
213
+ })
214
+
215
+ assert .is .True (# api .load () > 1 )
216
+ local current_file = cur_file ()
217
+ local headline = current_file .headlines [2 ]
218
+ assert .are .same (' ' , headline .priority )
219
+ assert .are .same (' B' , config .org_priority_default )
220
+ config .org_priority_start_cycle_with_default = false
221
+
222
+ headline :priority_down ():wait ()
223
+ assert .are .same (' C' , cur_file ().headlines [2 ].priority )
224
+ assert .is .True (vim .fn .getline (5 ):match (' %[#C%]' ) ~= nil )
225
+ end )
226
+
227
+ it (' should set/unset priorities' , function ()
228
+ helpers .create_file ({
229
+ ' #TITLE: First file' ,
230
+ ' ' ,
231
+ ' * TODO Test orgmode :WORK:OFFICE:' ,
232
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
233
+ ' ** TODO Second level :NESTEDTAG:' ,
234
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
235
+ ' * DONE Some task' ,
236
+ ' DEADLINE: <2021-07-21 Wed 22:02>' ,
237
+ })
238
+
239
+ assert .is .True (# api .load () > 1 )
240
+ local current_file = cur_file ()
241
+ local headline = current_file .headlines [2 ]
242
+ assert .are .same (' ' , headline .priority )
243
+
244
+ cur_file ().headlines [2 ]:set_priority (' B' ):wait ()
245
+ assert .is .True (vim .fn .getline (5 ):match (' %[#B%]' ) ~= nil )
146
246
cur_file ().headlines [2 ]:set_priority (' C' ):wait ()
147
247
assert .is .True (vim .fn .getline (5 ):match (' %[#C%]' ) ~= nil )
148
248
cur_file ().headlines [2 ]:set_priority (' A' ):wait ()
0 commit comments