def test_edge_of_file(self): set_active_view_text( "** Caption\n" "some text\n" "*** Other caption\n" "** Caption2\n") set_active_view_cursor_position(1, 5) self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), "** Caption\n" "some text\n" "*** Other caption\n" "** Caption2\n") self.assertEqual(get_active_view_cursor_position(), (1, 5)) set_active_view_cursor_position(4, 2) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), "** Caption\n" "some text\n" "*** Other caption\n" "** Caption2\n") self.assertEqual(get_active_view_cursor_position(), (4, 2))
def test_ordinary_move(self): set_active_view_text( " - List entry\n" " - Other list entry\n") set_active_view_cursor_position(1, 1) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), " - Other list entry\n" " - List entry\n") self.assertEqual(get_active_view_cursor_position(), (2, 1)) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), " - Other list entry\n" " - List entry\n") self.assertEqual(get_active_view_cursor_position(), (2, 1)) self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), " - List entry\n" " - Other list entry\n") self.assertEqual(get_active_view_cursor_position(), (1, 1)) self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), " - List entry\n" " - Other list entry\n") self.assertEqual(get_active_view_cursor_position(), (1, 1))
def test_toggle_checkbox(self): set_active_view_text( "* Caption\n" " - [ ] checkbox\n") set_active_view_cursor_position(1, 1) self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* Caption\n" " - [ ] checkbox\n") set_active_view_cursor_position(2, 1) self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* Caption\n" " - [X] checkbox\n") set_active_view_cursor_position(2, 1) self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* Caption\n" " - [ ] checkbox\n")
def test_selection(self): set_active_view_text("* Caption\n" # 1 " - [ ] checkbox 1\n" # 2 " - [X] checkbox 2\n" # 3 " - [ ] checkbox 3\n" # 4 " - [] not a checkbox 4\n" # 5 " - [ ] will not be toggled\n" # 6 ) view = get_active_view() sel = view.sel().clear() view.sel().add(sublime.Region(0, view.text_point(5, 0))) self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* Caption\n" " - [X] checkbox 1\n" " - [X] checkbox 2\n" " - [X] checkbox 3\n" " - [] not a checkbox 4\n" " - [ ] will not be toggled\n") self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* Caption\n" " - [ ] checkbox 1\n" " - [ ] checkbox 2\n" " - [ ] checkbox 3\n" " - [] not a checkbox 4\n" " - [ ] will not be toggled\n")
def test_text(self): set_active_view_text( " - List entry\n" " 1111\n" " * sublst 1 child 1\n" " 2222\n" " * sublst 2 child 1\n" " * sublst 2 child 2\n" " - Other list entry\n" " * 4444\n" " 3333\n" ) set_active_view_cursor_position(3, 1) with self.ensure_nothing_changes(): self.view.run_command('zorg_move_node_up') with self.ensure_nothing_changes(): self.view.run_command('zorg_move_node_down') set_active_view_cursor_position(5, 1) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), " - List entry\n" " 1111\n" " * sublst 1 child 1\n" " 2222\n" " * sublst 2 child 2\n" " * sublst 2 child 1\n" " - Other list entry\n" " * 4444\n" " 3333\n" ) self.assertEqual(get_active_view_cursor_position(), (6, 1)) with self.ensure_nothing_changes(): self.view.run_command('zorg_move_node_down') self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), " - List entry\n" " 1111\n" " * sublst 1 child 1\n" " 2222\n" " * sublst 2 child 1\n" " * sublst 2 child 2\n" " - Other list entry\n" " * 4444\n" " 3333\n" ) self.assertEqual(get_active_view_cursor_position(), (5, 1)) with self.ensure_nothing_changes(): self.view.run_command('zorg_move_node_up')
def test_sublists(self): set_active_view_text( " - List entry\n" " * child list entry\n" " * other child list entry\n" " - Other list entry\n" " * 333333\n") set_active_view_cursor_position(2, 1) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), " - List entry\n" " * other child list entry\n" " * child list entry\n" " - Other list entry\n" " * 333333\n") self.assertEqual(get_active_view_cursor_position(), (3, 1)) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), " - List entry\n" " * other child list entry\n" " * child list entry\n" " - Other list entry\n" " * 333333\n") self.assertEqual(get_active_view_cursor_position(), (3, 1)) self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), " - List entry\n" " * child list entry\n" " * other child list entry\n" " - Other list entry\n" " * 333333\n") self.assertEqual(get_active_view_cursor_position(), (2, 1)) with self.ensure_nothing_changes(): self.view.run_command('zorg_move_node_up') set_active_view_cursor_position(1, 1) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), " - Other list entry\n" " * 333333\n" " - List entry\n" " * child list entry\n" " * other child list entry\n") self.assertEqual(get_active_view_cursor_position(), (3, 1)) with self.ensure_nothing_changes(): self.view.run_command('zorg_move_node_down')
def test_empty_lines(self): set_active_view_text( " * 0000\n" "\n" "\n" " * 1111\n" " \n" " * 2222\n" " \n" " \n" " * 3333\n" ) set_active_view_cursor_position(4, 1) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), " * 0000\n" "\n" "\n" " * 2222\n" " \n" " * 1111\n" " \n" " \n" " * 3333\n" ) self.assertEqual(get_active_view_cursor_position(), (6, 1)) with self.ensure_nothing_changes(): self.view.run_command('zorg_move_node_down') self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), " * 0000\n" "\n" "\n" " * 1111\n" " \n" " * 2222\n" " \n" " \n" " * 3333\n" ) self.assertEqual(get_active_view_cursor_position(), (4, 1)) with self.ensure_nothing_changes(): self.view.run_command('zorg_move_node_up')
def test_ordinary_move(self): set_active_view_text( "some stuff\n" "** Caption\n" "some text\n" "*** Other caption\n" "** Caption2\n") set_active_view_cursor_position(1, 2) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), "some stuff\n" "** Caption\n" "some text\n" "*** Other caption\n" "** Caption2\n") self.assertEqual(get_active_view_cursor_position(), (1, 2)) set_active_view_cursor_position(2, 3) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), "some stuff\n" "** Caption2\n" "** Caption\n" "some text\n" "*** Other caption\n") self.assertEqual(get_active_view_cursor_position(), (3, 3)) set_active_view_cursor_position(2, 3) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), "some stuff\n" "** Caption\n" "some text\n" "*** Other caption\n" "** Caption2\n") self.assertEqual(get_active_view_cursor_position(), (5, 3)) self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), "some stuff\n" "** Caption2\n" "** Caption\n" "some text\n" "*** Other caption\n") self.assertEqual(get_active_view_cursor_position(), (2, 3))
def test_simple_agenda(self): original_file_view = get_active_view() set_active_view_text("* TODO Write agenda tests\n" # 1 "** TODO Open an editor\n" # 2 "** TODO Type tests\n" # 3 "** TODO Close the editor\n") # 4 original_file_view.run_command( "zorg_todo_list", { "show_in": "new_tab", "zorg_agenda_files": ["/dev/sublimetext_view/{}".format(get_active_view().id())], }) agenda_view = get_active_view() self.assertEqual( get_active_view_text(), "#+BEGIN_AGENDA\n" # 1 " TODO: TODO Write agenda tests\n" # 3 " TODO: TODO Open an editor\n" # 4 " TODO: TODO Type tests\n" # 5 " TODO: TODO Close the editor\n" # 6 "#+END_AGENDA\n" # 7 ) set_cursor_position(agenda_view, 4, 1) agenda_view.run_command("zorg_agenda_goto") self.assertEqual(get_active_view().id(), original_file_view.id()) self.assertEqual(get_active_view_cursor_position(), (3, 1))
def test_unordinary_cases(self): TEST_STRING = ("* [ ] Not checkbox but a headline\n" " * [ ] This is checkbox\n" " + [ ] Also checkbox\n" " - [] Not a checkbox\n" " 100500. [ ] Checkbox\n" " A. [ ] Checkbox\n" " -[] Not a checkbox\n" " [ ] Not a checkbox\n" "- [ ] Checkbox\n" "-[ ] Not a checkbox\n") set_active_view_text(TEST_STRING) for i in range(len(TEST_STRING.strip('\n').split('\n'))): set_active_view_cursor_position(i, 1) self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* [ ] Not checkbox but a headline\n" " * [X] This is checkbox\n" " + [X] Also checkbox\n" " - [] Not a checkbox\n" " 100500. [X] Checkbox\n" " A. [X] Checkbox\n" " -[] Not a checkbox\n" " [ ] Not a checkbox\n" "- [X] Checkbox\n" "-[ ] Not a checkbox\n")
def test_simple_agenda(self): original_file_view = get_active_view() set_active_view_text( "* TODO Write agenda tests\n" # 1 "** TODO Open an editor\n" # 2 "** TODO Type tests\n" # 3 "** TODO Close the editor\n") # 4 original_file_view.run_command("zorg_todo_list", { "show_in": "new_tab", "zorg_agenda_files": ["/dev/sublimetext_view/{}".format(get_active_view().id())], }) agenda_view = get_active_view() self.assertEqual( get_active_view_text(), "#+BEGIN_AGENDA\n" # 1 " TODO: TODO Write agenda tests\n" # 3 " TODO: TODO Open an editor\n" # 4 " TODO: TODO Type tests\n" # 5 " TODO: TODO Close the editor\n" # 6 "#+END_AGENDA\n" # 7 ) set_cursor_position(agenda_view, 4, 1) agenda_view.run_command("zorg_agenda_goto") self.assertEqual(get_active_view().id(), original_file_view.id()) self.assertEqual(get_active_view_cursor_position(), (3, 1))
def test_unordinary_cases(self): TEST_STRING = ( "* [ ] Not checkbox but a headline\n" " * [ ] This is checkbox\n" " + [ ] Also checkbox\n" " - [] Not a checkbox\n" " 100500. [ ] Checkbox\n" " A. [ ] Checkbox\n" " -[] Not a checkbox\n" " [ ] Not a checkbox\n" "- [ ] Checkbox\n" "-[ ] Not a checkbox\n") set_active_view_text(TEST_STRING) for i in range(len(TEST_STRING.strip('\n').split('\n'))): set_active_view_cursor_position(i, 1) self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* [ ] Not checkbox but a headline\n" " * [X] This is checkbox\n" " + [X] Also checkbox\n" " - [] Not a checkbox\n" " 100500. [X] Checkbox\n" " A. [X] Checkbox\n" " -[] Not a checkbox\n" " [ ] Not a checkbox\n" "- [X] Checkbox\n" "-[ ] Not a checkbox\n")
def test_other_headline(self): set_active_view_text( "** Caption\n" "some text\n" "*** Other caption\n" "some other text\n" "*** Other caption 2\n" "** Caption2\n" "*** Other caption 3\n") set_active_view_cursor_position(3, 5) self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), "** Caption\n" "some text\n" "*** Other caption\n" "some other text\n" "*** Other caption 2\n" "** Caption2\n" "*** Other caption 3\n") self.assertEqual(get_active_view_cursor_position(), (3, 5)) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), "** Caption\n" "some text\n" "*** Other caption 2\n" "*** Other caption\n" "some other text\n" "** Caption2\n" "*** Other caption 3\n") self.assertEqual(get_active_view_cursor_position(), (4, 5)) self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), "** Caption\n" "some text\n" "*** Other caption 2\n" "*** Other caption\n" "some other text\n" "** Caption2\n" "*** Other caption 3\n") self.assertEqual(get_active_view_cursor_position(), (4, 5))
def test_toggle_checkbox(self): set_active_view_text("* Caption\n" " - [ ] checkbox\n") set_active_view_cursor_position(1, 1) self.view.run_command('zorg_toggle_checkbox') self.assertEqual(get_active_view_text(), "* Caption\n" " - [ ] checkbox\n") set_active_view_cursor_position(2, 1) self.view.run_command('zorg_toggle_checkbox') self.assertEqual(get_active_view_text(), "* Caption\n" " - [X] checkbox\n") set_active_view_cursor_position(2, 1) self.view.run_command('zorg_toggle_checkbox') self.assertEqual(get_active_view_text(), "* Caption\n" " - [ ] checkbox\n")
def test_cut_section(self): set_active_view_text("* Header 1\n" "some text\n" "** Header 2\n" "another text\n" "* Header 3\n") set_active_view_cursor_position(1, 1) get_active_view().run_command("zorg_cut_node") self.assertEqual(get_active_view_text(), "* Header 3\n")
def test_cut_list_entry(self): set_active_view_text(" - foo\n" " - bar\n" " * baz\n" " continuation of baz\n" " continuation of bar\n" " + qux\n") set_active_view_cursor_position(2, 1) get_active_view().run_command("zorg_cut_node") self.assertEqual(get_active_view_text(), " - foo\n" " + qux\n")
def test_archivation_to_nonexistent_file(self): set_active_view_text("#+ARCHIVE:/dev/null/nonexistent_file\n" "* Header 1\n" "** Header 2\n" "* Header 3\n") set_active_view_cursor_position(3, 2) self.view.run_command("zorg_move_to_archive", {"silent": True}) self.assertEqual( get_active_view_text(), "#+ARCHIVE:/dev/null/nonexistent_file\n" "* Header 1\n" "** Header 2\n" "* Header 3\n")
def test_respect_folding(self): set_active_view_text( "* Caption {\n" "some text}\n" "* Caption 2\n" "* Caption 3 {\n" "text\n" "** subsection\n" "more text}") set_active_view_cursor_position(1, 2) self.view.run_command('zorg_cycle_all') try: self.assertProperFolding() except: # do not want this test to spam output raise RuntimeError("folding is broken") self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), "* Caption 2\n" "* Caption {\n" "some text}\n" "* Caption 3 {\n" "text\n" "** subsection\n" "more text}") self.assertProperFolding() self.view.run_command('zorg_move_node_down') self.assertEqual( get_active_view_text(), "* Caption 2\n" "* Caption 3 {\n" "text\n" "** subsection\n" "more text}\n" "* Caption {\n" "some text}")
def test_cut_section_with_src(self): set_active_view_text("* Header 1\n" "* Header 2\n" "#+BEGIN_SRC\n" "* This is actually not a header\n" "#+END_SRC\n" " #+BEGIN_SRC\n" "* This is also not a header\n" " #+END_SRC \n" "* Header 3\n") set_active_view_cursor_position(2, 1) get_active_view().run_command("zorg_cut_node") self.assertEqual(get_active_view_text(), "* Header 1\n" "* Header 3\n")
def test_missing_new_line_at_eof(self): set_active_view_text( "** Caption\n" "** Caption2\n" "text") set_active_view_cursor_position(2, 1) self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), "** Caption2\n" "text\n" "** Caption") self.assertEqual(get_active_view_cursor_position(), (1, 1))
def test_cursor_on_boundary(self): set_active_view_text( "** Caption\n" "** Caption2\n" "text\n") set_active_view_cursor_position(2, 1) self.view.run_command('zorg_move_node_up') self.assertEqual( get_active_view_text(), "** Caption2\n" "text\n" "** Caption\n") self.assertEqual(get_active_view_cursor_position(), (1, 1))
def test_selection(self): set_active_view_text( "* Caption\n" # 1 " - [ ] checkbox 1\n" # 2 " - [X] checkbox 2\n" # 3 " - [ ] checkbox 3\n" # 4 " - [] not a checkbox 4\n" # 5 " - [ ] will not be toggled\n" # 6 ) view = get_active_view() sel = view.sel().clear() view.sel().add( sublime.Region( 0, view.text_point(5, 0) ) ) self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* Caption\n" " - [X] checkbox 1\n" " - [X] checkbox 2\n" " - [X] checkbox 3\n" " - [] not a checkbox 4\n" " - [ ] will not be toggled\n" ) self.view.run_command('zorg_toggle_checkbox') self.assertEqual( get_active_view_text(), "* Caption\n" " - [ ] checkbox 1\n" " - [ ] checkbox 2\n" " - [ ] checkbox 3\n" " - [] not a checkbox 4\n" " - [ ] will not be toggled\n" )
def test_subheadline_archivation(self): with tempfile.NamedTemporaryFile() as tmpf: set_active_view_text("#+ARCHIVE:{tempfile}\n" "* Header 1\n" "** Header 2\n" "* Header 3\n".format(tempfile=tmpf.name)) set_active_view_cursor_position(3, 2) self.view.run_command("zorg_move_to_archive") self.assertEqual( get_active_view_text(), "#+ARCHIVE:{tempfile}\n" "* Header 1\n" "* Header 3\n".format(tempfile=tmpf.name)) self.assertEqual(tmpf.read().decode('utf-8'), "\n* Header 2\n")
def test_cut_section(self): set_active_view_text( "* Header 1\n" "some text\n" "** Header 2\n" "another text\n" "* Header 3\n" ) set_active_view_cursor_position(1, 1) get_active_view().run_command("zorg_cut_node") self.assertEqual( get_active_view_text(), "* Header 3\n" )
def test_cut_list_entry(self): set_active_view_text( " - foo\n" " - bar\n" " * baz\n" " continuation of baz\n" " continuation of bar\n" " + qux\n" ) set_active_view_cursor_position(2, 1) get_active_view().run_command("zorg_cut_node") self.assertEqual( get_active_view_text(), " - foo\n" " + qux\n" )
def test_archivation_to_nonexistent_file(self): set_active_view_text( "#+ARCHIVE:/dev/null/nonexistent_file\n" "* Header 1\n" "** Header 2\n" "* Header 3\n" ) set_active_view_cursor_position(3, 2) self.view.run_command("zorg_move_to_archive", {"silent": True}) self.assertEqual( get_active_view_text(), "#+ARCHIVE:/dev/null/nonexistent_file\n" "* Header 1\n" "** Header 2\n" "* Header 3\n" )
def test_simple_archivation(self): with tempfile.NamedTemporaryFile() as tmpf: set_active_view_text( "#+ARCHIVE:{tempfile}\n" "* Header 1\n" "** Header 2\n" "* Header 3\n".format(tempfile=tmpf.name)) set_active_view_cursor_position(2, 2) self.view.run_command("zorg_move_to_archive") self.assertEqual( get_active_view_text(), "#+ARCHIVE:{tempfile}\n" "* Header 3\n".format(tempfile=tmpf.name)) self.assertEqual( tmpf.read().decode('utf-8'), ("\n* Header 1\n" "** Header 2\n"))
def test_cut_section_with_src(self): set_active_view_text( "* Header 1\n" "* Header 2\n" "#+BEGIN_SRC\n" "* This is actually not a header\n" "#+END_SRC\n" " #+BEGIN_SRC\n" "* This is also not a header\n" " #+END_SRC \n" "* Header 3\n" ) set_active_view_cursor_position(2, 1) get_active_view().run_command("zorg_cut_node") self.assertEqual( get_active_view_text(), "* Header 1\n" "* Header 3\n" )