Skip to content

Instantly share code, notes, and snippets.

@alex-harvey-z3q
Created April 1, 2019 09:21
Show Gist options
  • Save alex-harvey-z3q/9838a85485790a0b049ff20057707f76 to your computer and use it in GitHub Desktop.
Save alex-harvey-z3q/9838a85485790a0b049ff20057707f76 to your computer and use it in GitHub Desktop.
## Tests to go with https://stackoverflow.com/a/55451627/3787051
setUp() {
cat > /tmp/before <<EOF
aaa
bbb
ccc
bbb
ccc
eee
EOF
cat > /tmp/expected <<EOF
aaa
bbb
ccc
bbb
ccc
ddd
eee
EOF
}
script_under_test1() {
cat <<EOF
function! AddLine()
call search("bbb")
call search("bbb")
let l:foundline = search("ccc")
call append(l:foundline, "ddd")
wq!
endfunction
EOF
}
script_under_test2() {
cat <<EOF
function! AddLine()
normal /bbb
n/ccc
oddd
wq!
endfunction
EOF
}
testIt1() {
script_under_test1 > /tmp/script.vim
vim -u /tmp/script.vim -c 'call AddLine()' /tmp/before
assertEquals "" "$(diff -u /tmp/expected /tmp/before)"
}
testIt2() {
script_under_test2 > /tmp/script.vim
vim -u /tmp/script.vim -c 'call AddLine()' /tmp/before
assertEquals "" "$(diff -u /tmp/expected /tmp/before)"
}
. shunit2
## Run them
▶ bash test.sh
testIt1
testIt2
Ran 2 tests.
OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment