neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

tutor_spec.lua (22427B)


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