mirror of
https://github.com/keith/swift.vim.git
synced 2025-12-12 20:35:53 +01:00
Add regression test (#157)
This commit is contained in:
20
.github/workflows/test.yml
vendored
Normal file
20
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Run Test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Run test
|
||||
run: ./run_test.sh
|
||||
23
autoindent.vim
Normal file
23
autoindent.vim
Normal file
@@ -0,0 +1,23 @@
|
||||
if empty($OUTPUT_FILE)
|
||||
echom "Error: Environment variable OUTPUT_FILE is not set."
|
||||
cquit! 1
|
||||
endif
|
||||
|
||||
set nocompatible
|
||||
set runtimepath^=$PWD
|
||||
filetype plugin indent on
|
||||
|
||||
syntax on
|
||||
augroup swiftIndent
|
||||
autocmd!
|
||||
autocmd BufRead,BufNewFile *.swift setlocal shiftwidth=4 expandtab
|
||||
augroup END
|
||||
|
||||
" Apply autoindent, save and quit.
|
||||
function! s:RemoveWhitespaceAndReindent()
|
||||
silent %s/^\s\+//
|
||||
normal gg=G
|
||||
execute 'write ' . fnameescape($OUTPUT_FILE)
|
||||
quit!
|
||||
endfunction
|
||||
autocmd BufReadPost * call s:RemoveWhitespaceAndReindent()
|
||||
18
run_test.sh
Executable file
18
run_test.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
tempdir=$(mktemp -d)
|
||||
trap cleanup EXIT
|
||||
|
||||
cleanup() {
|
||||
rm -r "$tempdir"
|
||||
}
|
||||
|
||||
for example_file in example/*.swift; do
|
||||
autoindented_file="$tempdir/${example_file##*/}"
|
||||
OUTPUT_FILE="$autoindented_file" vim -u autoindent.vim "$example_file"
|
||||
diff -u --color=auto "$example_file" "$autoindented_file"
|
||||
done
|
||||
|
||||
echo "test passed!"
|
||||
Reference in New Issue
Block a user