Skip to content

Commit 9f3fc61

Browse files
authored
Add a test to check diagnistic ranges are printed 1-based (#878)
Recently, we fixed a bug in `prettyRange` where lines where rendered 1-based but columns 0-based. Let's make sure we don't get into such weird situations again by adding a test.
1 parent 2896906 commit 9f3fc61

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/exe/Main.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import Data.Typeable
3030
import Development.IDE.Spans.Common
3131
import Development.IDE.Test
3232
import Development.IDE.Test.Runfiles
33+
import qualified Development.IDE.Types.Diagnostics as Diagnostics
3334
import Development.IDE.Types.Location
3435
import Development.Shake (getDirectoryFilesIO)
3536
import qualified Experiments as Bench
@@ -3706,6 +3707,23 @@ unitTests = do
37063707
uriToFilePath' uri @?= Just ""
37073708
, testCase "Key with empty file path roundtrips via Binary" $
37083709
Binary.decode (Binary.encode (Q ((), emptyFilePath))) @?= Q ((), emptyFilePath)
3710+
, testCase "showDiagnostics prints ranges 1-based (like vscode)" $ do
3711+
let diag = ("", Diagnostics.ShowDiag, Diagnostic
3712+
{ _range = Range
3713+
{ _start = Position{_line = 0, _character = 1}
3714+
, _end = Position{_line = 2, _character = 3}
3715+
}
3716+
, _severity = Nothing
3717+
, _code = Nothing
3718+
, _source = Nothing
3719+
, _message = ""
3720+
, _relatedInformation = Nothing
3721+
, _tags = Nothing
3722+
})
3723+
let shown = T.unpack (Diagnostics.showDiagnostics [diag])
3724+
let expected = "1:2-3:4"
3725+
assertBool (unwords ["expected to find range", expected, "in diagnostic", shown]) $
3726+
expected `isInfixOf` shown
37093727
]
37103728

37113729
positionMappingTests :: TestTree

0 commit comments

Comments
 (0)