Mercurial > vim
view src/testdir/test_indent.vim @ 32721:94f4a488412e v9.0.1683
Updated runtime files
Commit: https://github.com/vim/vim/commit/6efb1980336ff324e9c57a4e282530b952fca816
Author: Christian Brabandt <cb@256bit.org>
Date: Thu Aug 10 05:44:25 2023 +0200
Updated runtime files
This is a collection of various PRs from github that all require a minor
patch number:
1) https://github.com/vim/vim/pull/12612
Do not conflate dictionary key with end of block
2) https://github.com/vim/vim/pull/12729:
When saving and restoring 'undolevels', the constructs `&undolevels` and
`:set undolevels` are problematic.
The construct `&undolevels` reads an unpredictable value; it will be the
local option value (if one has been set), or the global option value
(otherwise), making it unsuitable for saving a value for later
restoration.
Similarly, if a local option value has been set for 'undolevels',
temporarily modifying the option via `:set undolevels` changes the local
value as well as the global value, requiring extra work to restore both
values.
Saving and restoring the option value in one step via the construct
`:let &undolevels = &undolevels` appears to make no changes to the
'undolevels' option, but if a local option has been set to a different
value than the global option, it has the unintended effect of changing
the global 'undolevels' value to the local value.
Update the documentation to explain these issues and recommend explicit
use of global and local option values when saving and restoring. Update
some unit tests to use `g:undolevels`.
3) https://github.com/vim/vim/pull/12702:
Problem: Pip requirements files are not recognized.
Solution: Add a pattern to match pip requirements files.
4) https://github.com/vim/vim/pull/12688:
Add indent file and tests for ABB Rapid
5) https://github.com/vim/vim/pull/12668:
Use Lua 5.1 numeric escapes in tests and add to CI
Only Lua 5.2+ and LuaJIT understand hexadecimal escapes in strings. Lua
5.1 only supports decimal escapes:
> A character in a string can also be specified by its numerical value
> using the escape sequence \ddd, where ddd is a sequence of up to three
> decimal digits. (Note that if a numerical escape is to be followed by a
> digit, it must be expressed using exactly three digits.) Strings in Lua
> can contain any 8-bit value, including embedded zeros, which can be
> specified as '\0'.
To make sure this works with Lua 5.4 and Lua 5.1 change the Vim CI to
run with Lua 5.1 as well as Lua 5.4
6) https://github.com/vim/vim/pull/12631:
Add hurl filetype detection
7) https://github.com/vim/vim/pull/12573:
Problem: Files for haskell persistent library are not recognized
Solution: Add pattern persistentmodels for haskell persistent library
closes: #12612
closes: #12729
closes: #12702
closes: #12688
closes: #12668
closes: #12631
closes: #12573
Co-authored-by: lacygoill <lacygoill@lacygoill.me>
Co-authored-by: Michael Henry <drmikehenry@drmikehenry.com>
Co-authored-by: ObserverOfTime <chronobserver@disroot.org>
Co-authored-by: KnoP-01 <knosowski@graeffrobotics.de>
Co-authored-by: James McCoy <jamessan@jamessan.com>
Co-authored-by: Jacob Pfeifer <jacob@pfeifer.dev>
Co-authored-by: Borys Lykah <lykahb@fastmail.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 10 Aug 2023 06:30:06 +0200 |
parents | dbec60b8c253 |
children | 872c07d5befe |
line wrap: on
line source
" Test for various indent options func Test_preserveindent() new " Test for autoindent copying indent from the previous line setlocal autoindent call setline(1, [repeat(' ', 16) .. 'line1']) call feedkeys("A\nline2", 'xt') call assert_equal("\t\tline2", getline(2)) setlocal autoindent& " Test for using CTRL-T with and without 'preserveindent' set shiftwidth=4 call cursor(1, 1) call setline(1, " \t ") call feedkeys("Al\<C-T>", 'xt') call assert_equal("\t\tl", getline(1)) set preserveindent call setline(1, " \t ") call feedkeys("Al\<C-T>", 'xt') call assert_equal(" \t \tl", getline(1)) set pi& sw& " Test for using CTRL-T with 'expandtab' and 'preserveindent' call cursor(1, 1) call setline(1, "\t \t") set shiftwidth=4 expandtab preserveindent call feedkeys("Al\<C-T>", 'xt') call assert_equal("\t \t l", getline(1)) set sw& et& pi& close! endfunc " Test for indent() func Test_indent_func() call assert_equal(-1, indent(-1)) new call setline(1, "\tabc") call assert_equal(8, indent(1)) call setline(1, " abc") call assert_equal(4, indent(1)) call setline(1, " \t abc") call assert_equal(12, indent(1)) close! endfunc " Test for reindenting a line using the '=' operator func Test_reindent() new call setline(1, 'abc') set nomodifiable call assert_fails('normal ==', 'E21:') set modifiable call setline(1, ['foo', 'bar']) call feedkeys('ggVG=', 'xt') call assert_equal(['foo', 'bar'], getline(1, 2)) close! endfunc " Test indent operator creating one undo entry func Test_indent_operator_undo() enew call setline(1, range(12)->map('"\t" .. v:val')) func FoldExpr() let g:foldcount += 1 return '=' endfunc set foldmethod=expr foldexpr=FoldExpr() let g:foldcount = 0 redraw call assert_equal(12, g:foldcount) normal gg=G call assert_equal(24, g:foldcount) undo call assert_equal(38, g:foldcount) bwipe! set foldmethod& foldexpr= delfunc FoldExpr unlet g:foldcount endfunc " Test for shifting a line with a preprocessor directive ('#') func Test_preproc_indent() new set sw=4 call setline(1, '#define FOO 1') normal >> call assert_equal(' #define FOO 1', getline(1)) " with 'smartindent' call setline(1, '#define FOO 1') set smartindent normal >> call assert_equal('#define FOO 1', getline(1)) set smartindent& " with 'cindent' set cindent normal >> call assert_equal('#define FOO 1', getline(1)) set cindent& close! endfunc " Test for 'copyindent' func Test_copyindent() new set shiftwidth=4 autoindent expandtab copyindent call setline(1, " \t abc") call feedkeys("ol", 'xt') call assert_equal(" \t l", getline(2)) set noexpandtab call setline(1, " \t abc") call feedkeys("ol", 'xt') call assert_equal(" \t l", getline(2)) set sw& ai& et& ci& close! endfunc " Test for changing multiple lines with lisp indent func Test_lisp_indent_change_multiline() new setlocal lisp autoindent call setline(1, ['(if a', ' (if b', ' (return 5)))']) normal! jc2j(return 4)) call assert_equal(' (return 4))', getline(2)) close! endfunc func Test_lisp_indent() new setlocal lisp autoindent call setline(1, ['(if a', ' ;; comment', ' \ abc', '', ' " str1\', ' " st\b', ' (return 5)']) normal! jo;; comment normal! jo\ abc normal! jo;; ret normal! jostr1" normal! jostr2" call assert_equal([' ;; comment', ' ;; comment', ' \ abc', ' \ abc', '', ' ;; ret', ' " str1\', ' str1"', ' " st\b', ' str2"'], getline(2, 11)) close! endfunc func Test_lisp_indent_quoted() " This was going past the end of the line new setlocal lisp autoindent call setline(1, ['"[', '=']) normal Gvk= bwipe! endfunc " Test for setting the 'indentexpr' from a modeline func Test_modeline_indent_expr() let modeline = &modeline set modeline func GetIndent() return line('.') * 2 endfunc call writefile(['# vim: indentexpr=GetIndent()'], 'Xmlfile.txt', 'D') set modelineexpr new Xmlfile.txt call assert_equal('GetIndent()', &indentexpr) exe "normal Oa\nb\n" call assert_equal([' a', ' b'], getline(1, 2)) set modelineexpr& delfunc GetIndent let &modeline = modeline close! endfunc func Test_indent_func_with_gq() function GetTeXIndent() " Sample indent expression for TeX files let lnum = prevnonblank(v:lnum - 1) " At the start of the file use zero indent. if lnum == 0 return 0 endif let line = getline(lnum) let ind = indent(lnum) " Add a 'shiftwidth' after beginning of environments. if line =~ '\\begin{center}' let ind = ind + shiftwidth() endif return ind endfunction new setl et sw=2 sts=2 ts=2 tw=50 indentexpr=GetTeXIndent() put =[ '\documentclass{article}', '', '\begin{document}', '', \ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ut enim non', \ 'libero efficitur aliquet. Maecenas metus justo, facilisis convallis blandit', \ 'non, semper eu urna. Suspendisse diam diam, iaculis faucibus lorem eu,', \ 'fringilla condimentum lectus. Quisque euismod diam at convallis vulputate.', \ 'Pellentesque laoreet tortor sit amet mauris euismod ornare. Sed varius', \ 'bibendum orci vel vehicula. Pellentesque tempor, ipsum et auctor accumsan,', \ 'metus lectus ultrices odio, sed elementum mi ante at arcu.', '', '\begin{center}', '', \ 'Proin nec risus consequat nunc dapibus consectetur. Mauris lacinia est a augue', \ 'tristique accumsan. Morbi pretium, felis molestie eleifend condimentum, arcu', \ 'ipsum congue nisl, quis euismod purus libero in ante.', '', \ 'Donec id semper purus.', \ 'Suspendisse eget aliquam nunc. Maecenas fringilla mauris vitae maximus', \ 'condimentum. Cras a quam in mi dictum eleifend at a lorem. Sed convallis', \ 'ante a commodo facilisis. Nam suscipit vulputate odio, vel dapibus nisl', \ 'dignissim facilisis. Vestibulum ante ipsum primis in faucibus orci luctus et', \ 'ultrices posuere cubilia curae;', '', ''] 1d_ call cursor(5, 1) ka call cursor(14, 1) kb norm! 'agqap norm! 'bgqG let expected = [ '\documentclass{article}', '', '\begin{document}', '', \ 'Lorem ipsum dolor sit amet, consectetur adipiscing', \ 'elit. Fusce ut enim non libero efficitur aliquet.', \ 'Maecenas metus justo, facilisis convallis blandit', \ 'non, semper eu urna. Suspendisse diam diam,', \ 'iaculis faucibus lorem eu, fringilla condimentum', \ 'lectus. Quisque euismod diam at convallis', \ 'vulputate. Pellentesque laoreet tortor sit amet', \ 'mauris euismod ornare. Sed varius bibendum orci', \ 'vel vehicula. Pellentesque tempor, ipsum et auctor', \ 'accumsan, metus lectus ultrices odio, sed', \ 'elementum mi ante at arcu.', '', '\begin{center}', '', \ ' Proin nec risus consequat nunc dapibus', \ ' consectetur. Mauris lacinia est a augue', \ ' tristique accumsan. Morbi pretium, felis', \ ' molestie eleifend condimentum, arcu ipsum congue', \ ' nisl, quis euismod purus libero in ante.', \ '', \ ' Donec id semper purus. Suspendisse eget aliquam', \ ' nunc. Maecenas fringilla mauris vitae maximus', \ ' condimentum. Cras a quam in mi dictum eleifend', \ ' at a lorem. Sed convallis ante a commodo', \ ' facilisis. Nam suscipit vulputate odio, vel', \ ' dapibus nisl dignissim facilisis. Vestibulum', \ ' ante ipsum primis in faucibus orci luctus et', \ ' ultrices posuere cubilia curae;', '', ''] call assert_equal(expected, getline(1, '$')) bwipe! delmark ab delfunction GetTeXIndent endfu func Test_formatting_keeps_first_line_indent() let lines =<< trim END foo() { int x; // manually positioned // more text that will be formatted // but not reindented END new call setline(1, lines) setlocal sw=4 cindent tw=45 et normal! 4Ggqj let expected =<< trim END foo() { int x; // manually positioned // more text that will be // formatted but not // reindented END call assert_equal(expected, getline(1, '$')) bwipe! endfunc " vim: shiftwidth=2 sts=2 expandtab