|
| 1 | +source vim/sensei.vim |
| 2 | + |
| 3 | +function Require(actual, required) |
| 4 | + for i in range(len(a:required)) |
| 5 | + if a:actual[i] > a:required[i] |
| 6 | + return 1 |
| 7 | + elseif a:actual[i] < a:required[i] |
| 8 | + return 0 |
| 9 | + endif |
| 10 | + endfor |
| 11 | + return 1 |
| 12 | +endfunction |
| 13 | + |
| 14 | +function GhcVersion(name) |
| 15 | + return matchlist(a:name, '\vghc-(\d+)\.(\d+)\.(\d+)\.errors')[1:3] |
| 16 | +endfunction |
| 17 | + |
| 18 | +function PopulateQuickFixList(name) |
| 19 | + SUCCESS a:name |
| 20 | + execute "cgetfile " . a:name |
| 21 | + return filter(getqflist(), 'v:val.valid') |
| 22 | +endfunction |
| 23 | + |
| 24 | +function GhcErrorsFor(name) |
| 25 | + let errors = glob("vim/test/assets/" . a:name . ".*.errors", v:true, v:true) |
| 26 | + call ShouldBe(len(errors), 5) |
| 27 | + return errors |
| 28 | +endfunction |
| 29 | + |
| 30 | +for name in GhcErrorsFor("lexical-error.hs") |
| 31 | + let errors = PopulateQuickFixList(name) |
| 32 | + call ShouldBe(len(errors), 1) |
| 33 | + |
| 34 | + let err = errors[0] |
| 35 | + call ShouldBe(bufname(err.bufnr), "lexical-error.hs") |
| 36 | + call ShouldBe(err.lnum, 1) |
| 37 | + call ShouldBe(err.col, 11) |
| 38 | + call ShouldBe(err.end_lnum, 0) |
| 39 | + call ShouldBe(err.end_col, 0) |
| 40 | + call ShouldBe(err.type, 'e') |
| 41 | + if Require(GhcVersion(name), [9,6]) |
| 42 | + call ShouldBe(err.nr, 21231) |
| 43 | + else |
| 44 | + call ShouldBe(err.nr, -1) |
| 45 | + endif |
| 46 | + call ShouldBe(err.text, "\n lexical error in string/character literal at character '\\n'") |
| 47 | +endfor |
| 48 | + |
| 49 | +for name in GhcErrorsFor("parse-error.hs") |
| 50 | + let errors = PopulateQuickFixList(name) |
| 51 | + call ShouldBe(len(errors), 1) |
| 52 | + |
| 53 | + let err = errors[0] |
| 54 | + call ShouldBe(bufname(err.bufnr), "parse-error.hs") |
| 55 | + call ShouldBe(err.lnum, 1) |
| 56 | + call ShouldBe(err.col, 1) |
| 57 | + call ShouldBe(err.end_lnum, 0) |
| 58 | + call ShouldBe(err.end_col, 0) |
| 59 | + call ShouldBe(err.type, 'e') |
| 60 | + if Require(GhcVersion(name), [9,8]) |
| 61 | + call ShouldBe(err.nr, 25277) |
| 62 | + else |
| 63 | + call ShouldBe(err.nr, -1) |
| 64 | + endif |
| 65 | + call ShouldBe(err.text, "\n Parse error: module header, import declaration\n or top-level declaration expected.") |
| 66 | +endfor |
| 67 | + |
| 68 | +for name in GhcErrorsFor("type-error.hs") |
| 69 | + let errors = PopulateQuickFixList(name) |
| 70 | + call ShouldBe(len(errors), 1) |
| 71 | + |
| 72 | + let err = errors[0] |
| 73 | + call ShouldBe(bufname(err.bufnr), "type-error.hs") |
| 74 | + call ShouldBe(err.lnum, 2) |
| 75 | + call ShouldBe(err.col, 7) |
| 76 | + call ShouldBe(err.end_lnum, 0) |
| 77 | + call ShouldBe(err.end_col, 0) |
| 78 | + call ShouldBe(err.type, 'e') |
| 79 | + if Require(GhcVersion(name), [9,6]) |
| 80 | + call ShouldBe(err.nr, 83865) |
| 81 | + call ShouldBe(err.text, "\n Couldn't match type ‘Int’ with ‘[Char]’\n Expected: String\n Actual: Int") |
| 82 | + else |
| 83 | + call ShouldBe(err.nr, -1) |
| 84 | + 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") |
| 85 | + endif |
| 86 | +endfor |
| 87 | + |
| 88 | +for name in GhcErrorsFor("suggested-fix.hs") |
| 89 | + let errors = PopulateQuickFixList(name) |
| 90 | + call ShouldBe(len(errors), 2) |
| 91 | + |
| 92 | + let err = errors[0] |
| 93 | + call ShouldBe(bufname(err.bufnr), "suggested-fix.hs") |
| 94 | + call ShouldBe(err.lnum, 1) |
| 95 | + call ShouldBe(err.col, 1) |
| 96 | + call ShouldBe(err.end_lnum, 0) |
| 97 | + call ShouldBe(err.end_col, 0) |
| 98 | + call ShouldBe(err.type, 'e') |
| 99 | + if Require(GhcVersion(name), [9,6]) |
| 100 | + call ShouldBe(err.nr, 44432) |
| 101 | + else |
| 102 | + call ShouldBe(err.nr, -1) |
| 103 | + endif |
| 104 | + call ShouldBe(err.text, "\n The type signature for ‘foo’ lacks an accompanying binding") |
| 105 | + |
| 106 | + let err = errors[1] |
| 107 | + call ShouldBe(bufname(err.bufnr), "suggested-fix.hs") |
| 108 | + call ShouldBe(err.lnum, 4) |
| 109 | + call ShouldBe(err.col, 1) |
| 110 | + call ShouldBe(err.end_lnum, 0) |
| 111 | + call ShouldBe(err.end_col, 0) |
| 112 | + call ShouldBe(err.type, 'e') |
| 113 | + if Require(GhcVersion(name), [9,6]) |
| 114 | + call ShouldBe(err.nr, 44432) |
| 115 | + else |
| 116 | + call ShouldBe(err.nr, -1) |
| 117 | + endif |
| 118 | + call ShouldBe(err.text, "\n The type signature for ‘bar’ lacks an accompanying binding") |
| 119 | +endfor |
| 120 | + |
| 121 | +for name in GhcErrorsFor("suggested-fix-multiline.hs") |
| 122 | + let errors = PopulateQuickFixList(name) |
| 123 | + call ShouldBe(len(errors), 2) |
| 124 | + |
| 125 | + let err = errors[0] |
| 126 | + call ShouldBe(bufname(err.bufnr), "suggested-fix-multiline.hs") |
| 127 | + call ShouldBe(err.lnum, 1) |
| 128 | + call ShouldBe(err.col, 1) |
| 129 | + call ShouldBe(err.end_lnum, 0) |
| 130 | + call ShouldBe(err.end_col, 0) |
| 131 | + call ShouldBe(err.type, 'e') |
| 132 | + if Require(GhcVersion(name), [9,6]) |
| 133 | + call ShouldBe(err.nr, 44432) |
| 134 | + else |
| 135 | + call ShouldBe(err.nr, -1) |
| 136 | + endif |
| 137 | + call ShouldBe(err.text, "\n The type signature for ‘foo’ lacks an accompanying binding") |
| 138 | + |
| 139 | + let err = errors[1] |
| 140 | + call ShouldBe(bufname(err.bufnr), "suggested-fix-multiline.hs") |
| 141 | + call ShouldBe(err.lnum, 4) |
| 142 | + call ShouldBe(err.col, 1) |
| 143 | + call ShouldBe(err.end_lnum, 0) |
| 144 | + call ShouldBe(err.end_col, 0) |
| 145 | + call ShouldBe(err.type, 'e') |
| 146 | + if Require(GhcVersion(name), [9,6]) |
| 147 | + call ShouldBe(err.nr, 44432) |
| 148 | + else |
| 149 | + call ShouldBe(err.nr, -1) |
| 150 | + endif |
| 151 | + call ShouldBe(err.text, "\n The type signature for ‘bar’ lacks an accompanying binding") |
| 152 | +endfor |
| 153 | + |
| 154 | +let errors = PopulateQuickFixList("vim/test/assets/hspec.hs.errors") |
| 155 | +call ShouldBe(len(errors), 1) |
| 156 | + |
| 157 | +let err = errors[0] |
| 158 | +call ShouldBe(bufname(err.bufnr), "vim/test/assets/hspec.hs") |
| 159 | +call ShouldBe(err.lnum, 6) |
| 160 | +call ShouldBe(err.col, 11) |
| 161 | +call ShouldBe(err.end_lnum, 0) |
| 162 | +call ShouldBe(err.end_col, 0) |
| 163 | +call ShouldBe(err.type, '') |
| 164 | +call ShouldBe(err.nr, -1) |
| 165 | +call ShouldBe(err.text, "") |
0 commit comments