about summary refs log tree commit diff stats
path: root/text_tests.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-14 09:17:53 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-14 09:20:14 -0700
commit9d792a203bb00b0f5521698fd1c6890f0cc12032 (patch)
treebe2f89a515b0d5e7ff936c98cb5f4e17d618bbe4 /text_tests.lua
parent974d17ffc071e2eb254d0dbc11cf932c62e59d5c (diff)
downloadtext.love-9d792a203bb00b0f5521698fd1c6890f0cc12032.tar.gz
new fork: rip out drawing support
Diffstat (limited to 'text_tests.lua')
-rw-r--r--text_tests.lua96
1 files changed, 19 insertions, 77 deletions
diff --git a/text_tests.lua b/text_tests.lua
index fa4c173..5de9ea8 100644
--- a/text_tests.lua
+++ b/text_tests.lua
@@ -14,34 +14,6 @@ function test_initial_state()
   check_eq(Editor_state.screen_top1.pos, 1, 'F - test_initial_state/screen_top:pos')
 end
 
-function test_click_to_create_drawing()
-  io.write('\ntest_click_to_create_drawing')
-  App.screen.init{width=120, height=60}
-  Editor_state = edit.initialize_test_state()
-  Editor_state.lines = load_array{}
-  Text.redraw_all(Editor_state)
-  edit.draw(Editor_state)
-  edit.run_after_mouse_click(Editor_state, 8,Editor_state.top+8, 1)
-  -- cursor skips drawing to always remain on text
-  check_eq(#Editor_state.lines, 2, 'F - test_click_to_create_drawing/#lines')
-  check_eq(Editor_state.cursor1.line, 2, 'F - test_click_to_create_drawing/cursor')
-end
-
-function test_backspace_to_delete_drawing()
-  io.write('\ntest_backspace_to_delete_drawing')
-  -- display a drawing followed by a line of text (you shouldn't ever have a drawing right at the end)
-  App.screen.init{width=120, height=60}
-  Editor_state = edit.initialize_test_state()
-  Editor_state.lines = load_array{'```lines', '```', ''}
-  Text.redraw_all(Editor_state)
-  -- cursor is on text as always (outside tests this will get initialized correctly)
-  Editor_state.cursor1.line = 2
-  -- backspacing deletes the drawing
-  edit.run_after_keychord(Editor_state, 'backspace')
-  check_eq(#Editor_state.lines, 1, 'F - test_backspace_to_delete_drawing/#lines')
-  check_eq(Editor_state.cursor1.line, 1, 'F - test_backspace_to_delete_drawing/cursor')
-end
-
 function test_backspace_from_start_of_final_line()
   io.write('\ntest_backspace_from_start_of_final_line')
   -- display final line of text with cursor at start of it
@@ -629,7 +601,7 @@ function test_cursor_movement_without_shift_resets_selection()
   edit.run_after_keychord(Editor_state, 'right')
   -- no change to data, selection is reset
   check_nil(Editor_state.selection1.line, 'F - test_cursor_movement_without_shift_resets_selection')
-  check_eq(Editor_state.lines[1].data, 'abc', 'F - test_cursor_movement_without_shift_resets_selection/data')
+  check_eq(Editor_state.lines[1], 'abc', 'F - test_cursor_movement_without_shift_resets_selection/data')
 end
 
 function test_edit_deletes_selection()
@@ -647,7 +619,7 @@ function test_edit_deletes_selection()
   -- press a key
   edit.run_after_textinput(Editor_state, 'x')
   -- selected text is deleted and replaced with the key
-  check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_edit_deletes_selection')
+  check_eq(Editor_state.lines[1], 'xbc', 'F - test_edit_deletes_selection')
 end
 
 function test_edit_with_shift_key_deletes_selection()
@@ -670,7 +642,7 @@ function test_edit_with_shift_key_deletes_selection()
   App.fake_key_release('lshift')
   -- selected text is deleted and replaced with the key
   check_nil(Editor_state.selection1.line, 'F - test_edit_with_shift_key_deletes_selection')
-  check_eq(Editor_state.lines[1].data, 'Dbc', 'F - test_edit_with_shift_key_deletes_selection/data')
+  check_eq(Editor_state.lines[1], 'Dbc', 'F - test_edit_with_shift_key_deletes_selection/data')
 end
 
 function test_copy_does_not_reset_selection()
@@ -708,7 +680,7 @@ function test_cut()
   edit.run_after_keychord(Editor_state, 'C-x')
   check_eq(App.clipboard, 'a', 'F - test_cut/clipboard')
   -- selected text is deleted
-  check_eq(Editor_state.lines[1].data, 'bc', 'F - test_cut/data')
+  check_eq(Editor_state.lines[1], 'bc', 'F - test_cut/data')
 end
 
 function test_paste_replaces_selection()
@@ -729,7 +701,7 @@ function test_paste_replaces_selection()
   edit.run_after_keychord(Editor_state, 'C-v')
   -- selection is reset since shift key is not pressed
   -- selection includes the newline, so it's also deleted
-  check_eq(Editor_state.lines[1].data, 'xyzdef', 'F - test_paste_replaces_selection')
+  check_eq(Editor_state.lines[1], 'xyzdef', 'F - test_paste_replaces_selection')
 end
 
 function test_deleting_selection_may_scroll()
@@ -755,7 +727,7 @@ function test_deleting_selection_may_scroll()
   edit.run_after_keychord(Editor_state, 'backspace')
   -- page scrolls up
   check_eq(Editor_state.screen_top1.line, 1, 'F - test_deleting_selection_may_scroll')
-  check_eq(Editor_state.lines[1].data, 'ahi', 'F - test_deleting_selection_may_scroll/data')
+  check_eq(Editor_state.lines[1], 'ahi', 'F - test_deleting_selection_may_scroll/data')
 end
 
 function test_edit_wrapping_text()
@@ -821,8 +793,8 @@ function test_insert_newline_at_start_of_line()
   edit.run_after_keychord(Editor_state, 'return')
   check_eq(Editor_state.cursor1.line, 2, 'F - test_insert_newline_at_start_of_line/cursor:line')
   check_eq(Editor_state.cursor1.pos, 1, 'F - test_insert_newline_at_start_of_line/cursor:pos')
-  check_eq(Editor_state.lines[1].data, '', 'F - test_insert_newline_at_start_of_line/data:1')
-  check_eq(Editor_state.lines[2].data, 'abc', 'F - test_insert_newline_at_start_of_line/data:2')
+  check_eq(Editor_state.lines[1], '', 'F - test_insert_newline_at_start_of_line/data:1')
+  check_eq(Editor_state.lines[2], 'abc', 'F - test_insert_newline_at_start_of_line/data:2')
 end
 
 function test_insert_from_clipboard()
@@ -994,36 +966,6 @@ function test_pagedown()
   App.screen.check(y, 'ghi', 'F - test_pagedown/screen:2')
 end
 
-function test_pagedown_skips_drawings()
-  io.write('\ntest_pagedown_skips_drawings')
-  -- some lines of text with a drawing intermixed
-  local drawing_width = 50
-  App.screen.init{width=Editor_state.left+drawing_width, height=80}
-  Editor_state = edit.initialize_test_state()
-  Editor_state.lines = load_array{'abc',               -- height 15
-                                  '```lines', '```',   -- height 25
-                                  'def',               -- height 15
-                                  'ghi'}               -- height 15
-  Text.redraw_all(Editor_state)
-  check_eq(Editor_state.lines[2].mode, 'drawing', 'F - test_pagedown_skips_drawings/baseline/lines')
-  Editor_state.cursor1 = {line=1, pos=1}
-  Editor_state.screen_top1 = {line=1, pos=1}
-  Editor_state.screen_bottom1 = {}
-  local drawing_height = Drawing_padding_height + drawing_width/2  -- default
-  -- initially the screen displays the first line and the drawing
-  -- 15px margin + 15px line1 + 10px margin + 25px drawing + 10px margin = 75px < screen height 80px
-  edit.draw(Editor_state)
-  local y = Editor_state.top
-  App.screen.check(y, 'abc', 'F - test_pagedown_skips_drawings/baseline/screen:1')
-  -- after pagedown the screen draws the drawing up top
-  -- 15px margin + 10px margin + 25px drawing + 10px margin + 15px line3 = 75px < screen height 80px
-  edit.run_after_keychord(Editor_state, 'pagedown')
-  check_eq(Editor_state.screen_top1.line, 2, 'F - test_pagedown_skips_drawings/screen_top')
-  check_eq(Editor_state.cursor1.line, 3, 'F - test_pagedown_skips_drawings/cursor')
-  y = Editor_state.top + drawing_height
-  App.screen.check(y, 'def', 'F - test_pagedown_skips_drawings/screen:1')
-end
-
 function test_pagedown_often_shows_start_of_wrapping_line()
   io.write('\ntest_pagedown_often_shows_start_of_wrapping_line')
   -- draw a few lines ending in part of a wrapping line
@@ -1816,7 +1758,7 @@ function test_backspace_past_line_boundary()
   Editor_state.cursor1 = {line=2, pos=1}
   -- backspace joins with previous line
   edit.run_after_keychord(Editor_state, 'backspace')
-  check_eq(Editor_state.lines[1].data, 'abcdef', "F - test_backspace_past_line_boundary")
+  check_eq(Editor_state.lines[1], 'abcdef', "F - test_backspace_past_line_boundary")
 end
 
 -- some tests for operating over selections created using Shift- chords
@@ -1833,7 +1775,7 @@ function test_backspace_over_selection()
   Editor_state.selection1 = {line=1, pos=2}
   -- backspace deletes the selected character, even though it's after the cursor
   edit.run_after_keychord(Editor_state, 'backspace')
-  check_eq(Editor_state.lines[1].data, 'bc', "F - test_backspace_over_selection/data")
+  check_eq(Editor_state.lines[1], 'bc', "F - test_backspace_over_selection/data")
   -- cursor (remains) at start of selection
   check_eq(Editor_state.cursor1.line, 1, "F - test_backspace_over_selection/cursor:line")
   check_eq(Editor_state.cursor1.pos, 1, "F - test_backspace_over_selection/cursor:pos")
@@ -1852,7 +1794,7 @@ function test_backspace_over_selection_reverse()
   Editor_state.selection1 = {line=1, pos=1}
   -- backspace deletes the selected character
   edit.run_after_keychord(Editor_state, 'backspace')
-  check_eq(Editor_state.lines[1].data, 'bc', "F - test_backspace_over_selection_reverse/data")
+  check_eq(Editor_state.lines[1], 'bc', "F - test_backspace_over_selection_reverse/data")
   -- cursor moves to start of selection
   check_eq(Editor_state.cursor1.line, 1, "F - test_backspace_over_selection_reverse/cursor:line")
   check_eq(Editor_state.cursor1.pos, 1, "F - test_backspace_over_selection_reverse/cursor:pos")
@@ -1871,8 +1813,8 @@ function test_backspace_over_multiple_lines()
   Editor_state.selection1 = {line=4, pos=2}
   -- backspace deletes the region and joins the remaining portions of lines on either side
   edit.run_after_keychord(Editor_state, 'backspace')
-  check_eq(Editor_state.lines[1].data, 'akl', "F - test_backspace_over_multiple_lines/data:1")
-  check_eq(Editor_state.lines[2].data, 'mno', "F - test_backspace_over_multiple_lines/data:2")
+  check_eq(Editor_state.lines[1], 'akl', "F - test_backspace_over_multiple_lines/data:1")
+  check_eq(Editor_state.lines[2], 'mno', "F - test_backspace_over_multiple_lines/data:2")
   -- cursor remains at start of selection
   check_eq(Editor_state.cursor1.line, 1, "F - test_backspace_over_multiple_lines/cursor:line")
   check_eq(Editor_state.cursor1.pos, 2, "F - test_backspace_over_multiple_lines/cursor:pos")
@@ -1891,8 +1833,8 @@ function test_backspace_to_end_of_line()
   Editor_state.selection1 = {line=1, pos=4}
   -- backspace deletes rest of line without joining to any other line
   edit.run_after_keychord(Editor_state, 'backspace')
-  check_eq(Editor_state.lines[1].data, 'a', "F - test_backspace_to_start_of_line/data:1")
-  check_eq(Editor_state.lines[2].data, 'def', "F - test_backspace_to_start_of_line/data:2")
+  check_eq(Editor_state.lines[1], 'a', "F - test_backspace_to_start_of_line/data:1")
+  check_eq(Editor_state.lines[2], 'def', "F - test_backspace_to_start_of_line/data:2")
   -- cursor remains at start of selection
   check_eq(Editor_state.cursor1.line, 1, "F - test_backspace_to_start_of_line/cursor:line")
   check_eq(Editor_state.cursor1.pos, 2, "F - test_backspace_to_start_of_line/cursor:pos")
@@ -1911,8 +1853,8 @@ function test_backspace_to_start_of_line()
   Editor_state.selection1 = {line=2, pos=3}
   -- backspace deletes beginning of line without joining to any other line
   edit.run_after_keychord(Editor_state, 'backspace')
-  check_eq(Editor_state.lines[1].data, 'abc', "F - test_backspace_to_start_of_line/data:1")
-  check_eq(Editor_state.lines[2].data, 'f', "F - test_backspace_to_start_of_line/data:2")
+  check_eq(Editor_state.lines[1], 'abc', "F - test_backspace_to_start_of_line/data:1")
+  check_eq(Editor_state.lines[2], 'f', "F - test_backspace_to_start_of_line/data:2")
   -- cursor remains at start of selection
   check_eq(Editor_state.cursor1.line, 2, "F - test_backspace_to_start_of_line/cursor:line")
   check_eq(Editor_state.cursor1.pos, 1, "F - test_backspace_to_start_of_line/cursor:pos")
@@ -2008,7 +1950,7 @@ function test_undo_restores_selection()
   edit.draw(Editor_state)
   -- delete selected text
   edit.run_after_textinput(Editor_state, 'x')
-  check_eq(Editor_state.lines[1].data, 'xbc', 'F - test_undo_restores_selection/baseline')
+  check_eq(Editor_state.lines[1], 'xbc', 'F - test_undo_restores_selection/baseline')
   check_nil(Editor_state.selection1.line, 'F - test_undo_restores_selection/baseline:selection')
   -- undo
   edit.run_after_keychord(Editor_state, 'C-z')
@@ -2022,7 +1964,7 @@ function test_search()
   io.write('\ntest_search')
   App.screen.init{width=120, height=60}
   Editor_state = edit.initialize_test_state()
-  Editor_state.lines = load_array{'```lines', '```', 'def', 'ghi', 'deg'}
+  Editor_state.lines = load_array{'abc', 'def', 'ghi', 'deg'}
   Text.redraw_all(Editor_state)
   Editor_state.cursor1 = {line=1, pos=1}
   Editor_state.screen_top1 = {line=1, pos=1}