Skip to content

Commit

Permalink
Update vim/sensei.test.vim
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Sep 18, 2024
1 parent 04cef0c commit 0f0cae5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 97 deletions.
172 changes: 89 additions & 83 deletions vim/sensei.test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,139 +21,145 @@ function PopulateQuickFixList(name)
return filter(getqflist(), 'v:val.valid')
endfunction

for name in glob("vim/test/assets/lexical-error.hs.*.errors", v:true, v:true)
function GhcErrorsFor(name)
let foo = glob("vim/test/assets/" . a:name . ".*.errors", v:true, v:true)
call ShouldBe(len(foo), 5)
return foo
endfunction

for name in GhcErrorsFor("lexical-error.hs")
let errors = PopulateQuickFixList(name)
call assert_equal(1, len(errors))
call ShouldBe(len(errors), 1)

let err = errors[0]
call assert_equal("lexical-error.hs", bufname(err.bufnr))
call assert_equal(1, err.lnum)
call assert_equal(11, err.col)
call assert_equal(0, err.end_lnum)
call assert_equal(0, err.end_col)
call assert_equal('e', err.type)
call ShouldBe(bufname(err.bufnr), "lexical-error.hs")
call ShouldBe(err.lnum, 1)
call ShouldBe(err.col, 11)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call assert_equal(21231, err.nr)
call ShouldBe(err.nr, 21231)
else
call assert_equal(-1, err.nr)
call ShouldBe(err.nr, -1)
endif
call assert_equal("\n lexical error in string/character literal at character '\\n'", err.text)
call ShouldBe(err.text, "\n lexical error in string/character literal at character '\\n'")
endfor

for name in glob("vim/test/assets/parse-error.hs.*.errors", v:true, v:true)
for name in GhcErrorsFor("parse-error.hs")
let errors = PopulateQuickFixList(name)
call assert_equal(1, len(errors))
call ShouldBe(len(errors), 1)

let err = errors[0]
call assert_equal("parse-error.hs", bufname(err.bufnr))
call assert_equal(1, err.lnum)
call assert_equal(1, err.col)
call assert_equal(0, err.end_lnum)
call assert_equal(0, err.end_col)
call assert_equal('e', err.type)
call ShouldBe(bufname(err.bufnr), "parse-error.hs")
call ShouldBe(err.lnum, 1)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,8])
call assert_equal(25277, err.nr)
call ShouldBe(err.nr, 25277)
else
call assert_equal(-1, err.nr)
call ShouldBe(err.nr, -1)
endif
call assert_equal("\n Parse error: module header, import declaration\n or top-level declaration expected.", err.text)
call ShouldBe(err.text, "\n Parse error: module header, import declaration\n or top-level declaration expected.")
endfor

for name in glob("vim/test/assets/type-error.hs.*.errors", v:true, v:true)
for name in GhcErrorsFor("type-error.hs")
let errors = PopulateQuickFixList(name)
call assert_equal(1, len(errors))
call ShouldBe(len(errors), 1)

let err = errors[0]
call assert_equal("type-error.hs", bufname(err.bufnr))
call assert_equal(2, err.lnum)
call assert_equal(7, err.col)
call assert_equal(0, err.end_lnum)
call assert_equal(0, err.end_col)
call assert_equal('e', err.type)
call ShouldBe(bufname(err.bufnr), "type-error.hs")
call ShouldBe(err.lnum, 2)
call ShouldBe(err.col, 7)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call assert_equal(83865, err.nr)
call assert_equal("\n Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int", err.text)
call ShouldBe(err.nr, 83865)
call ShouldBe(err.text, "\n Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int")
else
call assert_equal(-1, err.nr)
call assert_equal("\n • Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int\n • In the expression: 23 :: Int\n In an equation for ‘foo’: foo = 23 :: Int", err.text)
call ShouldBe(err.nr, -1)
call ShouldBe(err.text, "\n • Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int\n • In the expression: 23 :: Int\n In an equation for ‘foo’: foo = 23 :: Int")
endif
endfor

for name in glob("vim/test/assets/suggested-fix.hs.*.errors", v:true, v:true)
for name in GhcErrorsFor("suggested-fix.hs")
let errors = PopulateQuickFixList(name)
call assert_equal(2, len(errors))
call ShouldBe(len(errors), 2)

let err = errors[0]
call assert_equal("suggested-fix.hs", bufname(err.bufnr))
call assert_equal(1, err.lnum)
call assert_equal(1, err.col)
call assert_equal(0, err.end_lnum)
call assert_equal(0, err.end_col)
call assert_equal('e', err.type)
call ShouldBe(bufname(err.bufnr), "suggested-fix.hs")
call ShouldBe(err.lnum, 1)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call assert_equal(44432, err.nr)
call ShouldBe(err.nr, 44432)
else
call assert_equal(-1, err.nr)
call ShouldBe(err.nr, -1)
endif
call assert_equal("\n The type signature for ‘foo’ lacks an accompanying binding", err.text)
call ShouldBe(err.text, "\n The type signature for ‘foo’ lacks an accompanying binding")

