Skip to content

Commit df96e18

Browse files
committed
[ test ] Primitive testing for hover
1 parent 87c1036 commit df96e18

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ node_modules/
2121
cabal.sandbox.config
2222
cabal.project.local
2323
*~
24+
25+
26+
*.agdai

test/Test/LSP.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Agda
66
import Control.Monad.IO.Class
77
import qualified Data.Aeson as JSON
88
import Language.LSP.Protocol.Message
9+
import Language.LSP.Protocol.Types
910
import Language.LSP.Test
1011
import Switchboard (agdaCustomMethod)
1112
import Test.Tasty
@@ -24,14 +25,18 @@ demo alsPath = do
2425
runSession alsPath fullLatestClientCaps "test/data/" $ do
2526
doc <- openDoc "A.agda" "agda"
2627

27-
-- Use your favourite favourite combinators.
28-
-- skipManyTill loggingNotification (count 1 publishDiagnosticsNotification)
28+
-- hover
29+
TResponseMessage _ _ rsp <- request SMethod_TextDocumentHover (HoverParams doc (Position 3 9) Nothing)
30+
case rsp of
31+
Right (InL (Hover (InL (MarkupContent _ content)) (Just (Range start end)))) -> liftIO $ do
32+
content @?= "\n```agda-language-server\nAgda.Primitive.Set\n```\n"
33+
start @?= Position 3 9
34+
end @?= Position 3 9
35+
_ -> liftIO $ assertFailure "Unexpected response"
2936

37+
-- agda-mode:load
3038
testCustomMethod "IOTCM \"test/data/A.agdaa\" NonInteractive Direct( Cmd_load \"test/data/A.agda\" [] )"
3139

32-
-- Or use one of the helper functions
33-
-- getDocumentSymbols doc >>= liftIO . print
34-
3540
-- | Sends a custom method request to the server and expects a response of `CmdRes Nothing`
3641
testCustomMethod :: String -> Session ()
3742
testCustomMethod cmd = do

test/Test/SrcLoc.hs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module Test.SrcLoc where
22

3-
import Test.Tasty
4-
import Test.Tasty.HUnit
5-
import Data.List (sort)
63
import Agda.Position
7-
import Data.Text (Text)
84
import qualified Data.IntMap as IntMap
5+
import Data.List (sort)
6+
import Data.Text (Text)
7+
import Test.Tasty
8+
import Test.Tasty.HUnit
99

1010
tests :: TestTree
1111
tests = testGroup "Source Location" [positionToOffsetTests, offsetToPositionTests]
@@ -16,41 +16,40 @@ positionToOffsetTests :: TestTree
1616
positionToOffsetTests =
1717
testGroup
1818
"Position => Offset"
19-
[ testCase "cached table" $ IntMap.toList (unToOffset table) @?= [(1, 4), (2, 9), (3, 12)]
20-
, testCase "line 0" $ run [(0, 0), (0, 1), (0, 2), (0, 3)] @?= [0, 1, 2, 3]
21-
, testCase "line 1" $ run [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)] @?= [4, 5, 6, 7, 8]
22-
, testCase "line 2" $ run [(2, 0), (2, 1)] @?= [9, 10]
23-
, testCase "line 3" $ run [(3, 0), (3, 1)] @?= [12, 13]
19+
[ testCase "cached table" $ IntMap.toList (unToOffset table) @?= [(1, 4), (2, 9), (3, 12)],
20+
testCase "line 0" $ run [(0, 0), (0, 1), (0, 2), (0, 3)] @?= [0, 1, 2, 3],
21+
testCase "line 1" $ run [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)] @?= [4, 5, 6, 7, 8],
22+
testCase "line 2" $ run [(2, 0), (2, 1)] @?= [9, 10],
23+
testCase "line 3" $ run [(3, 0), (3, 1)] @?= [12, 13]
2424
]
2525
where
26-
text :: Text
26+
text :: Text
2727
text = "012\n456\r\n90\r23"
2828

2929
table :: ToOffset
3030
table = makeToOffset text
3131

3232
run :: [(Int, Int)] -> [Int]
3333
run = map (toOffset table)
34-
34+
3535
--------------------------------------------------------------------------------
3636

3737
offsetToPositionTests :: TestTree
3838
offsetToPositionTests =
3939
testGroup
4040
"Offset => Position"
41-
[ testCase "cached table" $ IntMap.toList (unFromOffset table) @?= [(4, 1), (9, 2), (12, 3)]
42-
, testCase "line 0" $ run [0, 1, 2, 3] @?= [(0, 0), (0, 1), (0, 2), (0, 3)]
43-
, testCase "line 1" $ run [4, 5, 6, 7, 8] @?= [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)]
44-
, testCase "line 2" $ run [9, 10] @?= [(2, 0), (2, 1)]
45-
, testCase "line 3" $ run [12, 13] @?= [(3, 0), (3, 1)]
41+
[ testCase "cached table" $ IntMap.toList (unFromOffset table) @?= [(4, 1), (9, 2), (12, 3)],
42+
testCase "line 0" $ run [0, 1, 2, 3] @?= [(0, 0), (0, 1), (0, 2), (0, 3)],
43+
testCase "line 1" $ run [4, 5, 6, 7, 8] @?= [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4)],
44+
testCase "line 2" $ run [9, 10] @?= [(2, 0), (2, 1)],
45+
testCase "line 3" $ run [12, 13] @?= [(3, 0), (3, 1)]
4646
]
4747
where
48-
text :: Text
48+
text :: Text
4949
text = "012\n456\r\n90\r23"
5050

5151
table :: FromOffset
5252
table = makeFromOffset text
5353

5454
run :: [Int] -> [(Int, Int)]
5555
run = map (fromOffset table)
56-

0 commit comments

Comments
 (0)