Skip to content

Commit 2fa181d

Browse files
authored
Add regression test (#157)
1 parent 30ce897 commit 2fa181d

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Run Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '*'
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Check out repository
17+
uses: actions/checkout@v4
18+
19+
- name: Run test
20+
run: ./run_test.sh

autoindent.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if empty($OUTPUT_FILE)
2+
echom "Error: Environment variable OUTPUT_FILE is not set."
3+
cquit! 1
4+
endif
5+
6+
set nocompatible
7+
set runtimepath^=$PWD
8+
filetype plugin indent on
9+
10+
syntax on
11+
augroup swiftIndent
12+
autocmd!
13+
autocmd BufRead,BufNewFile *.swift setlocal shiftwidth=4 expandtab
14+
augroup END
15+
16+
" Apply autoindent, save and quit.
17+
function! s:RemoveWhitespaceAndReindent()
18+
silent %s/^\s\+//
19+
normal gg=G
20+
execute 'write ' . fnameescape($OUTPUT_FILE)
21+
quit!
22+
endfunction
23+
autocmd BufReadPost * call s:RemoveWhitespaceAndReindent()

run_test.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
tempdir=$(mktemp -d)
6+
trap cleanup EXIT
7+
8+
cleanup() {
9+
rm -r "$tempdir"
10+
}
11+
12+
for example_file in example/*.swift; do
13+
autoindented_file="$tempdir/${example_file##*/}"
14+
OUTPUT_FILE="$autoindented_file" vim -u autoindent.vim "$example_file"
15+
diff -u --color=auto "$example_file" "$autoindented_file"
16+
done
17+
18+
echo "test passed!"

0 commit comments

Comments
 (0)