[RFC] Add legacy test conversion script.

I originally wanted to post this as a comment to #1286, but I suppose even if all legacy tests are converted at some point, new ones will be added because of upstream patches. Therefore it might be helpful to have this in the repository.

The output is not indented etc, but it can serve as a starting point for a proper spec.

Example output: `./scripts/legacy2luatest.sh src/nvim/testdir/test1.in test/functional/legacy` (written to `test/functional/legacy/test1_spec.lua`).

```lua
-- First a simple test to check if the test script works.
-- If Vim was not compiled with the +eval feature, the small.vim script will be
-- set to copy the test.ok file to test.out, so that it looks like the test
-- succeeded.  Otherwise an empty small.vim is written.  small.vim is sourced by
-- tests that require the +eval feature or other features that are missing in the
-- small version.
-- If Vim was not compiled with the +windows feature, the tiny.vim script will be
-- set like small.vim above.  tiny.vim is sourced by tests that require the
-- +windows feature or other features that are missing in the tiny version.
-- If Vim was not compiled with the +multi_byte feature, the mbyte.vim script will
-- be set like small.vim above.  mbyte.vim is sourced by tests that require the
-- +multi_byte feature.
-- Similar logic is applied to the +mzscheme feature, using mzscheme.vim.
-- Similar logic is applied to the +lua feature, using lua.vim.

local helpers = require('test.functional.helpers')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local execute, expect = helpers.execute, helpers.expect

describe('test1', function()
  setup(clear)

  it('is working', function()
  -- If columns or lines are too small, create wrongtermsize.
-- (Some tests will fail. When columns and/or lines are small)
feed(':if &lines < 24 || &columns < 80 | sp another | w! wrongtermsize | qa! | endif')

-- Write a single line to test.out to check if testing works at all.
feed(':%d')
feed('athis is a test^[:w! test.out')
-- Create small.vim and tiny.vim empty, create mbyte.vim to skip the test.
feed('0D:w! small.vim')
feed(':w! tiny.vim')
feed('ae! test.ok')
feed('w! test.out')
feed('qa!')
feed('^[:w! mbyte.vim')
feed(':w! mzscheme.vim')
feed(':w! lua.vim')

-- If +multi_byte feature supported, make mbyte.vim empty.
feed(':if has("multi_byte") | sp another | w! mbyte.vim | q | endif')

-- If +mzscheme feature supported, make mzscheme.vim empty.
feed(':if has("mzscheme") | sp another | w! mzscheme.vim | q | endif')

-- If +lua feature supported, make lua.vim empty.
feed(':if has("lua") | sp another | w! lua.vim | q | endif')

-- If +eval feature supported quit here, leaving tiny.vim and small.vim empty.
-- Otherwise write small.vim to skip the test.
feed(':if 1 | q! | endif')
feed(':w! small.vim')
-- If +windows feature not supported :sp will fail and tiny.vim will be
-- written to skip the test.
feed(':sp another')
feed(':wq! tiny.vim')
feed(':qa!')

-- The buffer should now contain:
expect([[this is a test]])
  end)
end)
```
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On October 19, 2014 2:02:52 AM GMT+03:00, Florian Walch <notifications@github.com> wrote:
>> +      # Extract possible in-line comment.
>> +      if [[ "${line}" == *\"* ]]; then
>> +        # Extract comment and remove possible prepended
>whitespace/trailing period.
>> +        local comment="$(cut -d '"' -f 2 <<< "${line}" | sed -e 's/
>*//' -e 's/\.$//')"
>> +
>> +        # Capitalize first character and emit as Lua comment.
>> +        echo "-- ${comment^}."
>> +
>> +        # Remove comment and trailing whitespace from line.
>> +        line="$(cut -d '"' -f 1 <<< "${line}" | sed 's/ *$//')"
>> +      fi
>> +
>> +      # Emit 'feed' if not a search ('/') or ex (':') command.
>> +      if [[ "${line}" != :* && "${line}" != /* ]]; then
>> +        # Replace terminal escape characters with <esc>.
>> +        line="${line///\<esc\>}"
>
>I just copied the control characters out of an existing Vim test file,
>that's why it looks like this. Thanks for the alternatives, I'll use
>one of these instead.
>
>I'll try the script on Ubuntu (where `sh` is `dash`, I think); if it
>works, I'll set the hashbang to `sh`.

Don't. I can say for sure it will not: ' <<< "${line}"' is a bash/zsh specific, double square brackets also are. I would actually suggest using Perl because text processing is out of the scope of bash responsibilities. Even lua would be better.

In any case you *must* use at least zsh because there is at least one test file which contains NUL in their line and you cannot have NUL in bash variable value.

>
>---
>Reply to this email directly or view it on GitHub:
>https://github.com/neovim/neovim/pull/1287/files#r19056544

-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQJNBAEBCgA3BQJUQ4DvMBwfMDI7PjIgHTg6PjswOSAQOzU6QTA9NEA+MjhHIDxr
cC1wYXZAeWFuZGV4LnJ1PgAKCRBu+P2/AXZZImW0D/9yPbn30w0aU3M1rLPwXPkK
FgLUqLSFkEMnDI700tYVE8NrV0SikmJNzO6YYOcgX5tWB9/zTf9rVsKkzBMQh+d0
G+vdYe8TGAZv5+7lg20rtLc8+HB9gHDLJOLV5p/qkp+yWULFokkjM/t0cBQnXPPW
iS3qQCB99X3uvkvGHo4TLRvKaJKPq8jwkP61BSnXGwDeDuxIFKWdVgpNzm2EKVES
gtK5/s25Iegk4M0aNa0xt5Wi7gPlRIrV557PnwmaWOdAmU5L3mmM+XlarY5Wfq9A
1G35Ak0zjzPq2XQRjWkTUDQTKkcEL1JHsTani4+S5zDF6rffm7Cql6CnHi5hdfd8
gGC9Xhtv0Qar2pCiwG2yKMijcw8hhX3JxQS9zn2zugkCf9iiaj7o9QqCxUNTd08Z
SV/ie4Ug3DsXF1ZciJ+wkfHBFJZKeeq2674ts4zMThRZPs9K83gI7Xcoq7XALjIi
TeTtxiJC+sRh5E3eFkgi4fWv5PY2XvDp4ZnI85m7TiYaIkZLI3AYzZ9r+/6fE+3Z
mFOZHW3pnVVHbtAULWk2zw9EWTovxa3/EaR/tPcnSgGPA+JyDA2J0NTSgQTyk2Br
X6rOYk0e4jcmggRhrAxHtnru4ljOPtI6QtspmNghyUSI6L08VfUPR0151tYVBjiX
2zCimFZAaP+fQDNiFefhpA==
=NaXL
-----END PGP SIGNATURE-----