Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 47f26f3

Browse files
committed
Add Functional tests
1 parent d8931f5 commit 47f26f3

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

test/functional/TypeDefinitionSpec.hs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
module TypeDefinitionSpec where
2+
3+
import Control.Monad.IO.Class
4+
import Language.Haskell.LSP.Test
5+
import Language.Haskell.LSP.Types
6+
import Haskell.Ide.Engine.PluginUtils
7+
import System.Directory
8+
import Test.Hspec
9+
import TestUtils
10+
11+
spec :: Spec
12+
spec = describe "type definitions" $ do
13+
it "finds local definition of record variable"
14+
$ runSession hieCommand fullCaps "test/testdata/gototest"
15+
$ do
16+
doc <- openDoc "src/Lib.hs" "haskell"
17+
defs <- getTypeDefinitions doc (toPos (11, 23))
18+
liftIO $ do
19+
fp <- canonicalizePath "test/testdata/gototest/src/Lib.hs"
20+
defs
21+
`shouldBe` [ Location (filePathToUri fp)
22+
(Range (toPos (8, 1)) (toPos (8, 29)))
23+
]
24+
it "finds local definition of newtype variable"
25+
$ runSession hieCommand fullCaps "test/testdata/gototest"
26+
$ do
27+
doc <- openDoc "src/Lib.hs" "haskell"
28+
defs <- getTypeDefinitions doc (toPos (16, 21))
29+
liftIO $ do
30+
fp <- canonicalizePath "test/testdata/gototest/src/Lib.hs"
31+
defs
32+
`shouldBe` [ Location (filePathToUri fp)
33+
(Range (toPos (13, 1)) (toPos (13, 30)))
34+
]
35+
it "finds local definition of sum type variable"
36+
$ runSession hieCommand fullCaps "test/testdata/gototest"
37+
$ do
38+
doc <- openDoc "src/Lib.hs" "haskell"
39+
defs <- getTypeDefinitions doc (toPos (21, 13))
40+
liftIO $ do
41+
fp <- canonicalizePath "test/testdata/gototest/src/Lib.hs"
42+
defs
43+
`shouldBe` [ Location (filePathToUri fp)
44+
(Range (toPos (18, 1)) (toPos (18, 26)))
45+
]
46+
it "finds local definition of sum type contructor"
47+
$ runSession hieCommand fullCaps "test/testdata/gototest"
48+
$ do
49+
doc <- openDoc "src/Lib.hs" "haskell"
50+
defs <- getTypeDefinitions doc (toPos (24, 7))
51+
liftIO $ do
52+
fp <- canonicalizePath "test/testdata/gototest/src/Lib.hs"
53+
defs
54+
`shouldBe` [ Location (filePathToUri fp)
55+
(Range (toPos (18, 1)) (toPos (18, 26)))
56+
]
57+
it "can not find non-local definition of type def"
58+
$ runSession hieCommand fullCaps "test/testdata/gototest"
59+
$ do
60+
doc <- openDoc "src/Lib.hs" "haskell"
61+
defs <- getTypeDefinitions doc (toPos (30, 17))
62+
liftIO $ defs `shouldBe` []
63+
64+
it "find local definition of type def"
65+
$ runSession hieCommand fullCaps "test/testdata/gototest"
66+
$ do
67+
doc <- openDoc "src/Lib2.hs" "haskell"
68+
otherDoc <- openDoc "src/Lib.hs" "haskell"
69+
closeDoc otherDoc
70+
defs <- getTypeDefinitions doc (toPos (35, 16))
71+
liftIO $ do
72+
fp <- canonicalizePath "test/testdata/gototest/src/Lib.hs"
73+
defs
74+
`shouldBe` [ Location (filePathToUri fp)
75+
(Range (toPos (18, 1)) (toPos (18, 26)))
76+
]
77+
78+
it "find type-definition of type def in component"
79+
$ runSession hieCommand fullCaps "test/testdata/gototest"
80+
$ do
81+
doc <- openDoc "src/Lib.hs" "haskell"
82+
defs <- getTypeDefinitions doc (toPos (13, 20))
83+
liftIO $ do
84+
fp <- canonicalizePath "test/testdata/gototest/src/Lib.hs"
85+
defs
86+
`shouldBe` [ Location (filePathToUri fp)
87+
(Range (toPos (8, 1)) (toPos (8, 29)))
88+
]
89+
it "find definition of parameterized data type"
90+
$ runSession hieCommand fullCaps "test/testdata/gototest"
91+
$ do
92+
doc <- openDoc "src/Lib.hs" "haskell"
93+
defs <- getTypeDefinitions doc (toPos (40, 19))
94+
liftIO $ do
95+
fp <- canonicalizePath "test/testdata/gototest/src/Lib.hs"
96+
defs
97+
`shouldBe` [ Location (filePathToUri fp)
98+
(Range (toPos (37, 1)) (toPos (37, 31)))
99+
]

0 commit comments

Comments
 (0)