@@ -451,4 +451,142 @@ describe('Todo mappings', function()
451451 ' ** Non-todo item' ,
452452 }, vim .api .nvim_buf_get_lines (0 , 0 , 6 , false ))
453453 end )
454+
455+ it (' should respect file-local todo keywords' , function ()
456+ helpers .create_file ({
457+ ' #+TODO: OPEN DOING | FINISHED ABORTED' ,
458+ ' * OPEN Test with file-local todo keywords' ,
459+ ' ** DOING Subtask' ,
460+ })
461+
462+ vim .fn .cursor (2 , 1 )
463+ vim .cmd ([[ norm cit]] )
464+ assert .are .same ({
465+ ' #+TODO: OPEN DOING | FINISHED ABORTED' ,
466+ ' * DOING Test with file-local todo keywords' ,
467+ ' ** DOING Subtask' ,
468+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
469+
470+ vim .cmd ([[ norm cit]] )
471+ local lines = vim .api .nvim_buf_get_lines (0 , 0 , 4 , false )
472+ assert .are .same (' #+TODO: OPEN DOING | FINISHED ABORTED' , lines [1 ])
473+ assert .are .same (' * FINISHED Test with file-local todo keywords' , lines [2 ])
474+ assert .is_true (lines [3 ]:match (' ^%s+CLOSED: %[%d%d%d%d%-%d%d%-%d%d' ) ~= nil )
475+ assert .are .same (' ** DOING Subtask' , lines [4 ])
476+
477+ vim .cmd ([[ norm cit]] )
478+ lines = vim .api .nvim_buf_get_lines (0 , 0 , 4 , false )
479+ assert .are .same (' #+TODO: OPEN DOING | FINISHED ABORTED' , lines [1 ])
480+ assert .are .same (' * ABORTED Test with file-local todo keywords' , lines [2 ])
481+ assert .is_true (lines [3 ]:match (' ^%s+CLOSED: %[%d%d%d%d%-%d%d%-%d%d' ) ~= nil )
482+ assert .are .same (' ** DOING Subtask' , lines [4 ])
483+
484+ vim .cmd ([[ norm cit]] )
485+ assert .are .same ({
486+ ' #+TODO: OPEN DOING | FINISHED ABORTED' ,
487+ ' * Test with file-local todo keywords' ,
488+ ' ** DOING Subtask' ,
489+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
490+
491+ vim .cmd ([[ norm cit]] )
492+ assert .are .same ({
493+ ' #+TODO: OPEN DOING | FINISHED ABORTED' ,
494+ ' * OPEN Test with file-local todo keywords' ,
495+ ' ** DOING Subtask' ,
496+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
497+ end )
498+ it (' should consider locally defined permutation of globally defined todo keywords' , function ()
499+ local local_todo_definition = ' #+TODO: DONE OPEN | DOING'
500+ config :extend ({
501+ org_todo_keywords = { ' OPEN' , ' DOING' , ' |' , ' DONE' },
502+ org_log_into_drawer = ' LOGBOOK' ,
503+ org_todo_repeat_to_state = ' MEET' ,
504+ })
505+ helpers .create_file ({
506+ local_todo_definition ,
507+ ' * Test with file-local todo keywords' ,
508+ ' ** DOING Subtask' ,
509+ })
510+
511+ vim .fn .cursor (2 , 1 )
512+ vim .cmd ([[ norm cit]] )
513+ assert .are .same ({
514+ local_todo_definition ,
515+ ' * DONE Test with file-local todo keywords' ,
516+ ' ** DOING Subtask' ,
517+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
518+
519+ vim .cmd ([[ norm cit]] )
520+ assert .are .same ({
521+ local_todo_definition ,
522+ ' * OPEN Test with file-local todo keywords' ,
523+ ' ** DOING Subtask' ,
524+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
525+
526+ vim .cmd ([[ norm cit]] )
527+ local lines = vim .api .nvim_buf_get_lines (0 , 0 , 4 , false )
528+ assert .are .same (local_todo_definition , lines [1 ])
529+ assert .are .same (' * DOING Test with file-local todo keywords' , lines [2 ])
530+ assert .is_true (lines [3 ]:match (' ^%s+CLOSED: %[%d%d%d%d%-%d%d%-%d%d' ) ~= nil )
531+ assert .are .same (' ** DOING Subtask' , lines [4 ])
532+
533+ vim .cmd ([[ norm cit]] )
534+ assert .are .same ({
535+ local_todo_definition ,
536+ ' * Test with file-local todo keywords' ,
537+ ' ** DOING Subtask' ,
538+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
539+
540+ vim .cmd ([[ norm cit]] )
541+ assert .are .same ({
542+ local_todo_definition ,
543+ ' * DONE Test with file-local todo keywords' ,
544+ ' ** DOING Subtask' ,
545+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
546+ end )
547+
548+ local todos_with_shortcuts = ' #+TODO: OPEN(o) DOING(d) | FINISHED(f) ABORTED(a)'
549+ it (' should respect file-local todo keywords with shortcut keys' , function ()
550+ helpers .create_file ({
551+ todos_with_shortcuts ,
552+ ' * OPEN Test with file-local todo keywords' ,
553+ ' ** DOING Subtask' ,
554+ })
555+
556+ vim .fn .cursor (2 , 1 )
557+ vim .cmd ([[ norm citd]] )
558+ assert .are .same ({
559+ todos_with_shortcuts ,
560+ ' * DOING Test with file-local todo keywords' ,
561+ ' ** DOING Subtask' ,
562+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
563+
564+ vim .cmd ([[ norm citf]] )
565+ local lines = vim .api .nvim_buf_get_lines (0 , 0 , 4 , false )
566+ assert .are .same (todos_with_shortcuts , lines [1 ])
567+ assert .are .same (' * FINISHED Test with file-local todo keywords' , lines [2 ])
568+ assert .is_true (lines [3 ]:match (' ^%s+CLOSED: %[%d%d%d%d%-%d%d%-%d%d' ) ~= nil )
569+ assert .are .same (' ** DOING Subtask' , lines [4 ])
570+
571+ vim .cmd ([[ norm cita]] )
572+ lines = vim .api .nvim_buf_get_lines (0 , 0 , 4 , false )
573+ assert .are .same (todos_with_shortcuts , lines [1 ])
574+ assert .are .same (' * ABORTED Test with file-local todo keywords' , lines [2 ])
575+ assert .is_true (lines [3 ]:match (' ^%s+CLOSED: %[%d%d%d%d%-%d%d%-%d%d' ) ~= nil )
576+ assert .are .same (' ** DOING Subtask' , lines [4 ])
577+
578+ vim .cmd ([[ exe "norm cit\<Space>"]] )
579+ assert .are .same ({
580+ todos_with_shortcuts ,
581+ ' * Test with file-local todo keywords' ,
582+ ' ** DOING Subtask' ,
583+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
584+
585+ vim .cmd ([[ norm cito]] )
586+ assert .are .same ({
587+ todos_with_shortcuts ,
588+ ' * OPEN Test with file-local todo keywords' ,
589+ ' ** DOING Subtask' ,
590+ }, vim .api .nvim_buf_get_lines (0 , 0 , 3 , false ))
591+ end )
454592end )
0 commit comments