diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-06-14 09:26:18 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-06-14 09:26:18 -0700 |
commit | cf38c26bc1025e77dd937b539bd88e6ea20649ac (patch) | |
tree | 6cae77083af553046c6f12b1fa96dec5cf1e0433 | |
parent | c1d8201d4436b7d2544b79dbe0465558f887fd18 (diff) | |
download | text.love-cf38c26bc1025e77dd937b539bd88e6ea20649ac.tar.gz |
lots more tests
I've been adding diligently to manual_tests but not actually _performing_ any manual tests before releases. They were just a todo list of automated tests to write, and long out of date. Now the list is up to date and much shorter.
-rw-r--r-- | manual_tests | 32 | ||||
-rw-r--r-- | text_tests.lua | 65 |
2 files changed, 65 insertions, 32 deletions
diff --git a/manual_tests b/manual_tests index 4fbe02d..b85e6a1 100644 --- a/manual_tests +++ b/manual_tests @@ -5,47 +5,15 @@ For example, string.sub should never use a _pos to substring, only an _offset. Wish I had some static typing here. We're not going to try to write tests to catch issues like this. -- manual tests -file load: - cursor_line = 1 - first line is a drawing -> cursor_line = 2 -click on text -> cursor moves -click on first character of text -> cursor on first character of text -click to right of text -> cursor past end of line -click to right of wrapped text -> cursor on final character of line -click on drawing -> cursor doesn't move -cursor past end of line -> renders -create drawing -> cursor bumps down below drawing -backspace - cursor_pos == 0, previous line is a drawing -> delete drawing, cursor still visible at start of line - cursor_pos == 0, previous line is text -> join lines, cursor still at same character - drawing draw a line, circle, rectangle, square, polygon select a point and move it select a point and name it -enter - cursor_pos == 0 -> insert empty line above current line - -scrolling: - given moby dick, a file containing all text: - page up moves top line on screen to bottom - page down moves bottom line on screen to top - cursor remains on screen - cursor remains on text line - 'up' arrow with cursor at top of screen scrolls up one line (drawings still fully in or out) - if cursor line wrapped before, it scrolls up by only one screen line - if previous line (above top of screen) wrapped, it scrolls up by only one screen line - 'down' arrow with cursor at bottom of screen scrolls down one line (drawings still fully in or out) - if cursor line wrapped before, it scrolls down by only one screen line - persistence: draw a line, circle, rectangle, square, polygon, quit, restart. All the shapes you drew should still be visible. select a point and name it, quit, restart. Name is still visible. -clipboard: - cut/copy without making a selection - resize: create a file containing a long line of characters without spaces. try resizing the window vertically and horizontally, as far as possible. diff --git a/text_tests.lua b/text_tests.lua index c75458d..9eeb7d6 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -1,6 +1,42 @@ -- major tests for text editing flows -- This still isn't quite as thorough as I'd like. +function test_initial_state() + io.write('\ntest_initial_state') + App.screen.init{width=120, height=60} + Lines = load_array{} + App.draw() + check_eq(#Lines, 1, 'F - test_initial_state/#lines') + check_eq(Cursor1.line, 1, 'F - test_initial_state/cursor:line') + check_eq(Cursor1.pos, 1, 'F - test_initial_state/cursor:pos') + check_eq(Screen_top1.line, 1, 'F - test_initial_state/screen_top:line') + check_eq(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} + Lines = load_array{} + App.draw() + App.run_after_mouse_click(8,Margin_top+8, 1) + -- cursor skips drawing to always remain on text + check_eq(#Lines, 2, 'F - test_click_to_create_drawing/#lines') + check_eq(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} + Lines = load_array{'```lines', '```', ''} + -- cursor is on text as always (outside tests this will get initialized correctly) + Cursor1.line = 2 + -- backspacing deletes the drawing + App.run_after_keychord('backspace') + check_eq(#Lines, 1, 'F - test_backspace_to_delete_drawing/#lines') + check_eq(Cursor1.line, 1, 'F - test_backspace_to_delete_drawing/cursor') +end + function test_insert_first_character() io.write('\ntest_insert_first_character') App.screen.init{width=120, height=60} @@ -202,6 +238,23 @@ function test_insert_newline() App.screen.check(y, 'def', 'F - test_insert_newline/screen:3') end +function test_insert_newline_at_start_of_line() + io.write('\ntest_insert_newline_at_start_of_line') + -- display a line + App.screen.init{width=25+30, height=60} + Lines = load_array{'abc'} + Line_width = App.screen.width + Cursor1 = {line=1, pos=1} + Screen_top1 = {line=1, pos=1} + Screen_bottom1 = {} + -- hitting the enter key splits the line + App.run_after_keychord('return') + check_eq(Cursor1.line, 2, 'F - test_insert_newline_at_start_of_line/cursor:line') + check_eq(Cursor1.pos, 1, 'F - test_insert_newline_at_start_of_line/cursor:pos') + check_eq(Lines[1].data, '', 'F - test_insert_newline_at_start_of_line/data:1') + check_eq(Lines[2].data, 'abc', 'F - test_insert_newline_at_start_of_line/data:2') +end + function test_insert_from_clipboard() io.write('\ntest_insert_from_clipboard') -- display a few lines @@ -1017,6 +1070,18 @@ function test_backspace_can_scroll_up_screen_line() check_eq(Cursor1.pos, 4, 'F - test_backspace_can_scroll_up_screen_line/cursor:pos') end +function test_backspace_past_line_boundary() + io.write('\ntest_backspace_past_line_boundary') + -- position cursor at start of a (non-first) line + App.screen.init{width=25+30, height=60} + Lines = load_array{'abc', 'def'} + Line_width = App.screen.width + Cursor1 = {line=2, pos=1} + -- backspace joins with previous line + App.run_after_keychord('backspace') + check_eq(Lines[1].data, 'abcdef', "F - test_backspace_past_line_boundary") +end + -- some tests for operating over selections created using Shift- chords -- we're just testing delete_selection, and it works the same for all keys |