robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
22.0 KiB289 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local command = n.command
8local feed = n.feed
9local is_os = t.is_os
10
11describe(':Tutor', function()
12  local screen --- @type test.functional.ui.screen
13
14  before_each(function()
15    clear({ args = { '--clean' } })
16    command('set cmdheight=0')
17    command('Tutor')
18    screen = Screen.new(81, 30)
19    screen:set_default_attr_ids({
20      [0] = { foreground = Screen.colors.Blue4, background = Screen.colors.Grey },
21      [1] = { bold = true },
22      [2] = { underline = true, foreground = tonumber('0x0088ff') },
23      [3] = { foreground = Screen.colors.SlateBlue },
24      [4] = { bold = true, foreground = Screen.colors.Brown },
25      [5] = { bold = true, foreground = Screen.colors.Magenta1 },
26      [6] = { italic = true },
27      [7] = { foreground = tonumber('0x00ff88'), bold = true, background = Screen.colors.Grey },
28      [8] = { bold = true, foreground = Screen.colors.Blue },
29      [9] = { foreground = Screen.colors.Magenta1 },
30      [10] = { foreground = tonumber('0xff2000'), bold = true },
31      [11] = { foreground = tonumber('0xff2000'), bold = true, background = Screen.colors.Grey },
32      [12] = { foreground = tonumber('0x6a0dad') },
33    })
34  end)
35  it('applies {unix:…,win:…} transform', function()
36    local expected = is_os('win')
37        and [[
38      {0:  }^                                                                               |
39      {0:  } 3. To verify that a file was retrieved, cursor back and notice that there     |
40      {0:  }    are now two copies of Lesson 5.3, the original and the retrieved version.  |
41      {0:  }                                                                               |
42      {0:  }{1:NOTE}: You can also read the output of an external command. For example,        |
43      {0:  }                                                                               |
44      {0:  }        :r {4:!}dir                                                                |
45      {0:  }                                                                               |
46      {0:  }      reads the output of the ls command and puts it below the cursor.         |
47      {0:  }                                                                               |
48      {0:  }{3:#}{5: Lesson 5 SUMMARY}                                                             |
49      {0:  }                                                                               |
50      {0:  } 1. {2::!command} executes an external command.                                    |
51      {0:  }                                                                               |
52      {0:  }     Some useful examples are:                                                 |
53      {0:  }     :{4:!}dir                   - shows a directory listing                       |
54      {0:  }     :{4:!}del FILENAME          - removes file FILENAME                           |
55      {0:  }                                                                               |
56      {0:  } 2. {2::w} FILENAME              writes the current Neovim file to disk with       |
57      {0:  }                             name FILENAME.                                    |
58      {0:  }                                                                               |
59      {0:  } 3. {2:v}  motion  :w FILENAME   saves the Visually selected lines in file         |
60      {0:  }                             FILENAME.                                         |
61      {0:  }                                                                               |
62      {0:  } 4. {2::r} FILENAME              retrieves disk file FILENAME and puts it          |
63      {0:  }                             below the cursor position.                        |
64      {0:  }                                                                               |
65      {0:  } 5. {2::r !dir}                  reads the output of the dir command and           |
66      {0:  }                             puts it below the cursor position.                |
67      {0:  }                                                                               |
68    ]]
69      or [[
70      {0:  }^                                                                               |
71      {0:  } 3. To verify that a file was retrieved, cursor back and notice that there     |
72      {0:  }    are now two copies of Lesson 5.3, the original and the retrieved version.  |
73      {0:  }                                                                               |
74      {0:  }{1:NOTE}: You can also read the output of an external command. For example,        |
75      {0:  }                                                                               |
76      {0:  }        :r {4:!}ls                                                                 |
77      {0:  }                                                                               |
78      {0:  }      reads the output of the ls command and puts it below the cursor.         |
79      {0:  }                                                                               |
80      {0:  }{3:#}{5: Lesson 5 SUMMARY}                                                             |
81      {0:  }                                                                               |
82      {0:  } 1. {2::!command} executes an external command.                                    |
83      {0:  }                                                                               |
84      {0:  }     Some useful examples are:                                                 |
85      {0:  }     :{4:!}ls                    - shows a directory listing                       |
86      {0:  }     :{4:!}rm  FILENAME          - removes file FILENAME                           |
87      {0:  }                                                                               |
88      {0:  } 2. {2::w} FILENAME              writes the current Neovim file to disk with       |
89      {0:  }                             name FILENAME.                                    |
90      {0:  }                                                                               |
91      {0:  } 3. {2:v}  motion  :w FILENAME   saves the Visually selected lines in file         |
92      {0:  }                             FILENAME.                                         |
93      {0:  }                                                                               |
94      {0:  } 4. {2::r} FILENAME              retrieves disk file FILENAME and puts it          |
95      {0:  }                             below the cursor position.                        |
96      {0:  }                                                                               |
97      {0:  } 5. {2::r !ls}                   reads the output of the ls command and            |
98      {0:  }                             puts it below the cursor position.                |
99      {0:  }                                                                               |
100    ]]
101
102    feed(':702<CR>zt')
103    screen:expect(expected)
104  end)
105
106  it('applies hyperlink highlighting', function()
107    local expected = [[
108      {0:  }^This concludes Chapter 1 of the Vim Tutor.  Consider continuing with           |
109      {0:  }{2:Chapter 2}.                                                                     |
110      {0:  }                                                                               |
111      {0:  }This was intended to give a brief overview of the Neovim editor, just enough to|
112      {0:  }allow you to use it fairly easily. It is far from complete as Neovim has       |
113      {0:  }many many more commands. Consult the help often.                               |
114      {0:  }There are also countless great tutorials and videos to be found online.        |
115      {0:  }Here's a bunch of them:                                                        |
116      {0:  }                                                                               |
117      {0:  }- {6:Learn Vim Progressively}:                                                     |
118      {0:  }  {2:https://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/}            |
119      {0:  }- {6:Learning Vim in 2014}:                                                        |
120      {0:  }  {2:https://benmccormick.org/learning-vim-in-2014/}                               |
121      {0:  }- {6:Vimcasts}:                                                                    |
122      {0:  }  {2:http://vimcasts.org/}                                                         |
123      {0:  }- {6:Vim Video-Tutorials by Derek Wyatt}:                                          |
124      {0:  }  {2:http://derekwyatt.org/vim/tutorials/}                                         |
125      {0:  }- {6:Learn Vimscript the Hard Way}:                                                |
126      {0:  }  {2:https://learnvimscriptthehardway.stevelosh.com/}                              |
127      {0:  }- {6:7 Habits of Effective Text Editing}:                                          |
128      {0:  }  {2:https://www.moolenaar.net/habits.html}                                        |
129      {0:  }- {6:vim-galore}:                                                                  |
130      {0:  }  {2:https://github.com/mhinz/vim-galore}                                          |
131      {0:  }                                                                               |
132      {0:  }If you prefer a book, {6:Practical Vim} by Drew Neil is recommended often          |
133      {0:  }(the sequel, {6:Modern Vim}, includes material specific to Neovim).                |
134      {0:  }                                                                               |
135      {0:  }This tutorial was written by Michael C. Pierce and Robert K. Ware, Colorado    |
136      {0:  }School of Mines using ideas supplied by Charles Smith, Colorado State          |
137      {0:  }University. E-mail: {2:bware@mines.colorado.edu}.                                  |
138    ]]
139
140    feed(':983<CR>zt')
141    screen:expect(expected)
142  end)
143
144  it("removing a line doesn't affect highlight/mark of other lines", function()
145    -- Do lesson 2.6
146    feed(':294<CR>zt')
147    screen:expect([[
148      {0:  }{3:^#}{5: Lesson 2.6: OPERATING ON LINES}                                               |
149      {0:  }                                                                               |
150      {0:  }{1: Type }{4:dd}{1: to delete a whole line. }                                              |
151      {0:  }                                                                               |
152      {0:  }Due to the frequency of whole line deletion, the designers of Vi decided       |
153      {0:  }it would be easier to simply type two d's to delete a line.                    |
154      {0:  }                                                                               |
155      {0:  } 1. Move the cursor to the second line in the phrase below.                    |
156      {0:  }                                                                               |
157      {0:  } 2. Type {2:dd} to delete the line.                                                |
158      {0:  }                                                                               |
159      {0:  } 3. Now move to the fourth line.                                               |
160      {0:  }                                                                               |
161      {0:  } 4. Type {9:2}{4:dd} to delete two lines.                                              |
162      {0:  }                                                                               |
163      {7:✓ }{3:1)  Roses are red,                                                             }|
164      {11:✗ }{3:2)  Mud is fun,                                                                }|
165      {7:✓ }{3:3)  Violets are blue,                                                          }|
166      {11:✗ }{3:4)  I have a car,                                                              }|
167      {11:✗ }{3:5)  Clocks tell time,                                                          }|
168      {7:✓ }{3:6)  Sugar is sweet                                                             }|
169      {7:✓ }{3:7)  And so are you.                                                            }|
170      {0:  }                                                                               |
171      {0:  }{3:#}{5: Lesson 2.7: THE UNDO COMMAND}                                                 |
172      {0:  }                                                                               |
173      {0:  }{1: Press }{4:u}{1: to undo the last commands, }{4:U}{1: to fix a whole line. }                    |
174      {0:  }                                                                               |
175      {0:  } 1. Move the cursor to the line below marked {10:✗} and place it on the first error.|
176      {0:  }                                                                               |
177      {0:  } 2. Type {4:x} to delete the first unwanted character.                             |
178]])
179
180    feed('<Cmd>310<CR>dd<Cmd>311<CR>2dd')
181    screen:expect([[
182      {0:  }{3:#}{5: Lesson 2.6: OPERATING ON LINES}                                               |
183      {0:  }                                                                               |
184      {0:  }{1: Type }{4:dd}{1: to delete a whole line. }                                              |
185      {0:  }                                                                               |
186      {0:  }Due to the frequency of whole line deletion, the designers of Vi decided       |
187      {0:  }it would be easier to simply type two d's to delete a line.                    |
188      {0:  }                                                                               |
189      {0:  } 1. Move the cursor to the second line in the phrase below.                    |
190      {0:  }                                                                               |
191      {0:  } 2. Type {2:dd} to delete the line.                                                |
192      {0:  }                                                                               |
193      {0:  } 3. Now move to the fourth line.                                               |
194      {0:  }                                                                               |
195      {0:  } 4. Type {9:2}{4:dd} to delete two lines.                                              |
196      {0:  }                                                                               |
197      {7:✓ }{3:1)  Roses are red,                                                             }|
198      {7:✓ }{3:3)  Violets are blue,                                                          }|
199      {7:✓ }{3:^6)  Sugar is sweet                                                             }|
200      {7:✓ }{3:7)  And so are you.                                                            }|
201      {0:  }                                                                               |
202      {0:  }{3:#}{5: Lesson 2.7: THE UNDO COMMAND}                                                 |
203      {0:  }                                                                               |
204      {0:  }{1: Press }{4:u}{1: to undo the last commands, }{4:U}{1: to fix a whole line. }                    |
205      {0:  }                                                                               |
206      {0:  } 1. Move the cursor to the line below marked {10:✗} and place it on the first error.|
207      {0:  }                                                                               |
208      {0:  } 2. Type {4:x} to delete the first unwanted character.                             |
209      {0:  }                                                                               |
210      {0:  } 3. Now type {4:u} to undo the last command executed.                              |
211      {0:  }                                                                               |
212    ]])
213  end)
214
215  it("inserting text at start of line doesn't affect highlight/sign", function()
216    -- Go to lesson 1.3 and make it top line in the window
217    feed('<Cmd>92<CR>zt')
218    screen:expect([[
219      {0:  }{3:^#}{5: Lesson 1.3: TEXT EDITING: DELETION}                                           |
220      {0:  }                                                                               |
221      {0:  }{1: Press }{4:x}{1: to delete the character under the cursor. }                            |
222      {0:  }                                                                               |
223      {0:  } 1. Move the cursor to the line below marked {10:✗}.                                |
224      {0:  }                                                                               |
225      {0:  } 2. To fix the errors, move the cursor until it is on top of the               |
226      {0:  }    character to be deleted.                                                   |
227      {0:  }                                                                               |
228      {0:  } 3. Press {2:the x key} to delete the unwanted character.                          |
229      {0:  }                                                                               |
230      {0:  } 4. Repeat steps 2 through 4 until the sentence is correct.                    |
231      {0:  }                                                                               |
232      {11:✗ }{3:The ccow jumpedd ovverr thhe mooon.                                            }|
233      {0:  }                                                                               |
234      {0:  } 5. Now that the line is correct, go on to Lesson 1.4.                         |
235      {0:  }                                                                               |
236      {0:  }{1:NOTE}: As you go through this tutorial, do not try to memorize everything,      |
237      {0:  }      your Neovim vocabulary will expand with usage. Consider returning to     |
238      {0:  }      this tutorial periodically for a refresher.                              |
239      {0:  }                                                                               |
240      {0:  }{3:#}{5: Lesson 1.4: TEXT EDITING: INSERTION}                                          |
241      {0:  }                                                                               |
242      {0:  }{1: Press }{12:i}{1: to insert text. }                                                      |
243      {0:  }                                                                               |
244      {0:  } 1. Move the cursor to the first line below marked {10:✗}.                          |
245      {0:  }                                                                               |
246      {0:  } 2. To make the first line the same as the second, move the cursor on top      |
247      {0:  }    of the first character AFTER where the text is to be inserted.             |
248      {0:  }                                                                               |
249    ]])
250    -- Go to the test line and insert text at the start of the line
251    feed('<Cmd>105<CR>iThe <Esc>')
252    -- Remove redundant characters
253    feed('fcxfdxfvxfrxfhxfox')
254    -- Remove the original "The " text (not the just-inserted one)
255    feed('^4ldw^')
256    screen:expect([[
257      {0:  }{3:#}{5: Lesson 1.3: TEXT EDITING: DELETION}                                           |
258      {0:  }                                                                               |
259      {0:  }{1: Press }{4:x}{1: to delete the character under the cursor. }                            |
260      {0:  }                                                                               |
261      {0:  } 1. Move the cursor to the line below marked {10:✗}.                                |
262      {0:  }                                                                               |
263      {0:  } 2. To fix the errors, move the cursor until it is on top of the               |
264      {0:  }    character to be deleted.                                                   |
265      {0:  }                                                                               |
266      {0:  } 3. Press {2:the x key} to delete the unwanted character.                          |
267      {0:  }                                                                               |
268      {0:  } 4. Repeat steps 2 through 4 until the sentence is correct.                    |
269      {0:  }                                                                               |
270      {7:✓ }{3:^The cow jumped over the moon.                                                  }|
271      {0:  }                                                                               |
272      {0:  } 5. Now that the line is correct, go on to Lesson 1.4.                         |
273      {0:  }                                                                               |
274      {0:  }{1:NOTE}: As you go through this tutorial, do not try to memorize everything,      |
275      {0:  }      your Neovim vocabulary will expand with usage. Consider returning to     |
276      {0:  }      this tutorial periodically for a refresher.                              |
277      {0:  }                                                                               |
278      {0:  }{3:#}{5: Lesson 1.4: TEXT EDITING: INSERTION}                                          |
279      {0:  }                                                                               |
280      {0:  }{1: Press }{12:i}{1: to insert text. }                                                      |
281      {0:  }                                                                               |
282      {0:  } 1. Move the cursor to the first line below marked {10:✗}.                          |
283      {0:  }                                                                               |
284      {0:  } 2. To make the first line the same as the second, move the cursor on top      |
285      {0:  }    of the first character AFTER where the text is to be inserted.             |
286      {0:  }                                                                               |
287    ]])
288  end)
289end)