Fortran · 7359 bytes Raw Blame History
1 program test_enhanced_features
2 use test_framework
3 use test_driver_module
4 use text_buffer_module
5 use editor_state_module
6 implicit none
7
8 type(test_suite) :: suite
9 type(test_case), allocatable :: tests(:)
10
11 ! Define test suite
12 suite%name = "Enhanced Features Tests"
13
14 ! Allocate and configure tests
15 allocate(tests(8))
16
17 tests(1)%name = "Auto-close brackets"
18 tests(1)%test_procedure => test_auto_close_brackets
19
20 tests(2)%name = "Auto-close quotes"
21 tests(2)%test_procedure => test_auto_close_quotes
22
23 tests(3)%name = "Tab indents selection"
24 tests(3)%test_procedure => test_tab_indent
25
26 tests(4)%name = "Shift-Tab dedents selection"
27 tests(4)%test_procedure => test_shift_tab_dedent
28
29 tests(5)%name = "Join lines"
30 tests(5)%test_procedure => test_join_lines
31
32 tests(6)%name = "Transpose characters"
33 tests(6)%test_procedure => test_transpose
34
35 tests(7)%name = "Kill and yank line"
36 tests(7)%test_procedure => test_kill_yank
37
38 tests(8)%name = "Undo and redo"
39 tests(8)%test_procedure => test_undo_redo
40
41 suite%tests = tests
42
43 ! Run the test suite
44 call run_tests(suite)
45
46 contains
47
48 subroutine test_auto_close_brackets()
49 type(editor_state_t) :: editor
50 type(buffer_t) :: buffer
51
52 call create_test_editor(editor, buffer)
53
54 ! Test parentheses
55 call simulate_typing(editor, buffer, "(")
56 call assert_buffer_equals(buffer, "()", "Auto-close parentheses")
57 call assert_cursor_at(editor, 1, 2, "Cursor between parens")
58
59 ! Type inside the parens
60 call simulate_typing(editor, buffer, "test")
61 call assert_buffer_equals(buffer, "(test)", "Text inside parens")
62
63 ! Test square brackets
64 call simulate_key(editor, buffer, "end") ! Move to end
65 call simulate_typing(editor, buffer, "[")
66 call assert_buffer_equals(buffer, "(test)[]", "Auto-close brackets")
67
68 ! Test curly braces
69 call simulate_typing(editor, buffer, "x") ! Type between brackets
70 call simulate_key(editor, buffer, "end")
71 call simulate_typing(editor, buffer, "{")
72 call assert_buffer_equals(buffer, "(test)[x]{}", "Auto-close braces")
73
74 call destroy_test_editor(editor, buffer)
75 end subroutine test_auto_close_brackets
76
77 subroutine test_auto_close_quotes()
78 type(editor_state_t) :: editor
79 type(buffer_t) :: buffer
80
81 call create_test_editor(editor, buffer)
82
83 ! Test double quotes
84 call simulate_typing(editor, buffer, '"')
85 call assert_buffer_equals(buffer, '""', "Auto-close double quotes")
86 call assert_cursor_at(editor, 1, 2, "Cursor between quotes")
87
88 call simulate_typing(editor, buffer, "hello")
89 call assert_buffer_equals(buffer, '"hello"', "Text in quotes")
90
91 ! Test single quotes
92 call simulate_key(editor, buffer, "end")
93 call simulate_typing(editor, buffer, " ")
94 call simulate_typing(editor, buffer, "'")
95 call assert_buffer_equals(buffer, '"hello" ' // "''", "Auto-close single quotes")
96
97 call destroy_test_editor(editor, buffer)
98 end subroutine test_auto_close_quotes
99
100 subroutine test_tab_indent()
101 type(editor_state_t) :: editor
102 type(buffer_t) :: buffer
103
104 ! Create multi-line text
105 call create_test_editor(editor, buffer, "Line 1" // char(10) // "Line 2" // char(10) // "Line 3")
106
107 ! Select lines 2 and 3
108 editor%cursors(1)%line = 2
109 editor%cursors(1)%column = 1
110 editor%cursors(1)%has_selection = .true.
111 editor%cursors(1)%selection_start_line = 2
112 editor%cursors(1)%selection_start_col = 1
113 editor%cursors(1)%line = 3
114 editor%cursors(1)%column = 7 ! End of "Line 3"
115
116 ! Tab to indent
117 call simulate_key(editor, buffer, "tab")
118
119 call assert_line_equals(buffer, 1, "Line 1", "Line 1 unchanged")
120 call assert_line_equals(buffer, 2, " Line 2", "Line 2 indented")
121 call assert_line_equals(buffer, 3, " Line 3", "Line 3 indented")
122
123 call destroy_test_editor(editor, buffer)
124 end subroutine test_tab_indent
125
126 subroutine test_shift_tab_dedent()
127 type(editor_state_t) :: editor
128 type(buffer_t) :: buffer
129
130 ! Create indented text
131 call create_test_editor(editor, buffer, " Line 1" // char(10) // " Line 2")
132
133 ! Select both lines
134 editor%cursors(1)%has_selection = .true.
135 editor%cursors(1)%selection_start_line = 1
136 editor%cursors(1)%selection_start_col = 1
137 editor%cursors(1)%line = 2
138 editor%cursors(1)%column = 11
139
140 ! Shift-Tab to dedent
141 call simulate_key(editor, buffer, "shift-tab")
142
143 call assert_line_equals(buffer, 1, "Line 1", "Line 1 dedented")
144 call assert_line_equals(buffer, 2, "Line 2", "Line 2 dedented")
145
146 call destroy_test_editor(editor, buffer)
147 end subroutine test_shift_tab_dedent
148
149 subroutine test_join_lines()
150 type(editor_state_t) :: editor
151 type(buffer_t) :: buffer
152
153 call create_test_editor(editor, buffer, "Hello" // char(10) // " World")
154
155 ! Join the lines
156 call simulate_key(editor, buffer, "ctrl-j")
157
158 call assert_buffer_equals(buffer, "Hello World", "Lines joined with space")
159 call assert_cursor_at(editor, 1, 1, "Cursor position maintained")
160
161 call destroy_test_editor(editor, buffer)
162 end subroutine test_join_lines
163
164 subroutine test_transpose()
165 type(editor_state_t) :: editor
166 type(buffer_t) :: buffer
167
168 call create_test_editor(editor, buffer, "Hello")
169 editor%cursors(1)%column = 3 ! Between 'e' and 'l'
170
171 call simulate_key(editor, buffer, "ctrl-t")
172
173 call assert_buffer_equals(buffer, "Hlelo", "Characters transposed")
174 call assert_cursor_at(editor, 1, 4, "Cursor moved forward")
175
176 call destroy_test_editor(editor, buffer)
177 end subroutine test_transpose
178
179 subroutine test_kill_yank()
180 type(editor_state_t) :: editor
181 type(buffer_t) :: buffer
182
183 call create_test_editor(editor, buffer, "Hello World")
184 editor%cursors(1)%column = 6 ! After "Hello"
185
186 ! Kill to end of line
187 call simulate_key(editor, buffer, "ctrl-k")
188 call assert_buffer_equals(buffer, "Hello", "Kill line forward")
189
190 ! Move to beginning and yank
191 call simulate_key(editor, buffer, "home")
192 call simulate_key(editor, buffer, "ctrl-y")
193 call assert_buffer_equals(buffer, " WorldHello", "Yanked text")
194
195 call destroy_test_editor(editor, buffer)
196 end subroutine test_kill_yank
197
198 subroutine test_undo_redo()
199 type(editor_state_t) :: editor
200 type(buffer_t) :: buffer
201
202 call create_test_editor(editor, buffer)
203
204 ! Type some text
205 call simulate_typing(editor, buffer, "Hello")
206 call assert_buffer_equals(buffer, "Hello", "Initial text")
207
208 ! Undo
209 call simulate_key(editor, buffer, "ctrl-z")
210 call assert_buffer_equals(buffer, "", "Undo typing")
211
212 ! Redo
213 call simulate_key(editor, buffer, "ctrl-shift-z")
214 call assert_buffer_equals(buffer, "Hello", "Redo typing")
215
216 call destroy_test_editor(editor, buffer)
217 end subroutine test_undo_redo
218
219 end program test_enhanced_features