diff options
-rwxr-xr-x | scripts/vim-patch.sh | 231 | ||||
-rw-r--r-- | src/nvim/eval.c | 15 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 15 | ||||
-rw-r--r-- | src/nvim/os/env.c | 19 | ||||
-rw-r--r-- | src/nvim/path.c | 36 | ||||
-rw-r--r-- | src/nvim/terminal.c | 9 | ||||
-rw-r--r-- | src/nvim/testdir/Makefile | 4 | ||||
-rw-r--r-- | src/nvim/testdir/test11.in | 84 | ||||
-rw-r--r-- | src/nvim/testdir/test11.ok | 61 | ||||
-rw-r--r-- | src/nvim/testdir/test36.in | 105 | ||||
-rw-r--r-- | src/nvim/testdir/test36.ok | 96 | ||||
-rw-r--r-- | src/nvim/testdir/test49.vim | 26 | ||||
-rw-r--r-- | src/nvim/version.c | 12 | ||||
-rw-r--r-- | test/functional/autocmd/termclose_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/legacy/011_autocommands_spec.lua | 230 | ||||
-rw-r--r-- | test/functional/legacy/036_regexp_character_classes_spec.lua | 272 |
16 files changed, 767 insertions, 464 deletions
diff --git a/scripts/vim-patch.sh b/scripts/vim-patch.sh index bdd3d6209b..7612a2ada0 100755 --- a/scripts/vim-patch.sh +++ b/scripts/vim-patch.sh @@ -5,9 +5,12 @@ set -u set -o pipefail readonly NEOVIM_SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -readonly VIM_SOURCE_DIR_DEFAULT=${NEOVIM_SOURCE_DIR}/.vim-src +readonly VIM_SOURCE_DIR_DEFAULT="${NEOVIM_SOURCE_DIR}/.vim-src" readonly VIM_SOURCE_DIR="${VIM_SOURCE_DIR:-${VIM_SOURCE_DIR_DEFAULT}}" readonly BASENAME="$(basename "${0}")" +readonly BRANCH_PREFIX="vim-" + +CREATED_FILES=() usage() { echo "Helper script for porting Vim patches. For more information, see" @@ -21,6 +24,7 @@ usage() { echo " -p {vim-revision} Download and apply the Vim patch vim-revision." echo " vim-revision can be a version number of the " echo " format '7.4.xxx' or a Git commit hash." + echo " -s Submit a vim-patch pull request to Neovim." echo " -r {pr-number} Review a vim-patch pull request to Neovim." echo echo "Set VIM_SOURCE_DIR to change where Vim's sources are stored." @@ -35,6 +39,27 @@ check_executable() { fi } +clean_files() { + if [[ ${#CREATED_FILES[@]} -eq 0 ]]; then + return + fi + + echo + echo "Created files:" + local file + for file in ${CREATED_FILES[@]}; do + echo " • ${file}" + done + + read -p "Delete these files (Y/n)? " -n 1 -r reply + echo + if [[ "${reply}" =~ ^[Yy]$ ]]; then + rm -- ${CREATED_FILES[@]} + else + echo "You can use 'git clean' to remove these files when you're done." + fi +} + get_vim_sources() { check_executable git @@ -66,22 +91,26 @@ assign_commit_details() { # Interpret parameter as version number (tag). vim_version="${1}" vim_tag="v${1}" - vim_commit=$( cd "${VIM_SOURCE_DIR}" \ - && git log -1 --format="%H" ${vim_tag} ) + vim_commit=$(cd "${VIM_SOURCE_DIR}" \ + && git log -1 --format="%H" ${vim_tag}) local strip_commit_line=true else # Interpret parameter as commit hash. vim_version="${1:0:7}" - vim_commit="${1}" + vim_commit=$(cd "${VIM_SOURCE_DIR}" \ + && git log -1 --format="%H" ${vim_version}) local strip_commit_line=false fi vim_commit_url="https://github.com/vim/vim/commit/${vim_commit}" - vim_message="$(git log -1 --pretty='format:%B' "${vim_commit}")" + vim_message="$(cd "${VIM_SOURCE_DIR}" \ + && git log -1 --pretty='format:%B' "${vim_commit}" \ + | sed -e 's/\(#[0-9]*\)/vim\/vim\1/g')" if [[ ${strip_commit_line} == "true" ]]; then # Remove first line of commit message. vim_message="$(echo "${vim_message}" | sed -e '1d')" fi + patch_file="vim-${vim_version}.patch" } get_vim_patch() { @@ -96,66 +125,108 @@ get_vim_patch() { echo echo "✔ Found Vim revision '${vim_commit}'." - # Collect patch details and store into variables. - vim_full="$(git show -1 --pretty=medium "${vim_commit}")" # Patch surgery: preprocess the patch. # - transform src/ paths to src/nvim/ - vim_diff="$(git show -1 "${vim_commit}" \ + local vim_full="$(git show -1 --pretty=medium "${vim_commit}" \ | LC_ALL=C sed -e 's/\( [ab]\/src\)/\1\/nvim/g')" - neovim_message="$(commit_message)" - neovim_pr=" -\`\`\` -${vim_message} -\`\`\` - -${vim_commit_url} - -Original patch: - -\`\`\`diff -${vim_diff} -\`\`\`" - neovim_branch="vim-${vim_version}" + local neovim_branch="${BRANCH_PREFIX}${vim_version}" - echo - echo "Creating Git branch." cd "${NEOVIM_SOURCE_DIR}" - output="$(git checkout -b "${neovim_branch}" 2>&1)" && - echo "✔ ${output}" || - (echo "✘ ${output}"; false) + local checked_out_branch="$(git rev-parse --abbrev-ref HEAD)" + if [[ "${checked_out_branch}" == ${BRANCH_PREFIX}* ]]; then + echo "✔ Current branch '${checked_out_branch}' seems to be a vim-patch" + echo " branch; not creating a new branch." + else + echo + echo "Fetching 'upstream/master'." + output="$(git fetch upstream master 2>&1)" && + echo "✔ ${output}" || + (echo "✘ ${output}"; false) + + echo + echo "Creating new branch '${neovim_branch}' based on 'upstream/master'." + cd "${NEOVIM_SOURCE_DIR}" + output="$(git checkout -b "${neovim_branch}" upstream/master 2>&1)" && + echo "✔ ${output}" || + (echo "✘ ${output}"; false) + fi echo echo "Creating empty commit with correct commit message." - output="$(git commit --allow-empty --file 2>&1 - <<< "${neovim_message}")" && + output="$(commit_message | git commit --allow-empty --file 2>&1 -)" && echo "✔ ${output}" || (echo "✘ ${output}"; false) echo echo "Creating files." - echo "${vim_diff}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff" - echo "✔ Saved diff to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.diff'." - echo "${vim_full}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch" - echo "✔ Saved full commit details to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.patch'." - echo "${neovim_pr}" > "${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr" - echo "✔ Saved suggested PR description to '${NEOVIM_SOURCE_DIR}/${neovim_branch}.pr'." - echo "You can use 'git clean' to remove these files when you're done." + echo "${vim_full}" > "${NEOVIM_SOURCE_DIR}/${patch_file}" + echo "✔ Saved full commit details to '${NEOVIM_SOURCE_DIR}/${patch_file}'." echo echo "Instructions:" echo echo " Proceed to port the patch." - echo " You might want to try 'patch -p1 < ${neovim_branch}.diff' first." + echo " You might want to try 'patch -p1 < ${patch_file}' first." + echo + echo " If the patch contains a new test, consider porting it to Lua." + echo " You might want to try 'scripts/legacy2luatest.pl'." echo echo " Stage your changes ('git add ...') and use 'git commit --amend' to commit." echo - echo " Push your changes with 'git push origin ${neovim_branch}' and create a" - echo " pull request called '[RFC] vim-patch:${vim_version}'. You might want " - echo " to use the text in '${neovim_branch}.pr' as the description of this pull request." + echo " To port additional patches related to ${vim_version} and add them to the current" + echo " branch, call '${BASENAME} -p' again. Please use this only if it wouldn't make" + echo " sense to send in each patch individually, as it will increase the size of the" + echo " pull request and make it harder to review." + echo + echo " When you are finished, use '${BASENAME} -s' to submit a pull request." echo echo " See https://github.com/neovim/neovim/wiki/Merging-patches-from-upstream-vim" echo " for more information." } +submit_pr() { + check_executable git + check_executable hub + + cd "${NEOVIM_SOURCE_DIR}" + local checked_out_branch="$(git rev-parse --abbrev-ref HEAD)" + if [[ "${checked_out_branch}" != ${BRANCH_PREFIX}* ]]; then + echo "✘ Current branch '${checked_out_branch}' doesn't seem to be a vim-patch branch." + exit 1 + fi + + local pr_body="$(git log --reverse --format='#### %s%n%n%b%n' upstream/master..HEAD)" + local patches=("$(git log --reverse --format='%s' upstream/master..HEAD)") + patches=(${patches[@]//vim-patch:}) # Remove 'vim-patch:' prefix for each item in array. + local pr_title="${patches[@]}" # Create space-separated string from array. + pr_title="${pr_title// /,}" # Replace spaces with commas. + + local pr_message="$(printf '[RFC] vim-patch:%s\n\n%s\n' "${pr_title#,}" "${pr_body}")" + + echo "Pushing to 'origin/${checked_out_branch}'." + output="$(git push origin "${checked_out_branch}" 2>&1)" && + echo "✔ ${output}" || + (echo "✘ ${output}"; git reset --soft HEAD^1; false) + + echo + echo "Creating pull request." + output="$(hub pull-request -F - 2>&1 <<< "${pr_message}")" && + echo "✔ ${output}" || + (echo "✘ ${output}"; false) + + echo + echo "Cleaning up files." + local patch_file + for patch_file in ${patches[@]}; do + patch_file="vim-${patch_file}.patch" + if [[ ! -f "${NEOVIM_SOURCE_DIR}/${patch_file}" ]]; then + continue + fi + rm -- "${NEOVIM_SOURCE_DIR}/${patch_file}" + echo "✔ Removed '${NEOVIM_SOURCE_DIR}/${patch_file}'." + done +} + list_vim_patches() { get_vim_sources @@ -189,7 +260,8 @@ list_vim_patches() { echo "Instructions:" echo echo " To port one of the above patches to Neovim, execute" - echo " this script with the patch revision as argument." + echo " this script with the patch revision as argument and" + echo " follow the instructions." echo echo " Examples: '${BASENAME} -p 7.4.487'" echo " '${BASENAME} -p 1e8ebf870720e7b671f98f22d653009826304c4f'" @@ -198,32 +270,28 @@ list_vim_patches() { echo " Out-of-order patches increase the possibility of bugs." } -review_pr() { - check_executable curl - check_executable nvim - - get_vim_sources - - local pr="${1}" - echo - echo "Downloading data for pull request #${pr}." +review_commit() { + local neovim_commit_url="${1}" + local neovim_patch_url="${neovim_commit_url}.patch" local git_patch_prefix='Subject: \[PATCH\] ' - local neovim_patch="$(curl -Ssf "https://patch-diff.githubusercontent.com/raw/neovim/neovim/pull/${pr}.patch")" - echo "${neovim_patch}" > a + local neovim_patch="$(curl -Ssf "${neovim_patch_url}")" local vim_version="$(head -n 4 <<< "${neovim_patch}" | sed -n "s/${git_patch_prefix}vim-patch:\([a-z0-9.]*\)$/\1/p")" + echo if [[ -n "${vim_version}" ]]; then echo "✔ Detected Vim patch '${vim_version}'." else echo "✘ Could not detect the Vim patch number." - echo " This script assumes that the PR contains a single commit" - echo " with 'vim-patch:XXX' as its title." + echo " This script assumes that the PR contains only commits" + echo " with 'vim-patch:XXX' in their title." exit 1 fi assign_commit_details "${vim_version}" + local vim_patch_url="${vim_commit_url}.patch" + local expected_commit_message="$(commit_message)" local message_length="$(wc -l <<< "${expected_commit_message}")" local commit_message="$(tail -n +4 <<< "${neovim_patch}" | head -n "${message_length}")" @@ -235,26 +303,57 @@ review_pr() { echo "${expected_commit_message}" echo " Actual:" echo "${commit_message#${git_patch_prefix}}" - exit 1 fi - local base_name="vim-${vim_version}" echo echo "Creating files." - curl -Ssfo "${NEOVIM_SOURCE_DIR}/n${base_name}.diff" "https://patch-diff.githubusercontent.com/raw/neovim/neovim/pull/${pr}.diff" - echo "✔ Saved pull request diff to '${NEOVIM_SOURCE_DIR}/n${base_name}.diff'." - echo "${neovim_patch}" > "${NEOVIM_SOURCE_DIR}/n${base_name}.patch" - echo "✔ Saved full pull request commit details to '${NEOVIM_SOURCE_DIR}/n${base_name}.patch'." - git show "${vim_commit}" > "${NEOVIM_SOURCE_DIR}/${base_name}.diff" - echo "✔ Saved Vim diff to '${NEOVIM_SOURCE_DIR}/${base_name}.diff'." - echo "You can use 'git clean' to remove these files when you're done." + echo "${neovim_patch}" > "${NEOVIM_SOURCE_DIR}/n${patch_file}" + echo "✔ Saved pull request diff to '${NEOVIM_SOURCE_DIR}/n${patch_file}'." + CREATED_FILES+=("${NEOVIM_SOURCE_DIR}/n${patch_file}") + + curl -Ssfo "${NEOVIM_SOURCE_DIR}/${patch_file}" "${vim_patch_url}" + echo "✔ Saved Vim diff to '${NEOVIM_SOURCE_DIR}/${patch_file}'." + CREATED_FILES+=("${NEOVIM_SOURCE_DIR}/${patch_file}") echo echo "Launching nvim." - exec nvim -O "${NEOVIM_SOURCE_DIR}/${base_name}.diff" "${NEOVIM_SOURCE_DIR}/n${base_name}.diff" + nvim -c "cd ${NEOVIM_SOURCE_DIR}" \ + -O "${NEOVIM_SOURCE_DIR}/${patch_file}" "${NEOVIM_SOURCE_DIR}/n${patch_file}" } -while getopts "hlp:r:" opt; do +review_pr() { + check_executable curl + check_executable nvim + check_executable jq + + get_vim_sources + + local pr="${1}" + echo + echo "Downloading data for pull request #${pr}." + + local pr_commit_urls=($(curl -Ssf "https://api.github.com/repos/neovim/neovim/pulls/${pr}/commits" \ + | jq -r '.[].html_url')) + + echo "Found ${#pr_commit_urls[@]} commit(s)." + + local pr_commit_url + local reply + for pr_commit_url in ${pr_commit_urls[@]}; do + review_commit "${pr_commit_url}" + if [[ "${pr_commit_url}" != "${pr_commit_urls[-1]}" ]]; then + read -p "Continue with next commit (Y/n)? " -n 1 -r reply + echo + if [[ ! "${reply}" =~ ^[Yy]$ ]]; then + break + fi + fi + done + + clean_files +} + +while getopts "hlp:r:s" opt; do case ${opt} in h) usage @@ -272,6 +371,10 @@ while getopts "hlp:r:" opt; do review_pr "${OPTARG}" exit 0 ;; + s) + submit_pr + exit 0 + ;; *) exit 1 ;; diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 837e19ab98..96fc79504f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -20926,14 +20926,18 @@ call_user_func ( save_sourcing_name = sourcing_name; save_sourcing_lnum = sourcing_lnum; sourcing_lnum = 1; - sourcing_name = xmalloc((save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) - + STRLEN(fp->uf_name) + 13); + // need space for function name + ("function " + 3) or "[number]" + size_t len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) + + STRLEN(fp->uf_name) + 20; + sourcing_name = xmalloc(len); { if (save_sourcing_name != NULL - && STRNCMP(save_sourcing_name, "function ", 9) == 0) - sprintf((char *)sourcing_name, "%s..", save_sourcing_name); - else + && STRNCMP(save_sourcing_name, "function ", 9) == 0) { + vim_snprintf((char *)sourcing_name, len, "%s[%zu]..", + save_sourcing_name, save_sourcing_lnum); + } else { STRCPY(sourcing_name, "function "); + } cat_func_name(sourcing_name + STRLEN(sourcing_name), fp); if (p_verbose >= 12) { @@ -22199,7 +22203,6 @@ static void on_process_exit(Process *proc, int status, void *d) char msg[22]; snprintf(msg, sizeof msg, "\r\n[Process exited %d]", proc->status); terminal_close(data->term, msg); - apply_autocmds(EVENT_TERMCLOSE, NULL, NULL, false, curbuf); } if (data->status_ptr) { diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index dfae2b849d..13a298cc78 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -8774,19 +8774,18 @@ static int ses_do_frame(frame_T *fr) return FALSE; } -/* - * Return non-zero if window "wp" is to be stored in the Session. - */ +/// Return non-zero if window "wp" is to be stored in the Session. static int ses_do_win(win_T *wp) { if (wp->w_buffer->b_fname == NULL - /* When 'buftype' is "nofile" can't restore the window contents. */ - || bt_nofile(wp->w_buffer) - ) + // When 'buftype' is "nofile" can't restore the window contents. + || (!wp->w_buffer->terminal && bt_nofile(wp->w_buffer))) { return ssop_flags & SSOP_BLANK; - if (wp->w_buffer->b_help) + } + if (wp->w_buffer->b_help) { return ssop_flags & SSOP_HELP; - return TRUE; + } + return true; } /* diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index c1804067e9..41ce8ddbc2 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -262,8 +262,25 @@ void expand_env_esc(char_u *srcp, char_u *dst, int dstlen, bool esc, bool one, startstr_len = (int)STRLEN(startstr); src = skipwhite(srcp); - --dstlen; // leave one char space for "\," + dstlen--; // leave one char space for "\," while (*src && dstlen > 0) { + // Skip over `=expr`. + if (src[0] == '`' && src[1] == '=') { + var = src; + src += 2; + (void)skip_expr(&src); + if (*src == '`') { + src++; + } + size_t len = (size_t)(src - var); + if (len > (size_t)dstlen) { + len = (size_t)dstlen; + } + memcpy((char *)dst, (char *)var, len); + dst += len; + dstlen -= (int)len; + continue; + } copy_char = true; if ((*src == '$') || (*src == '~' && at_start)) { mustfree = false; diff --git a/src/nvim/path.c b/src/nvim/path.c index e0e5f19911..5cd93ab811 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -556,8 +556,9 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, return 0; } - /* make room for file name */ - buf = xmalloc(STRLEN(path) + BASENAMELEN + 5); + // Make room for file name. When doing encoding conversion the actual + // length may be quite a bit longer, thus use the maximum possible length. + buf = xmalloc(MAXPATHL); /* * Find the first part in the path name that contains a wildcard. @@ -1158,12 +1159,17 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file, add_pat = -1; p = pat[i]; - if (vim_backtick(p)) + if (vim_backtick(p)) { add_pat = expand_backtick(&ga, p, flags); - else { - /* - * First expand environment variables, "~/" and "~user/". - */ + if (add_pat == -1) { + recursive = false; + FreeWild(ga.ga_len, (char_u **)ga.ga_data); + *num_file = 0; + *file = NULL; + return FAIL; + } + } else { + // First expand environment variables, "~/" and "~user/". if (has_env_var(p) || *p == '~') { p = expand_env_save_opt(p, true); if (p == NULL) @@ -1246,13 +1252,10 @@ static int vim_backtick(char_u *p) return *p == '`' && *(p + 1) != NUL && *(p + STRLEN(p) - 1) == '`'; } -/* - * Expand an item in `backticks` by executing it as a command. - * Currently only works when pat[] starts and ends with a `. - * Returns number of file names found. - */ -static int -expand_backtick ( +// Expand an item in `backticks` by executing it as a command. +// Currently only works when pat[] starts and ends with a `. +// Returns number of file names found, -1 if an error is encountered. +static int expand_backtick( garray_T *gap, char_u *pat, int flags /* EW_* flags */ @@ -1273,8 +1276,9 @@ expand_backtick ( buffer = get_cmd_output(cmd, NULL, (flags & EW_SILENT) ? kShellOptSilent : 0, NULL); xfree(cmd); - if (buffer == NULL) - return 0; + if (buffer == NULL) { + return -1; + } cmd = buffer; while (*cmd != NUL) { diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 0a7807d811..fb74569e3b 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -236,7 +236,7 @@ Terminal *terminal_open(TerminalOptions opts) set_option_value((uint8_t *)"relativenumber", false, NULL, OPT_LOCAL); RESET_BINDING(curwin); // Apply TermOpen autocmds so the user can configure the terminal - apply_autocmds(EVENT_TERMOPEN, NULL, NULL, true, curbuf); + apply_autocmds(EVENT_TERMOPEN, NULL, NULL, false, curbuf); // Configure the scrollback buffer. Try to get the size from: // @@ -288,8 +288,9 @@ void terminal_close(Terminal *term, char *msg) term->forward_mouse = false; term->closed = true; + buf_T *buf = handle_get_buffer(term->buf_handle); + if (!msg || exiting) { - buf_T *buf = handle_get_buffer(term->buf_handle); // If no msg was given, this was called by close_buffer(buffer.c). Or if // exiting, we must inform the buffer the terminal no longer exists so that // close_buffer() doesn't call this again. @@ -304,6 +305,10 @@ void terminal_close(Terminal *term, char *msg) } else { terminal_receive(term, msg, strlen(msg)); } + + if (buf) { + apply_autocmds(EVENT_TERMCLOSE, NULL, NULL, false, buf); + } } void terminal_resize(Terminal *term, uint16_t width, uint16_t height) diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 9dd18ab63e..7886835b4d 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -9,12 +9,12 @@ SCRIPTSOURCE := ../../../runtime SCRIPTS := \ test8.out test10.out \ - test11.out test12.out test13.out test14.out \ + test12.out test13.out test14.out \ test17.out \ test24.out \ test30.out \ test32.out test34.out \ - test36.out test37.out test40.out \ + test37.out test40.out \ test42.out \ test47.out test48.out test49.out \ test52.out test53.out test55.out \ diff --git a/src/nvim/testdir/test11.in b/src/nvim/testdir/test11.in deleted file mode 100644 index 9e9e257c1d..0000000000 --- a/src/nvim/testdir/test11.in +++ /dev/null @@ -1,84 +0,0 @@ -Tests for autocommands: -- FileWritePre writing a compressed file -- FileReadPost reading a compressed file -- BufNewFile reading a file template -- BufReadPre decompressing the file to be read -- FilterReadPre substituting characters in the temp file -- FilterReadPost substituting characters after filtering -- FileReadPre set options for decompression -- FileReadPost decompress the file - -Note: This test is skipped if "gzip" is not available. -$GZIP is made empty, "-v" would cause trouble. -Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz" being -modified outside of Vim (noticed on Solaris). - -STARTTEST -:so small.vim -:" drop out when there is no gzip program -:if !executable("gzip") -: e! test.ok -: w! test.out -: qa! -:endif -:let $GZIP = "" -:au FileChangedShell * echo "caught FileChangedShell" -:set bin -:au FileWritePre *.gz '[,']!gzip -:au FileWritePost *.gz undo -:/^start of testfile/,/^end of testfile/w! Xtestfile.gz -:au FileReadPost *.gz '[,']!gzip -d -:$r Xtestfile.gz " Read and decompress the testfile -:?startstart?,$w! test.out " Write contents of this file -:au BufNewFile *.c read Xtest.c -:/^start of test.c/+1,/^end of test.c/-1w! Xtest.c -:e! foo.c " Will load Xtest.c -:au FileAppendPre *.out '[,']s/new/NEW/ -:au FileAppendPost *.out !cat Xtest.c >>test.out -:w>>test.out " Append it to the output file -:au! FileAppendPre -:" setup autocommands to decompress before reading and re-compress afterwards -:au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand("<afile>")) -:au BufReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) -:au BufReadPost *.gz call rename(expand("<afile>"), expand("<afile>:r")) -:au BufReadPost *.gz exe '!gzip ' . shellescape(expand("<afile>:r")) -:e! Xtestfile.gz " Edit compressed file -:w>>test.out " Append it to the output file -:set shelltemp " need temp files here -:au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t") -:au FilterReadPre *.out exe 'silent !sed s/e/E/ ' . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>")) -:au FilterReadPre *.out exe 'silent !rm ' . shellescape(expand("<afile>")) . '.t' -:au FilterReadPost *.out '[,']s/x/X/g -:e! test.out " Edit the output file -:23,$!cat -:23,$s/\r$// " remove CR for when sed adds them -:au! FileReadPre *.gz exe 'silent !gzip -d ' . shellescape(expand("<afile>")) -:au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>")) -:au! FileReadPost *.gz '[,']s/l/L/ -:$r Xtestfile.gz " Read compressed file -:w " write it, after filtering -:au! " remove all autocommands -:e " Edit test.out again -:set nobin ff& " use the default fileformat for writing -:w -:qa! -ENDTEST - -startstart -start of testfile -line 2 Abcdefghijklmnopqrstuvwxyz -line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 4 Abcdefghijklmnopqrstuvwxyz -line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 6 Abcdefghijklmnopqrstuvwxyz -line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 8 Abcdefghijklmnopqrstuvwxyz -line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 10 Abcdefghijklmnopqrstuvwxyz -end of testfile - -start of test.c -/* - * Here is a new .c file - */ -end of test.c diff --git a/src/nvim/testdir/test11.ok b/src/nvim/testdir/test11.ok deleted file mode 100644 index af8c5ce261..0000000000 --- a/src/nvim/testdir/test11.ok +++ /dev/null @@ -1,61 +0,0 @@ -startstart -start of testfile -line 2 Abcdefghijklmnopqrstuvwxyz -line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 4 Abcdefghijklmnopqrstuvwxyz -line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 6 Abcdefghijklmnopqrstuvwxyz -line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 8 Abcdefghijklmnopqrstuvwxyz -line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 10 Abcdefghijklmnopqrstuvwxyz -end of testfile - -start of test.c -/* - * Here is a new .c file - */ -end of test.c -start of testfile -line 2 Abcdefghijklmnopqrstuvwxyz -line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -line 4 Abcdefghijklmnopqrstuvwxyz -linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -linE 6 AbcdefghijklmnopqrstuvwXyz -linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -linE 8 AbcdefghijklmnopqrstuvwXyz -linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -linE 10 AbcdefghijklmnopqrstuvwXyz -End of testfile - -/* - * HEre is a NEW .c file - */ -/* - * HEre is a new .c file - */ -start of tEstfile -linE 2 AbcdefghijklmnopqrstuvwXyz -linE 3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -linE 4 AbcdefghijklmnopqrstuvwXyz -linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -linE 6 AbcdefghijklmnopqrstuvwXyz -linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -linE 8 AbcdefghijklmnopqrstuvwXyz -linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -linE 10 AbcdefghijklmnopqrstuvwXyz -End of testfile -/* - * HEre is a new .c file - */ -start of testfiLe -Line 2 Abcdefghijklmnopqrstuvwxyz -Line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -Line 4 Abcdefghijklmnopqrstuvwxyz -Line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -Line 6 Abcdefghijklmnopqrstuvwxyz -Line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -Line 8 Abcdefghijklmnopqrstuvwxyz -Line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -Line 10 Abcdefghijklmnopqrstuvwxyz -end of testfiLe diff --git a/src/nvim/testdir/test36.in b/src/nvim/testdir/test36.in deleted file mode 100644 index 8cdb5262bd..0000000000 --- a/src/nvim/testdir/test36.in +++ /dev/null @@ -1,105 +0,0 @@ -Test character classes in regexp using regexpengine 0, 1, 2. - -STARTTEST -/^start-here/+1 -Y:s/\%#=0\d//g -p:s/\%#=1\d//g -p:s/\%#=2\d//g -p:s/\%#=0[0-9]//g -p:s/\%#=1[0-9]//g -p:s/\%#=2[0-9]//g -p:s/\%#=0\D//g -p:s/\%#=1\D//g -p:s/\%#=2\D//g -p:s/\%#=0[^0-9]//g -p:s/\%#=1[^0-9]//g -p:s/\%#=2[^0-9]//g -p:s/\%#=0\o//g -p:s/\%#=1\o//g -p:s/\%#=2\o//g -p:s/\%#=0[0-7]//g -p:s/\%#=1[0-7]//g -p:s/\%#=2[0-7]//g -p:s/\%#=0\O//g -p:s/\%#=1\O//g -p:s/\%#=2\O//g -p:s/\%#=0[^0-7]//g -p:s/\%#=1[^0-7]//g -p:s/\%#=2[^0-7]//g -p:s/\%#=0\x//g -p:s/\%#=1\x//g -p:s/\%#=2\x//g -p:s/\%#=0[0-9A-Fa-f]//g -p:s/\%#=1[0-9A-Fa-f]//g -p:s/\%#=2[0-9A-Fa-f]//g -p:s/\%#=0\X//g -p:s/\%#=1\X//g -p:s/\%#=2\X//g -p:s/\%#=0[^0-9A-Fa-f]//g -p:s/\%#=1[^0-9A-Fa-f]//g -p:s/\%#=2[^0-9A-Fa-f]//g -p:s/\%#=0\w//g -p:s/\%#=1\w//g -p:s/\%#=2\w//g -p:s/\%#=0[0-9A-Za-z_]//g -p:s/\%#=1[0-9A-Za-z_]//g -p:s/\%#=2[0-9A-Za-z_]//g -p:s/\%#=0\W//g -p:s/\%#=1\W//g -p:s/\%#=2\W//g -p:s/\%#=0[^0-9A-Za-z_]//g -p:s/\%#=1[^0-9A-Za-z_]//g -p:s/\%#=2[^0-9A-Za-z_]//g -p:s/\%#=0\h//g -p:s/\%#=1\h//g -p:s/\%#=2\h//g -p:s/\%#=0[A-Za-z_]//g -p:s/\%#=1[A-Za-z_]//g -p:s/\%#=2[A-Za-z_]//g -p:s/\%#=0\H//g -p:s/\%#=1\H//g -p:s/\%#=2\H//g -p:s/\%#=0[^A-Za-z_]//g -p:s/\%#=1[^A-Za-z_]//g -p:s/\%#=2[^A-Za-z_]//g -p:s/\%#=0\a//g -p:s/\%#=1\a//g -p:s/\%#=2\a//g -p:s/\%#=0[A-Za-z]//g -p:s/\%#=1[A-Za-z]//g -p:s/\%#=2[A-Za-z]//g -p:s/\%#=0\A//g -p:s/\%#=1\A//g -p:s/\%#=2\A//g -p:s/\%#=0[^A-Za-z]//g -p:s/\%#=1[^A-Za-z]//g -p:s/\%#=2[^A-Za-z]//g -p:s/\%#=0\l//g -p:s/\%#=1\l//g -p:s/\%#=2\l//g -p:s/\%#=0[a-z]//g -p:s/\%#=1[a-z]//g -p:s/\%#=2[a-z]//g -p:s/\%#=0\L//g -p:s/\%#=1\L//g -p:s/\%#=2\L//g -p:s/\%#=0[^a-z]//g -p:s/\%#=1[^a-z]//g -p:s/\%#=2[^a-z]//g -p:s/\%#=0\u//g -p:s/\%#=1\u//g -p:s/\%#=2\u//g -p:s/\%#=0[A-Z]//g -p:s/\%#=1[A-Z]//g -p:s/\%#=2[A-Z]//g -p:s/\%#=0\U//g -p:s/\%#=1\U//g -p:s/\%#=2\U//g -p:s/\%#=0[^A-Z]//g -p:s/\%#=1[^A-Z]//g -p:s/\%#=2[^A-Z]//g -:/^start-here/+1,$wq! test.out -ENDTEST - -start-here -
!"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ diff --git a/src/nvim/testdir/test36.ok b/src/nvim/testdir/test36.ok deleted file mode 100644 index f72a74b2b7..0000000000 --- a/src/nvim/testdir/test36.ok +++ /dev/null @@ -1,96 +0,0 @@ -
!"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -0123456789 -0123456789 -0123456789 -0123456789 -0123456789 -0123456789 -
!"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./89:;<=>?@ABCDEFGHIXYZ[\]^_`abcdefghiwxyz{|}~ -01234567 -01234567 -01234567 -01234567 -01234567 -01234567 -
!"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~ -
!"#$%&'()#+'-./:;<=>?@GHIXYZ[\]^_`ghiwxyz{|}~ -0123456789ABCDEFabcdef -0123456789ABCDEFabcdef -0123456789ABCDEFabcdef -0123456789ABCDEFabcdef -0123456789ABCDEFabcdef -0123456789ABCDEFabcdef -
!"#$%&'()#+'-./:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./:;<=>?@[\]^`{|}~ -0123456789ABCDEFGHIXYZ_abcdefghiwxyz -0123456789ABCDEFGHIXYZ_abcdefghiwxyz -0123456789ABCDEFGHIXYZ_abcdefghiwxyz -0123456789ABCDEFGHIXYZ_abcdefghiwxyz -0123456789ABCDEFGHIXYZ_abcdefghiwxyz -0123456789ABCDEFGHIXYZ_abcdefghiwxyz -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^`{|}~ -ABCDEFGHIXYZ_abcdefghiwxyz -ABCDEFGHIXYZ_abcdefghiwxyz -ABCDEFGHIXYZ_abcdefghiwxyz -ABCDEFGHIXYZ_abcdefghiwxyz -ABCDEFGHIXYZ_abcdefghiwxyz -ABCDEFGHIXYZ_abcdefghiwxyz -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`{|}~ -ABCDEFGHIXYZabcdefghiwxyz -ABCDEFGHIXYZabcdefghiwxyz -ABCDEFGHIXYZabcdefghiwxyz -ABCDEFGHIXYZabcdefghiwxyz -ABCDEFGHIXYZabcdefghiwxyz -ABCDEFGHIXYZabcdefghiwxyz -
!"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@ABCDEFGHIXYZ[\]^_`{|}~ -abcdefghiwxyz -abcdefghiwxyz -abcdefghiwxyz -abcdefghiwxyz -abcdefghiwxyz -abcdefghiwxyz -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~ -
!"#$%&'()#+'-./0123456789:;<=>?@[\]^_`abcdefghiwxyz{|}~ -ABCDEFGHIXYZ -ABCDEFGHIXYZ -ABCDEFGHIXYZ -ABCDEFGHIXYZ -ABCDEFGHIXYZ -ABCDEFGHIXYZ diff --git a/src/nvim/testdir/test49.vim b/src/nvim/testdir/test49.vim index afee9d882c..70d388b06a 100644 --- a/src/nvim/testdir/test49.vim +++ b/src/nvim/testdir/test49.vim @@ -1,6 +1,6 @@ " Vim script language tests " Author: Servatius Brandt <Servatius.Brandt@fujitsu-siemens.com> -" Last Change: 2013 Jun 06 +" Last Change: 2015 Sep 25 "------------------------------------------------------------------------------- " Test environment {{{1 @@ -5188,19 +5188,19 @@ catch /.*/ Xpath 65536 " X: 65536 let exception = v:exception let throwpoint = v:throwpoint - call CHECK(1, "oops", '\<F\.\.G\.\.T\>', '\<2\>') + call CHECK(1, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') exec "let exception = v:exception" exec "let throwpoint = v:throwpoint" - call CHECK(2, "oops", '\<F\.\.G\.\.T\>', '\<2\>') + call CHECK(2, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') CmdException CmdThrowpoint - call CHECK(3, "oops", '\<F\.\.G\.\.T\>', '\<2\>') + call CHECK(3, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') call FuncException() call FuncThrowpoint() - call CHECK(4, "oops", '\<F\.\.G\.\.T\>', '\<2\>') + call CHECK(4, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') exec "source" scriptException exec "source" scriptThrowPoint - call CHECK(5, "oops", '\<F\.\.G\.\.T\>', '\<2\>') + call CHECK(5, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') try Xpath 131072 " X: 131072 call G("arrgh", 4) @@ -5208,7 +5208,7 @@ catch /.*/ Xpath 262144 " X: 262144 let exception = v:exception let throwpoint = v:throwpoint - call CHECK(6, "arrgh", '\<G\.\.T\>', '\<4\>') + call CHECK(6, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') try Xpath 524288 " X: 524288 let g:arg = "autsch" @@ -5226,7 +5226,7 @@ catch /.*/ Xpath 2097152 " X: 2097152 let exception = v:exception let throwpoint = v:throwpoint - call CHECK(8, "arrgh", '\<G\.\.T\>', '\<4\>') + call CHECK(8, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') try Xpath 4194304 " X: 4194304 let g:arg = "brrrr" @@ -5242,27 +5242,27 @@ catch /.*/ Xpath 16777216 " X: 16777216 let exception = v:exception let throwpoint = v:throwpoint - call CHECK(10, "arrgh", '\<G\.\.T\>', '\<4\>') + call CHECK(10, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') endtry Xpath 33554432 " X: 33554432 let exception = v:exception let throwpoint = v:throwpoint - call CHECK(11, "arrgh", '\<G\.\.T\>', '\<4\>') + call CHECK(11, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') endtry Xpath 67108864 " X: 67108864 let exception = v:exception let throwpoint = v:throwpoint - call CHECK(12, "arrgh", '\<G\.\.T\>', '\<4\>') + call CHECK(12, "arrgh", '\<G\[1]\.\.T\>', '\<4\>') finally Xpath 134217728 " X: 134217728 let exception = v:exception let throwpoint = v:throwpoint - call CHECK(13, "oops", '\<F\.\.G\.\.T\>', '\<2\>') + call CHECK(13, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') endtry Xpath 268435456 " X: 268435456 let exception = v:exception let throwpoint = v:throwpoint - call CHECK(14, "oops", '\<F\.\.G\.\.T\>', '\<2\>') + call CHECK(14, "oops", '\<F\[1]\.\.G\[1]\.\.T\>', '\<2\>') finally Xpath 536870912 " X: 536870912 let exception = v:exception diff --git a/src/nvim/version.c b/src/nvim/version.c index 813448ca40..ca685d32c3 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -387,7 +387,7 @@ static int included_patches[] = { // 906 NA // 905, // 904, - // 903, + 903, // 902 NA // 901, // 900 NA @@ -409,9 +409,9 @@ static int included_patches[] = { // 884 NA 883, // 882, - // 881, + 881, // 880 NA - // 879, + 879, // 878, 877, // 876 NA @@ -445,7 +445,7 @@ static int included_patches[] = { 848, 847, // 846 NA - // 845, + 845, 844, 843, // 842 NA @@ -458,8 +458,8 @@ static int included_patches[] = { 835, 834, 833, - // 832, - // 831, + 832, + 831, 830, // 829 NA 828, diff --git a/test/functional/autocmd/termclose_spec.lua b/test/functional/autocmd/termclose_spec.lua index 0961340e61..4de3f039c1 100644 --- a/test/functional/autocmd/termclose_spec.lua +++ b/test/functional/autocmd/termclose_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local clear, execute, feed, nvim, nvim_dir = helpers.clear, helpers.execute, helpers.feed, helpers.nvim, helpers.nvim_dir +local eval, eq = helpers.eval, helpers.eq describe('TermClose event', function() local screen @@ -25,4 +26,19 @@ describe('TermClose event', function() TermClose works! | ]]) end) + + it('reports the correct <abuf>', function() + execute('set hidden') + execute('autocmd TermClose * let g:abuf = expand("<abuf>")') + execute('edit foo') + execute('edit bar') + eq(2, eval('bufnr("%")')) + execute('terminal') + feed('<c-\\><c-n>') + eq(3, eval('bufnr("%")')) + execute('buffer 1') + eq(1, eval('bufnr("%")')) + execute('3bdelete!') + eq('3', eval('g:abuf')) + end) end) diff --git a/test/functional/legacy/011_autocommands_spec.lua b/test/functional/legacy/011_autocommands_spec.lua new file mode 100644 index 0000000000..483e465cee --- /dev/null +++ b/test/functional/legacy/011_autocommands_spec.lua @@ -0,0 +1,230 @@ +-- Tests for autocommands +-- - FileWritePre writing a compressed file +-- - FileReadPost reading a compressed file +-- - BufNewFile reading a file template +-- - BufReadPre decompressing the file to be read +-- - FilterReadPre substituting characters in the temp file +-- - FilterReadPost substituting characters after filtering +-- - FileReadPre set options for decompression +-- - FileReadPost decompress the file +-- Note: This test is skipped if "gzip" is not available. +-- $GZIP is made empty, "-v" would cause trouble. +-- Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz" +-- being modified outside of Vim (noticed on Solaris). + +local helpers, lfs = require('test.functional.helpers'), require('lfs') +local clear, execute, expect, eq, neq, dedent, write_file, feed = + helpers.clear, helpers.execute, helpers.expect, helpers.eq, helpers.neq, + helpers.dedent, helpers.write_file, helpers.feed + +local function has_gzip() + return os.execute('gzip --help >/dev/null 2>&1') == 0 +end + +local function prepare_gz_file(name, text) + write_file(name, text..'\n') + -- Compress the file with gzip. + os.execute('gzip --force '..name) + -- This should create the .gz file and delete the original. + neq(nil, lfs.attributes(name..'.gz')) + eq(nil, lfs.attributes(name)) +end + +describe('file reading, writing and bufnew and filter autocommands', function() + local text1 = dedent([[ + start of testfile + line 2 Abcdefghijklmnopqrstuvwxyz + line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 4 Abcdefghijklmnopqrstuvwxyz + line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 6 Abcdefghijklmnopqrstuvwxyz + line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 8 Abcdefghijklmnopqrstuvwxyz + line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 10 Abcdefghijklmnopqrstuvwxyz + end of testfile]]) + setup(function() + write_file('Xtest.c', [[ + /* + * Here is a new .c file + */ + ]]) + end) + before_each(clear) + teardown(function() + os.remove('Xtestfile.gz') + os.remove('Xtest.c') + os.remove('test.out') + end) + + if not has_gzip() then + pending('skipped (missing `gzip` utility)', function() end) + else + + it('FileReadPost (using gzip)', function() + prepare_gz_file('Xtestfile', text1) + execute('let $GZIP = ""') + --execute('au FileChangedShell * echo "caught FileChangedShell"') + execute('set bin') + execute("au FileReadPost *.gz '[,']!gzip -d") + -- Read and decompress the testfile. + execute('$r Xtestfile.gz') + expect('\n'..text1) + end) + + it('BufReadPre, BufReadPost (using gzip)', function() + prepare_gz_file('Xtestfile', text1) + local gzip_data = io.open('Xtestfile.gz'):read('*all') + execute('let $GZIP = ""') + -- Setup autocommands to decompress before reading and re-compress afterwards. + execute("au BufReadPre *.gz exe '!gzip -d ' . shellescape(expand('<afile>'))") + execute("au BufReadPre *.gz call rename(expand('<afile>:r'), expand('<afile>'))") + execute("au BufReadPost *.gz call rename(expand('<afile>'), expand('<afile>:r'))") + execute("au BufReadPost *.gz exe '!gzip ' . shellescape(expand('<afile>:r'))") + -- Edit compressed file. + execute('e! Xtestfile.gz') + -- Discard all prompts and messages. + feed('<C-L>') + -- Expect the decompressed file in the buffer. + expect(text1) + -- Expect the original file to be unchanged. + eq(gzip_data, io.open('Xtestfile.gz'):read('*all')) + end) + + it('FileReadPre, FileReadPost', function() + prepare_gz_file('Xtestfile', text1) + execute('au! FileReadPre *.gz exe "silent !gzip -d " . shellescape(expand("<afile>"))') + execute('au FileReadPre *.gz call rename(expand("<afile>:r"), expand("<afile>"))') + execute("au! FileReadPost *.gz '[,']s/l/L/") + -- Read compressed file. + execute('$r Xtestfile.gz') + -- Discard all prompts and messages. + feed('<C-L>') + expect([[ + + start of testfiLe + Line 2 Abcdefghijklmnopqrstuvwxyz + Line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Line 4 Abcdefghijklmnopqrstuvwxyz + Line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Line 6 Abcdefghijklmnopqrstuvwxyz + Line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Line 8 Abcdefghijklmnopqrstuvwxyz + Line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Line 10 Abcdefghijklmnopqrstuvwxyz + end of testfiLe]]) + end) + + end + + it('FileAppendPre, FileAppendPost', function() + execute('au BufNewFile *.c read Xtest.c') + -- Will load Xtest.c. + execute('e! foo.c') + execute("au FileAppendPre *.out '[,']s/new/NEW/") + execute('au FileAppendPost *.out !cat Xtest.c >>test.out') + -- Append it to the output file. + execute('w>>test.out') + -- Discard all prompts and messages. + feed('<C-L>') + -- Expect the decompressed file in the buffer. + execute('e test.out') + expect([[ + + /* + * Here is a NEW .c file + */]]) + end) + + it('FilterReadPre, FilterReadPost', function() + -- Write a special input file for this test block. + write_file('test.out', dedent([[ + startstart + ]]) .. text1 .. dedent([[ + + + start of test.c + /* + * Here is a new .c file + */ + end of test.c + ]]) .. text1 .. dedent([[ + + + /* + * Here is a NEW .c file + */ + /* + * Here is a new .c file + */ + ]]) .. text1 .. dedent([[ + + /* + * Here is a new .c file + */]])) + -- Need temp files here. + execute('set shelltemp') + execute('au FilterReadPre *.out call rename(expand("<afile>"), expand("<afile>") . ".t")') + execute('au FilterReadPre *.out exe "silent !sed s/e/E/ " . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>"))') + execute('au FilterReadPre *.out exe "silent !rm " . shellescape(expand("<afile>")) . ".t"') + execute("au FilterReadPost *.out '[,']s/x/X/g") + -- Edit the output file. + execute('e! test.out') + execute('23,$!cat') + -- Discard all prompts and messages. + feed('<C-L>') + -- Remove CR for when sed adds them. + execute([[23,$s/\r$//]]) + expect([[ + startstart + start of testfile + line 2 Abcdefghijklmnopqrstuvwxyz + line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 4 Abcdefghijklmnopqrstuvwxyz + line 5 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 6 Abcdefghijklmnopqrstuvwxyz + line 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 8 Abcdefghijklmnopqrstuvwxyz + line 9 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 10 Abcdefghijklmnopqrstuvwxyz + end of testfile + + start of test.c + /* + * Here is a new .c file + */ + end of test.c + start of testfile + line 2 Abcdefghijklmnopqrstuvwxyz + line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + line 4 Abcdefghijklmnopqrstuvwxyz + linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + linE 6 AbcdefghijklmnopqrstuvwXyz + linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + linE 8 AbcdefghijklmnopqrstuvwXyz + linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + linE 10 AbcdefghijklmnopqrstuvwXyz + End of testfile + + /* + * HEre is a NEW .c file + */ + /* + * HEre is a new .c file + */ + start of tEstfile + linE 2 AbcdefghijklmnopqrstuvwXyz + linE 3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + linE 4 AbcdefghijklmnopqrstuvwXyz + linE 5 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + linE 6 AbcdefghijklmnopqrstuvwXyz + linE 7 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + linE 8 AbcdefghijklmnopqrstuvwXyz + linE 9 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + linE 10 AbcdefghijklmnopqrstuvwXyz + End of testfile + /* + * HEre is a new .c file + */]]) + end) +end) diff --git a/test/functional/legacy/036_regexp_character_classes_spec.lua b/test/functional/legacy/036_regexp_character_classes_spec.lua new file mode 100644 index 0000000000..205922eac2 --- /dev/null +++ b/test/functional/legacy/036_regexp_character_classes_spec.lua @@ -0,0 +1,272 @@ +-- Test character classes in regexp using regexpengine 0, 1, 2. + +local helpers = require('test.functional.helpers') +local ffi = require('ffi') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect, eq, eval = helpers.clear, helpers.execute, helpers.expect, helpers.eq, helpers.eval +local write_file = helpers.write_file + +local function sixlines(text) + local result = '' + for i = 1, 6 do + result = result .. text .. '\n' + end + return result +end + +local function diff(text, nodedent) + local tmpname = os.tmpname() + if ffi.os == 'OSX' and string.match(tmpname, '^/tmp') then + tmpname = '/private'..tmpname + end + execute('w! '..tmpname) + helpers.wait() + local data = io.open(tmpname):read('*all') + if nodedent then + helpers.eq(text, data) + else + helpers.eq(helpers.dedent(text), data) + end + os.remove(tmpname) +end + +describe('character classes in regexp', function() + local ctrl1 = '\t\x0c\r' + local punct1 = " !\"#$%&'()#+'-./" + local digits = '0123456789' + local punct2 = ':;<=>?@' + local upper = 'ABCDEFGHIXYZ' + local punct3 = '[\\]^_`' + local lower = 'abcdefghiwxyz' + local punct4 = '{|}~' + local ctrl2 = '\x7f\x80\x82\x90\x9b' + local iso_text = '\xa6\xb1\xbc\xc7\xd3\xe9' -- "¦±¼ÇÓé" in utf-8 + setup(function() + -- The original test32.in file was not in utf-8 encoding and did also + -- contain some control characters. We use lua escape sequences to write + -- them to the test file. + local line = ctrl1..punct1..digits..punct2..upper..punct3..lower..punct4..ctrl2..iso_text + write_file('test36.in', sixlines(line)) + end) + before_each(function() + clear() + execute('e test36.in') + end) + teardown(function() + os.remove('test36.in') + end) + + it('is working', function() + source([[ + 1 s/\%#=0\d//g + 2 s/\%#=1\d//g + 3 s/\%#=2\d//g + 4 s/\%#=0[0-9]//g + 5 s/\%#=1[0-9]//g + 6 s/\%#=2[0-9]//g]]) + diff(sixlines(ctrl1..punct1..punct2..upper..punct3..lower..punct4.. + ctrl2..iso_text)) + end) + it('is working', function() + source([[ + 1 s/\%#=0\D//g + 2 s/\%#=1\D//g + 3 s/\%#=2\D//g + 4 s/\%#=0[^0-9]//g + 5 s/\%#=1[^0-9]//g + 6 s/\%#=2[^0-9]//g]]) + expect([[ + 0123456789 + 0123456789 + 0123456789 + 0123456789 + 0123456789 + 0123456789]]) + end) + it('is working', function() + source([[ + 1 s/\%#=0\o//g + 2 s/\%#=1\o//g + 3 s/\%#=2\o//g + 4 s/\%#=0[0-7]//g + 5 s/\%#=1[0-7]//g + 6 s/\%#=2[0-7]//g]]) + diff(sixlines(ctrl1..punct1..'89'..punct2..upper..punct3..lower..punct4..ctrl2.. + iso_text)) + end) + it('is working', function() + source([[ + 1 s/\%#=0\O//g + 2 s/\%#=1\O//g + 3 s/\%#=2\O//g + 4 s/\%#=0[^0-7]//g + 5 s/\%#=1[^0-7]//g + 6 s/\%#=2[^0-7]//g]]) + expect([[ + 01234567 + 01234567 + 01234567 + 01234567 + 01234567 + 01234567]]) + end) + it('is working', function() + source([[ + 1 s/\%#=0\x//g + 2 s/\%#=1\x//g + 3 s/\%#=2\x//g + 4 s/\%#=0[0-9A-Fa-f]//g + 5 s/\%#=1[0-9A-Fa-f]//g + 6 s/\%#=2[0-9A-Fa-f]//g]]) + diff(sixlines(ctrl1..punct1..punct2..'GHIXYZ'..punct3..'ghiwxyz'..punct4..ctrl2..iso_text)) + end) + it('is working', function() + source([[ + 1 s/\%#=0\X//g + 2 s/\%#=1\X//g + 3 s/\%#=2\X//g + 4 s/\%#=0[^0-9A-Fa-f]//g + 5 s/\%#=1[^0-9A-Fa-f]//g + 6 s/\%#=2[^0-9A-Fa-f]//g]]) + expect([[ + 0123456789ABCDEFabcdef + 0123456789ABCDEFabcdef + 0123456789ABCDEFabcdef + 0123456789ABCDEFabcdef + 0123456789ABCDEFabcdef + 0123456789ABCDEFabcdef]]) + end) + it('is working', function() + source([[ + 1 s/\%#=0\w//g + 2 s/\%#=1\w//g + 3 s/\%#=2\w//g + 4 s/\%#=0[0-9A-Za-z_]//g + 5 s/\%#=1[0-9A-Za-z_]//g + 6 s/\%#=2[0-9A-Za-z_]//g]]) + diff(sixlines(ctrl1..punct1..punct2..'[\\]^`'..punct4..ctrl2..iso_text)) + end) + it('is working', function() + source([[ + 1 s/\%#=0\W//g + 2 s/\%#=1\W//g + 3 s/\%#=2\W//g + 4 s/\%#=0[^0-9A-Za-z_]//g + 5 s/\%#=1[^0-9A-Za-z_]//g + 6 s/\%#=2[^0-9A-Za-z_]//g]]) + expect([[ + 0123456789ABCDEFGHIXYZ_abcdefghiwxyz + 0123456789ABCDEFGHIXYZ_abcdefghiwxyz + 0123456789ABCDEFGHIXYZ_abcdefghiwxyz + 0123456789ABCDEFGHIXYZ_abcdefghiwxyz + 0123456789ABCDEFGHIXYZ_abcdefghiwxyz + 0123456789ABCDEFGHIXYZ_abcdefghiwxyz]]) + end) + it('is working', function() + source([[ + 1 s/\%#=0\h//g + 2 s/\%#=1\h//g + 3 s/\%#=2\h//g + 4 s/\%#=0[A-Za-z_]//g + 5 s/\%#=1[A-Za-z_]//g + 6 s/\%#=2[A-Za-z_]//g]]) + diff(sixlines(ctrl1..punct1..digits..punct2..'[\\]^`'..punct4..ctrl2.. + iso_text)) + end) + it('is working', function() + source([[ + 1 s/\%#=0\H//g + 2 s/\%#=1\H//g + 3 s/\%#=2\H//g + 4 s/\%#=0[^A-Za-z_]//g + 5 s/\%#=1[^A-Za-z_]//g + 6 s/\%#=2[^A-Za-z_]//g]]) + expect([[ + ABCDEFGHIXYZ_abcdefghiwxyz + ABCDEFGHIXYZ_abcdefghiwxyz + ABCDEFGHIXYZ_abcdefghiwxyz + ABCDEFGHIXYZ_abcdefghiwxyz + ABCDEFGHIXYZ_abcdefghiwxyz + ABCDEFGHIXYZ_abcdefghiwxyz]]) + end) + it('is working', function() + source([[ + 1 s/\%#=0\a//g + 2 s/\%#=1\a//g + 3 s/\%#=2\a//g + 4 s/\%#=0[A-Za-z]//g + 5 s/\%#=1[A-Za-z]//g + 6 s/\%#=2[A-Za-z]//g]]) + diff(sixlines(ctrl1..punct1..digits..punct2..punct3..punct4..ctrl2..iso_text)) + end) + it('is working', function() + source([[ + 1 s/\%#=0\A//g + 2 s/\%#=1\A//g + 3 s/\%#=2\A//g + 4 s/\%#=0[^A-Za-z]//g + 5 s/\%#=1[^A-Za-z]//g + 6 s/\%#=2[^A-Za-z]//g]]) + expect([[ + ABCDEFGHIXYZabcdefghiwxyz + ABCDEFGHIXYZabcdefghiwxyz + ABCDEFGHIXYZabcdefghiwxyz + ABCDEFGHIXYZabcdefghiwxyz + ABCDEFGHIXYZabcdefghiwxyz + ABCDEFGHIXYZabcdefghiwxyz]]) + end) + it('is working', function() + source([[ + 1 s/\%#=0\l//g + 2 s/\%#=1\l//g + 3 s/\%#=2\l//g + 4 s/\%#=0[a-z]//g + 5 s/\%#=1[a-z]//g + 6 s/\%#=2[a-z]//g]]) + diff(sixlines(ctrl1..punct1..digits..punct2..upper..punct3..punct4.. + ctrl2..iso_text)) + end) + it('is working', function() + source([[ + 1 s/\%#=0\L//g + 2 s/\%#=1\L//g + 3 s/\%#=2\L//g + 4 s/\%#=0[^a-z]//g + 5 s/\%#=1[^a-z]//g + 6 s/\%#=2[^a-z]//g]]) + expect([[ + abcdefghiwxyz + abcdefghiwxyz + abcdefghiwxyz + abcdefghiwxyz + abcdefghiwxyz + abcdefghiwxyz]]) + end) + it('is working', function() + source([[ + 1 s/\%#=0\u//g + 2 s/\%#=1\u//g + 3 s/\%#=2\u//g + 4 s/\%#=0[A-Z]//g + 5 s/\%#=1[A-Z]//g + 6 s/\%#=2[A-Z]//g]]) + diff(sixlines(ctrl1..punct1..digits..punct2..punct3..lower..punct4.. + ctrl2..iso_text)) + end) + it('is working', function() + source([[ + 1 s/\%#=0\U//g + 2 s/\%#=1\U//g + 3 s/\%#=2\U//g + 4 s/\%#=0[^A-Z]//g + 5 s/\%#=1[^A-Z]//g + 6 s/\%#=2[^A-Z]//g]]) + expect([[ + ABCDEFGHIXYZ + ABCDEFGHIXYZ + ABCDEFGHIXYZ + ABCDEFGHIXYZ + ABCDEFGHIXYZ + ABCDEFGHIXYZ]]) + end) +end) |