let err = errors[1]
call assert_equal("suggested-fix.hs", bufname(err.bufnr))
call assert_equal(4, err.lnum)
call assert_equal(1, err.col)
call assert_equal(0, err.end_lnum)
call assert_equal(0, err.end_col)
call assert_equal('e', err.type)
call ShouldBe(bufname(err.bufnr), "suggested-fix.hs")
call ShouldBe(err.lnum, 4)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call assert_equal(44432, err.nr)
call ShouldBe(err.nr, 44432)
else
call assert_equal(-1, err.nr)
call ShouldBe(err.nr, -1)
endif
call assert_equal("\n The type signature for ‘bar’ lacks an accompanying binding", err.text)
call ShouldBe(err.text, "\n The type signature for ‘bar’ lacks an accompanying binding")
endfor

for name in glob("vim/test/assets/suggested-fix-multiline.hs.*.errors", v:true, v:true)
for name in GhcErrorsFor("suggested-fix-multiline.hs")
let errors = PopulateQuickFixList(name)
call assert_equal(2, len(errors))
call ShouldBe(len(errors), 2)

let err = errors[0]
call assert_equal("suggested-fix-multiline.hs", bufname(err.bufnr))
call assert_equal(1, err.lnum)
call assert_equal(1, err.col)
call assert_equal(0, err.end_lnum)
call assert_equal(0, err.end_col)
call assert_equal('e', err.type)
call ShouldBe(bufname(err.bufnr), "suggested-fix-multiline.hs")
call ShouldBe(err.lnum, 1)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call assert_equal(44432, err.nr)
call ShouldBe(err.nr, 44432)
else
call assert_equal(-1, err.nr)
call ShouldBe(err.nr, -1)
endif
call assert_equal("\n The type signature for ‘foo’ lacks an accompanying binding", err.text)
call ShouldBe(err.text, "\n The type signature for ‘foo’ lacks an accompanying binding")

let err = errors[1]
call assert_equal("suggested-fix-multiline.hs", bufname(err.bufnr))
call assert_equal(4, err.lnum)
call assert_equal(1, err.col)
call assert_equal(0, err.end_lnum)
call assert_equal(0, err.end_col)
call assert_equal('e', err.type)
call ShouldBe(bufname(err.bufnr), "suggested-fix-multiline.hs")
call ShouldBe(err.lnum, 4)
call ShouldBe(err.col, 1)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, 'e')
if Require(GhcVersion(name), [9,6])
call assert_equal(44432, err.nr)
call ShouldBe(err.nr, 44432)
else
call assert_equal(-1, err.nr)
call ShouldBe(err.nr, -1)
endif
call assert_equal("\n The type signature for ‘bar’ lacks an accompanying binding", err.text)
call ShouldBe(err.text, "\n The type signature for ‘bar’ lacks an accompanying binding")
endfor

let errors = PopulateQuickFixList("vim/test/assets/hspec.hs.errors")
call assert_equal(1, len(errors))
call ShouldBe(len(errors), 1)

let err = errors[0]
call assert_equal("vim/test/assets/hspec.hs", bufname(err.bufnr))
call assert_equal(6, err.lnum)
call assert_equal(11, err.col)
call assert_equal(0, err.end_lnum)
call assert_equal(0, err.end_col)
call assert_equal('', err.type)
call assert_equal(-1, err.nr)
call assert_equal("", err.text)
call ShouldBe(bufname(err.bufnr), "vim/test/assets/hspec.hs")
call ShouldBe(err.lnum, 6)
call ShouldBe(err.col, 11)
call ShouldBe(err.end_lnum, 0)
call ShouldBe(err.end_col, 0)
call ShouldBe(err.type, '')
call ShouldBe(err.nr, -1)
call ShouldBe(err.text, "")
18 changes: 5 additions & 13 deletions vim/run-tests.vim → vim/test/run.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ highlight green ctermfg=green
command -nargs=* FAILURE echohl red | echo <args> | echohl none
command -nargs=* SUCCESS echohl green | echo <args> | echohl none

function CheckResults()
if !empty(v:errors)
FAILURE "FAILURES:\n"
for error in v:errors
echo "\n"
FAILURE substitute(substitute(substitute(error, "^command line..script ", "", ""), " Expected ", "\n\nexpected: ", ""), " but got", "\n but got:", "")
endfor
cquit
function ShouldBe(actual, expected)
if !(a:actual ==# a:expected)
throw "expected: " . a:expected . "\n but got: " . a:actual
endif
endfunction

Expand All @@ -26,14 +21,11 @@ try
execute "source " . name
endfor
catch
FAILURE substitute(v:throwpoint, "^command line..script ", "", "")
FAILURE substitute(substitute(v:throwpoint, "^command line..script ", "", ""), expand("<script>") . "\\v\\[\\d+]\\.\\.(.*)\\[(\\d+)\\]\\.\\.function ShouldBe, line \\d+", "\\1:\\2", "")
echo "\n"
FAILURE v:exception
cquit
endtry

echo "\n"

call CheckResults()
SUCCESS "SUCCESS"
SUCCESS "\nSUCCESS"
quit
2 changes: 1 addition & 1 deletion vim/test/watch.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
while true; do
echo
./vim/run-tests.vim
./vim/test/run.vim
inotifywait -e modify -e attrib -e close_write -e move -e create -e delete -r vim/
done

0 comments on commit 0f0cae5

Please sign in to comment.