about summary refs log tree commit diff stats
path: root/source_text_tests.lua
diff options
context:
space:
mode:
Diffstat (limited to 'source_text_tests.lua')
-rw-r--r--source_text_tests.lua85
1 files changed, 85 insertions, 0 deletions
diff --git a/source_text_tests.lua b/source_text_tests.lua
index 11e7613..c2e054a 100644
--- a/source_text_tests.lua
+++ b/source_text_tests.lua
@@ -1,4 +1,6 @@
 -- major tests for text editing flows
+-- Arguably this should be called source_edit_tests.lua,
+-- but that would mess up the git blame at this point.
 
 function test_initial_state()
   App.screen.init{width=120, height=60}
@@ -828,6 +830,67 @@ function test_select_text_using_mouse()
   check_eq(Editor_state.cursor1.pos, 4, 'cursor:pos')
 end
 
+function test_select_text_using_mouse_starting_above_text()
+  App.screen.init{width=50, height=60}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc', 'def', 'xyz'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=1}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  Editor_state.selection1 = {}
+  edit.draw(Editor_state)  -- populate line_cache.starty for each line Editor_state.line_cache
+  -- press mouse above first line of text
+  edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
+  check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
+  check_eq(Editor_state.selection1.line, 1, 'selection:line')
+  check_eq(Editor_state.selection1.pos, 1, 'selection:pos')
+end
+
+function test_select_text_using_mouse_starting_above_text_wrapping_line()
+  -- first screen line starts in the middle of a line
+  App.screen.init{width=50, height=60}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc', 'defgh', 'xyz'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=2, pos=5}
+  Editor_state.screen_top1 = {line=2, pos=3}
+  Editor_state.screen_bottom1 = {}
+  -- press mouse above first line of text
+  edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
+  -- selection is at screen top
+  check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
+  check_eq(Editor_state.selection1.line, 2, 'selection:line')
+  check_eq(Editor_state.selection1.pos, 3, 'selection:pos')
+end
+
+function test_select_text_using_mouse_starting_below_text()
+  -- I'd like to test what happens when a mouse click is below some page of
+  -- text, potentially even in the middle of a line.
+  -- However, it's brittle to set up a text line boundary just right.
+  -- So I'm going to just check things below the bottom of the final line of
+  -- text when it's in the middle of the screen.
+  -- final screen line ends in the middle of screen
+  App.screen.init{width=50, height=60}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abcde'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=1}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  edit.draw(Editor_state)
+  local y = Editor_state.top
+  App.screen.check(y, 'ab', 'baseline:screen:1')
+  y = y + Editor_state.line_height
+  App.screen.check(y, 'cde', 'baseline:screen:2')
+  -- press mouse above first line of text
+  edit.run_after_mouse_press(Editor_state, 5,App.screen.height-5, 1)
+  -- selection is past bottom-most text in screen
+  check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
+  check_eq(Editor_state.selection1.line, 1, 'selection:line')
+  check_eq(Editor_state.selection1.pos, 6, 'selection:pos')
+end
+
 function test_select_text_using_mouse_and_shift()
   App.screen.init{width=50, height=60}
   Editor_state = edit.initialize_test_state()
@@ -882,6 +945,28 @@ function test_select_text_repeatedly_using_mouse_and_shift()
   check_eq(Editor_state.cursor1.pos, 2, 'cursor:pos')
 end
 
+function test_select_all_text()
+  -- display a single line of text
+  App.screen.init{width=75, height=80}
+  Editor_state = edit.initialize_test_state()
+  Editor_state.lines = load_array{'abc def'}
+  Text.redraw_all(Editor_state)
+  Editor_state.cursor1 = {line=1, pos=1}
+  Editor_state.screen_top1 = {line=1, pos=1}
+  Editor_state.screen_bottom1 = {}
+  edit.draw(Editor_state)
+  -- select all
+  App.fake_key_press('lctrl')
+  edit.run_after_keychord(Editor_state, 'C-a')
+  App.fake_key_release('lctrl')
+  edit.key_release(Editor_state, 'lctrl')
+  -- selection
+  check_eq(Editor_state.selection1.line, 1, 'selection:line')
+  check_eq(Editor_state.selection1.pos, 1, 'selection:pos')
+  check_eq(Editor_state.cursor1.line, 1, 'cursor:line')
+  check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos')
+end
+
 function test_cut_without_selection()
   -- display a few lines
   App.screen.init{width=Editor_state.left+30, height=60}
;' href='/akkartik/mu/commit/shell/data.limg?h=hlt&id=380837ac2abe494fc88647e71d4ae969ef5ad1e6'>380837ac ^
dd192dd5 ^



380837ac ^

a54c6f2e ^
d605ba1f ^




a54c6f2e ^
d605ba1f ^
380837ac ^

e42ae821 ^










35336a5f ^
e42ae821 ^

35336a5f ^
e42ae821 ^
35336a5f ^
e42ae821 ^

35336a5f ^
380837ac ^

665b1e8f ^

650f417d ^
380837ac ^

35336a5f ^
18301077 ^
35336a5f ^
18301077 ^
35336a5f ^
18301077 ^
35336a5f ^
18301077 ^
35336a5f ^
18301077 ^
35336a5f ^
18301077 ^
35336a5f ^
18301077 ^
35336a5f ^
18301077 ^
35336a5f ^
18301077 ^
380837ac ^

18301077 ^







380837ac ^




fa8d337d ^
35336a5f ^
fa8d337d ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137