summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPhilFreeman <>2016-09-24 20:26:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2016-09-24 20:26:00 (GMT)
commit2acef0fe7e56d4fd60d611d3cf48b5ea37537fd0 (patch)
treeb364973659ce94072fdaf3c61ec694ef6d14d9c2 /tests
parent4d61f80cdcce39749da53bdcab7d71e406710222 (diff)
version 0.10.00.10.0
Diffstat (limited to 'tests')
-rw-r--r--tests/Language/PureScript/Ide/ImportsSpec.hs2
-rw-r--r--tests/Language/PureScript/Ide/Integration.hs28
-rw-r--r--tests/Language/PureScript/Ide/MatcherSpec.hs16
-rw-r--r--tests/Language/PureScript/Ide/ReexportsSpec.hs2
-rw-r--r--tests/Language/PureScript/Ide/SourceFile/IntegrationSpec.hs21
-rw-r--r--tests/Language/PureScript/Ide/SourceFileSpec.hs10
-rw-r--r--tests/Language/PureScript/Ide/StateSpec.hs51
-rw-r--r--tests/TestDocs.hs1
-rw-r--r--tests/TestPscIde.hs1
-rw-r--r--tests/TestPsci.hs1
-rw-r--r--tests/TestUtils.hs2
-rw-r--r--tests/support/bower.json5
12 files changed, 97 insertions, 43 deletions
diff --git a/tests/Language/PureScript/Ide/ImportsSpec.hs b/tests/Language/PureScript/Ide/ImportsSpec.hs
index 5680020..7cea546 100644
--- a/tests/Language/PureScript/Ide/ImportsSpec.hs
+++ b/tests/Language/PureScript/Ide/ImportsSpec.hs
@@ -70,7 +70,7 @@ spec = do
addValueImport i mn is =
prettyPrintImportSection (addExplicitImport' (IdeValue (P.Ident i) wildcard) mn is)
addOpImport op mn is =
- prettyPrintImportSection (addExplicitImport' (IdeValueOperator op "" 2 P.Infix) mn is)
+ prettyPrintImportSection (addExplicitImport' (IdeValueOperator op (P.Qualified Nothing (Left (P.Ident ""))) 2 P.Infix Nothing) mn is)
addDtorImport i t mn is =
prettyPrintImportSection (addExplicitImport' (IdeDataConstructor (P.ProperName i) t wildcard) mn is)
it "adds an implicit unqualified import" $
diff --git a/tests/Language/PureScript/Ide/Integration.hs b/tests/Language/PureScript/Ide/Integration.hs
index f733959..92569d0 100644
--- a/tests/Language/PureScript/Ide/Integration.hs
+++ b/tests/Language/PureScript/Ide/Integration.hs
@@ -37,13 +37,11 @@ module Language.PureScript.Ide.Integration
, getFlexCompletions
, getFlexCompletionsInModule
, getType
- , getInfo
, rebuildModule
, reset
-- checking results
, resultIsSuccess
, parseCompletions
- , parseInfo
, parseTextResult
) where
@@ -95,7 +93,7 @@ compileTestProject = do
pdir <- projectDirectory
(_, _, _, procHandle) <- createProcess $
(shell . toS $ "psc " <> fileGlob) { cwd = Just pdir }
- r <- tryNTimes 5 (getProcessExitCode procHandle)
+ r <- tryNTimes 10 (getProcessExitCode procHandle)
pure (fromMaybe False (isSuccess <$> r))
tryNTimes :: Int -> IO (Maybe a) -> IO (Maybe a)
@@ -158,18 +156,15 @@ loadModules = sendCommand . load
loadAll :: IO Text
loadAll = sendCommand (load [])
-getFlexCompletions :: Text -> IO [(Text, Text, Text)]
+getFlexCompletions :: Text -> IO [(Text, Text, Text, Maybe P.SourceSpan)]
getFlexCompletions q = parseCompletions <$> sendCommand (completion [] (Just (flexMatcher q)) Nothing)
-getFlexCompletionsInModule :: Text -> Text -> IO [(Text, Text, Text)]
+getFlexCompletionsInModule :: Text -> Text -> IO [(Text, Text, Text, Maybe P.SourceSpan)]
getFlexCompletionsInModule q m = parseCompletions <$> sendCommand (completion [] (Just (flexMatcher q)) (Just m))
-getType :: Text -> IO [(Text, Text, Text)]
+getType :: Text -> IO [(Text, Text, Text, Maybe P.SourceSpan)]
getType q = parseCompletions <$> sendCommand (typeC q [])
-getInfo :: Text -> IO [P.SourceSpan]
-getInfo q = parseInfo <$> sendCommand (typeC q [])
-
addImport :: Text -> FilePath -> FilePath -> IO Text
addImport identifier fp outfp = sendCommand (addImportC identifier fp outfp)
@@ -254,17 +249,14 @@ withResult p v = do
Left err -> pure (Left err)
Right res -> Right <$> p res
-completionParser :: Value -> Parser [(Text, Text, Text)]
+completionParser :: Value -> Parser [(Text, Text, Text, Maybe P.SourceSpan)]
completionParser = withArray "res" $ \cs ->
mapM (withObject "completion" $ \o -> do
ident <- o .: "identifier"
module' <- o .: "module"
ty <- o .: "type"
- pure (module', ident, ty)) (V.toList cs)
-
-infoParser :: Value -> Parser [P.SourceSpan]
-infoParser = withArray "res" $ \cs ->
- mapM (withObject "info" $ \o -> o .: "definedAt") (V.toList cs)
+ ss <- o .: "definedAt"
+ pure (module', ident, ty, ss)) (V.toList cs)
valueFromText :: Text -> Value
valueFromText = fromJust . decode . toS
@@ -272,14 +264,10 @@ valueFromText = fromJust . decode . toS
resultIsSuccess :: Text -> Bool
resultIsSuccess = isRight . join . first toS . parseEither unwrapResult . valueFromText
-parseCompletions :: Text -> [(Text, Text, Text)]
+parseCompletions :: Text -> [(Text, Text, Text, Maybe P.SourceSpan)]
parseCompletions s =
fromJust $ join (rightToMaybe <$> parseMaybe (withResult completionParser) (valueFromText s))
-parseInfo :: Text -> [P.SourceSpan]
-parseInfo s =
- fromJust $ join (rightToMaybe <$> parseMaybe (withResult infoParser) (valueFromText s))
-
parseTextResult :: Text -> Text
parseTextResult s =
fromJust $ join (rightToMaybe <$> parseMaybe (withResult (withText "tr" pure)) (valueFromText s))
diff --git a/tests/Language/PureScript/Ide/MatcherSpec.hs b/tests/Language/PureScript/Ide/MatcherSpec.hs
index 04d0ae5..6a8b2df 100644
--- a/tests/Language/PureScript/Ide/MatcherSpec.hs
+++ b/tests/Language/PureScript/Ide/MatcherSpec.hs
@@ -9,20 +9,21 @@ import qualified Language.PureScript as P
import Language.PureScript.Ide.Integration
import Language.PureScript.Ide.Matcher
import Language.PureScript.Ide.Types
+import Language.PureScript.Ide.Util
import Test.Hspec
-value :: Text -> IdeDeclaration
-value s = IdeValue (P.Ident (toS s)) P.REmpty
+value :: Text -> IdeDeclarationAnn
+value s = withEmptyAnn (IdeValue (P.Ident (toS s)) P.REmpty)
-firstResult, secondResult, fiult :: Match IdeDeclaration
+firstResult, secondResult, fiult :: Match IdeDeclarationAnn
firstResult = Match (P.moduleNameFromString "Match", value "firstResult")
secondResult = Match (P.moduleNameFromString "Match", value "secondResult")
fiult = Match (P.moduleNameFromString "Match", value "fiult")
-completions :: [Match IdeDeclaration]
+completions :: [Match IdeDeclarationAnn]
completions = [firstResult, secondResult, fiult]
-runFlex :: Text -> [Match IdeDeclaration]
+runFlex :: Text -> [Match IdeDeclarationAnn]
runFlex s = runMatcher (flexMatcher s) completions
setup :: IO ()
@@ -43,5 +44,6 @@ spec = do
cs <- getFlexCompletions ""
cs `shouldBe` []
it "matches on equality" $ do
- cs <- getFlexCompletions "const"
- cs `shouldBe` [("MatcherSpec", "const", "forall a b. a -> b -> a")]
+ -- ignore any position information
+ (m, i, t, _) : _ <- getFlexCompletions "const"
+ (m, i, t) `shouldBe` ("MatcherSpec", "const", "forall a b. a -> b -> a")
diff --git a/tests/Language/PureScript/Ide/ReexportsSpec.hs b/tests/Language/PureScript/Ide/ReexportsSpec.hs
index c9a59ff..f0e03c4 100644
--- a/tests/Language/PureScript/Ide/ReexportsSpec.hs
+++ b/tests/Language/PureScript/Ide/ReexportsSpec.hs
@@ -2,7 +2,7 @@
{-# LANGUAGE NoImplicitPrelude #-}
module Language.PureScript.Ide.ReexportsSpec where
-import qualified Prelude as Prelude
+import qualified Prelude
import Protolude
import qualified Data.Map as Map
diff --git a/tests/Language/PureScript/Ide/SourceFile/IntegrationSpec.hs b/tests/Language/PureScript/Ide/SourceFile/IntegrationSpec.hs
index a16a9b5..4fd6056 100644
--- a/tests/Language/PureScript/Ide/SourceFile/IntegrationSpec.hs
+++ b/tests/Language/PureScript/Ide/SourceFile/IntegrationSpec.hs
@@ -14,23 +14,28 @@ setup :: IO ()
setup = void (Integration.reset *> Integration.loadAll)
spec :: Spec
-spec = beforeAll_ setup $ do
+spec = beforeAll_ setup $
describe "Sourcefile Integration" $ do
- it "finds a value declaration" $ do
+ it "finds a value declaration" $
testCase "sfValue" (3, 1)
- it "finds a type declaration" $ do
+ it "finds a type declaration" $
testCase "SFType" (5, 1)
- it "finds a data declaration" $ do
+ it "finds a data declaration" $
testCase "SFData" (7, 1)
- it "finds a data constructor" $ do
+ it "finds a data constructor" $
testCase "SFOne" (7, 1)
- it "finds a typeclass" $ do
+ it "finds a typeclass" $
testCase "SFClass" (9, 1)
- it "finds a typeclass member" $ do
+ it "finds a typeclass member" $
testCase "sfShow" (10, 3)
testCase :: Text -> (Int, Int) -> IO ()
testCase s (x, y) = do
- (P.SourceSpan f (P.SourcePos l c) _):_ <- Integration.getInfo s
+ P.SourceSpan f (P.SourcePos l c) _ <- getLocation s
toS f `shouldSatisfy` T.isSuffixOf "SourceFileSpec.purs"
(l, c) `shouldBe` (x, y)
+
+getLocation :: Text -> IO P.SourceSpan
+getLocation s = do
+ (_, _, _, Just location) : _ <- Integration.getType s
+ pure location
diff --git a/tests/Language/PureScript/Ide/SourceFileSpec.hs b/tests/Language/PureScript/Ide/SourceFileSpec.hs
index 26a2dba..ac53dde 100644
--- a/tests/Language/PureScript/Ide/SourceFileSpec.hs
+++ b/tests/Language/PureScript/Ide/SourceFileSpec.hs
@@ -13,11 +13,12 @@ span0 = P.SourceSpan "ModuleLevel" (P.SourcePos 0 0) (P.SourcePos 1 1)
span1 = P.SourceSpan "" (P.SourcePos 1 1) (P.SourcePos 2 2)
span2 = P.SourceSpan "" (P.SourcePos 2 2) (P.SourcePos 3 3)
-value1, synonym1, class1, class2, data1, data2, foreign1, foreign2, member1 :: P.Declaration
+typeAnnotation1, value1, synonym1, class1, class2, data1, data2, foreign1, foreign2, member1 :: P.Declaration
+typeAnnotation1 = P.TypeDeclaration (P.Ident "value1") P.REmpty
value1 = P.ValueDeclaration (P.Ident "value1") P.Public [] (Left [])
synonym1 = P.TypeSynonymDeclaration (P.ProperName "Synonym1") [] P.REmpty
-class1 = P.TypeClassDeclaration (P.ProperName "Class1") [] [] []
-class2 = P.TypeClassDeclaration (P.ProperName "Class2") [] []
+class1 = P.TypeClassDeclaration (P.ProperName "Class1") [] [] [] []
+class2 = P.TypeClassDeclaration (P.ProperName "Class2") [] [] []
[P.PositionedDeclaration span2 [] member1]
data1 = P.DataDeclaration P.Newtype (P.ProperName "Data1") [] []
data2 = P.DataDeclaration P.Data (P.ProperName "Data2") [] [(P.ProperName "Cons1", [])]
@@ -44,3 +45,6 @@ spec = do
extractSpans span0 (P.PositionedDeclaration span1 [] foreign1) `shouldBe` [(Left "foreign1", span1)]
it "extracts a span for a data foreign declaration" $
extractSpans span0 (P.PositionedDeclaration span1 [] foreign2) `shouldBe` [(Right "Foreign2", span1)]
+ describe "Type annotations" $ do
+ it "extracts a type annotation" $
+ extractTypeAnnotations [typeAnnotation1] `shouldBe` [(P.Ident "value1", P.REmpty)]
diff --git a/tests/Language/PureScript/Ide/StateSpec.hs b/tests/Language/PureScript/Ide/StateSpec.hs
new file mode 100644
index 0000000..87b50d2
--- /dev/null
+++ b/tests/Language/PureScript/Ide/StateSpec.hs
@@ -0,0 +1,51 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+module Language.PureScript.Ide.StateSpec where
+
+import Protolude
+import Language.PureScript.Ide.Types
+import Language.PureScript.Ide.State
+import qualified Language.PureScript as P
+import Test.Hspec
+import qualified Data.Map as Map
+
+valueOperator :: Maybe P.Type -> IdeDeclarationAnn
+valueOperator =
+ d . IdeValueOperator (P.OpName "<$>") (P.Qualified (Just (mn "Test")) (Left (P.Ident "function"))) 2 P.Infix
+
+ctorOperator :: Maybe P.Type -> IdeDeclarationAnn
+ctorOperator =
+ d . IdeValueOperator (P.OpName ":") (P.Qualified (Just (mn "Test")) (Right (P.ProperName "Cons"))) 2 P.Infix
+
+typeOperator :: Maybe P.Kind -> IdeDeclarationAnn
+typeOperator =
+ d . IdeTypeOperator (P.OpName ":") (P.Qualified (Just (mn "Test")) (P.ProperName "List")) 2 P.Infix
+
+testModule :: Module
+testModule = (mn "Test", [ d (IdeValue (P.Ident "function") P.REmpty)
+ , d (IdeDataConstructor (P.ProperName "Cons") (P.ProperName "List") (P.REmpty))
+ , d (IdeType (P.ProperName "List") P.Star)
+ , valueOperator Nothing
+ , ctorOperator Nothing
+ , typeOperator Nothing
+ ])
+
+d :: IdeDeclaration -> IdeDeclarationAnn
+d = IdeDeclarationAnn emptyAnn
+
+mn :: Text -> P.ModuleName
+mn = P.moduleNameFromString . toS
+
+testState :: Map P.ModuleName [IdeDeclarationAnn]
+testState = Map.fromList
+ [ testModule
+ ]
+
+spec :: Spec
+spec = describe "resolving operators" $ do
+ it "resolves the type for a value operator" $
+ resolveOperatorsForModule testState (snd testModule) `shouldSatisfy` elem (valueOperator (Just P.REmpty))
+ it "resolves the type for a constructor operator" $
+ resolveOperatorsForModule testState (snd testModule) `shouldSatisfy` elem (ctorOperator (Just P.REmpty))
+ it "resolves the kind for a type operator" $
+ resolveOperatorsForModule testState (snd testModule) `shouldSatisfy` elem (typeOperator (Just P.Star))
diff --git a/tests/TestDocs.hs b/tests/TestDocs.hs
index 6a645c1..1d56293 100644
--- a/tests/TestDocs.hs
+++ b/tests/TestDocs.hs
@@ -278,6 +278,7 @@ testCases =
[ ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "explicit" (ShowFn (hasTypeVar "something"))
, ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "anInt" (ShowFn (P.tyInt ==))
, ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "aNumber" (ShowFn (P.tyNumber ==))
+ , ValueShouldHaveTypeSignature (n "ExplicitTypeSignatures") "nestedForAll" (renderedType "forall c. (forall a b. c)")
])
, ("ConstrainedArgument",
diff --git a/tests/TestPscIde.hs b/tests/TestPscIde.hs
index d90b9d2..bf9e62c 100644
--- a/tests/TestPscIde.hs
+++ b/tests/TestPscIde.hs
@@ -11,4 +11,5 @@ main = do
s <- compileTestProject
unless s $ fail "Failed to compile .purs sources"
+ quitServer -- shuts down any left over server (primarily happens during development)
withServer (hspec PscIdeSpec.spec)
diff --git a/tests/TestPsci.hs b/tests/TestPsci.hs
index 1047607..19eb961 100644
--- a/tests/TestPsci.hs
+++ b/tests/TestPsci.hs
@@ -102,7 +102,6 @@ completionTestData =
, ("ST.new", ["ST.newSTRef"])
, ("Control.Monad.ST.new", ["Control.Monad.ST.newSTRef"])
]
- where
assertCompletedOk :: (String, [String]) -> Assertion
assertCompletedOk (line, expecteds) = do
diff --git a/tests/TestUtils.hs b/tests/TestUtils.hs
index 49e9c2a..f1a2522 100644
--- a/tests/TestUtils.hs
+++ b/tests/TestUtils.hs
@@ -75,6 +75,8 @@ supportModules =
, "Data.Function"
, "Data.Functor"
, "Data.HeytingAlgebra"
+ , "Data.NaturalTransformation"
+ , "Data.Newtype"
, "Data.Ord.Unsafe"
, "Data.Ord"
, "Data.Ordering"
diff --git a/tests/support/bower.json b/tests/support/bower.json
index ca9d449..7bbaebd 100644
--- a/tests/support/bower.json
+++ b/tests/support/bower.json
@@ -5,8 +5,9 @@
"purescript-console": "1.0.0-rc.1",
"purescript-eff": "1.0.0-rc.1",
"purescript-functions": "1.0.0-rc.1",
- "purescript-prelude": "1.0.0-rc.3",
+ "purescript-prelude": "1.1.0",
"purescript-st": "1.0.0-rc.1",
- "purescript-partial": "1.1.2"
+ "purescript-partial": "1.1.2",
+ "purescript-newtype": "0.1.0"
}
}