diff options
author | PhilFreeman <> | 2017-07-10 20:00:00 (GMT) |
---|---|---|
committer | hdiff <hdiff@hdiff.luite.com> | 2017-07-10 20:00:00 (GMT) |
commit | bc80a9937fd209e5553541b5abddf8010f1e3b31 (patch) | |
tree | d4a4950483623e8b4fbea6207ebd0615a915c3d3 /tests | |
parent | 365104aef9239bb6b25980ffbeba1a1b5682ba78 (diff) |
version 0.11.60.11.6
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Language/PureScript/Ide/CompletionSpec.hs | 2 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/FilterSpec.hs | 79 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/ImportsSpec.hs | 4 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/ReexportsSpec.hs | 23 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/SourceFileSpec.hs | 65 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/StateSpec.hs | 32 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/Test.hs | 16 | ||||
-rw-r--r-- | tests/TestDocs.hs | 14 | ||||
-rw-r--r-- | tests/support/bower.json | 3 |
9 files changed, 166 insertions, 72 deletions
diff --git a/tests/Language/PureScript/Ide/CompletionSpec.hs b/tests/Language/PureScript/Ide/CompletionSpec.hs index 623a58e..255d697 100644 --- a/tests/Language/PureScript/Ide/CompletionSpec.hs +++ b/tests/Language/PureScript/Ide/CompletionSpec.hs @@ -19,7 +19,7 @@ reexportMatches = moduleB = [ideKind "Kind" `annExp` "A"] matches :: [(Match IdeDeclarationAnn, [P.ModuleName])] -matches = map (\d -> (Match (mn "Main", d), [mn "Main"])) [ ideKind "Kind", ideType "Type" Nothing ] +matches = map (\d -> (Match (mn "Main", d), [mn "Main"])) [ ideKind "Kind", ideType "Type" Nothing [] ] spec :: Spec spec = describe "Applying completion options" $ do diff --git a/tests/Language/PureScript/Ide/FilterSpec.hs b/tests/Language/PureScript/Ide/FilterSpec.hs index 2e1c8f9..ed0e376 100644 --- a/tests/Language/PureScript/Ide/FilterSpec.hs +++ b/tests/Language/PureScript/Ide/FilterSpec.hs @@ -5,6 +5,7 @@ module Language.PureScript.Ide.FilterSpec where import Protolude import Data.List.NonEmpty import Language.PureScript.Ide.Filter +import Language.PureScript.Ide.Filter.Declaration as D import Language.PureScript.Ide.Types import Language.PureScript.Ide.Test as T import qualified Language.PureScript as P @@ -12,11 +13,16 @@ import Test.Hspec type Module = (P.ModuleName, [IdeDeclarationAnn]) -moduleA, moduleB, moduleC, moduleD :: Module +moduleA, moduleB, moduleC, moduleD, moduleE, moduleF, moduleG, moduleH, moduleI :: Module moduleA = (P.moduleNameFromString "Module.A", [T.ideValue "function1" Nothing]) moduleB = (P.moduleNameFromString "Module.B", [T.ideValue "data1" Nothing]) -moduleC = (P.moduleNameFromString "Module.C", [T.ideType "List" Nothing]) +moduleC = (P.moduleNameFromString "Module.C", [T.ideType "List" Nothing []]) moduleD = (P.moduleNameFromString "Module.D", [T.ideKind "kind1"]) +moduleE = (P.moduleNameFromString "Module.E", [T.ideSynonym "SFType" Nothing Nothing `annLoc` synonymSS]) +moduleF = (P.moduleNameFromString "Module.F", [T.ideDtor "DtorA" "TypeA" Nothing]) +moduleG = (P.moduleNameFromString "Module.G", [T.ideTypeClass "MyClass" P.kindType []]) +moduleH = (P.moduleNameFromString "Module.H", [T.ideValueOp "<$>" (P.Qualified Nothing (Left "")) 0 Nothing Nothing]) +moduleI = (P.moduleNameFromString "Module.I", [T.ideTypeOp "~>" (P.Qualified Nothing "") 0 Nothing Nothing]) modules :: [Module] modules = [moduleA, moduleB] @@ -33,6 +39,9 @@ runModule ms = applyFilters [moduleFilter ms] modules runNamespace :: NonEmpty IdeNamespace -> [Module] -> [Module] runNamespace namespaces = applyFilters [namespaceFilter namespaces] +runDeclaration :: [D.IdeDeclaration] -> [Module] -> [Module] +runDeclaration decls = applyFilters [declarationTypeFilter decls] + spec :: Spec spec = do describe "equality Filter" $ do @@ -91,3 +100,69 @@ spec = do runNamespace (fromList [ IdeNSValue, IdeNSType, IdeNSKind]) [moduleA, moduleB, moduleC, moduleD] `shouldBe` [moduleA, moduleB, moduleC, moduleD] + describe "declarationTypeFilter" $ do + let moduleADecl = D.IdeDeclaration D.Value + moduleCDecl = D.IdeDeclaration D.Type + moduleDDecl = D.IdeDeclaration D.Kind + moduleEDecl = D.IdeDeclaration D.Synonym + moduleFDecl = D.IdeDeclaration D.DataConstructor + moduleGDecl = D.IdeDeclaration D.TypeClass + moduleHDecl = D.IdeDeclaration D.ValueOperator + moduleIDecl = D.IdeDeclaration D.TypeOperator + it "keeps everything on empty list of declarations" $ + runDeclaration [] + [moduleA, moduleB, moduleD] `shouldBe` [moduleA, moduleB, moduleD] + it "extracts modules by filtering `value` declarations" $ + runDeclaration [moduleADecl] + [moduleA, moduleB, moduleD] `shouldBe` [moduleA, moduleB] + it "removes everything if no `value` declarations has been found" $ + runDeclaration [moduleADecl] + [moduleD, moduleG, moduleE, moduleH] `shouldBe` [] + it "extracts module by filtering `type` declarations" $ + runDeclaration [moduleCDecl] + [moduleA, moduleB, moduleC, moduleD, moduleE] `shouldBe` [moduleC] + it "removes everything if a `type` declaration have not been found" $ + runDeclaration [moduleCDecl] + [moduleA, moduleG, moduleE, moduleH] `shouldBe` [] + it "extracts module by filtering `synonym` declarations" $ + runDeclaration [moduleEDecl] + [moduleA, moduleB, moduleD, moduleE] `shouldBe` [moduleE] + it "removes everything if a `synonym` declaration have not been found" $ + runDeclaration [moduleEDecl] + [moduleA, moduleB, moduleC, moduleH] `shouldBe` [] + it "extracts module by filtering `constructor` declarations" $ + runDeclaration [moduleFDecl] + [moduleA, moduleB, moduleC, moduleF] `shouldBe` [moduleF] + it "removes everything if a `constructor` declaration have not been found" $ + runDeclaration [moduleFDecl] + [moduleA, moduleB, moduleC, moduleH] `shouldBe` [] + it "extracts module by filtering `typeclass` declarations" $ + runDeclaration [moduleGDecl] + [moduleA, moduleC, moduleG] `shouldBe` [moduleG] + it "removes everything if a `typeclass` declaration have not been found" $ + runDeclaration [moduleGDecl] + [moduleA, moduleB, moduleC, moduleH] `shouldBe` [] + it "extracts modules by filtering `valueoperator` declarations" $ + runDeclaration [moduleHDecl] + [moduleA, moduleC, moduleG, moduleH, moduleF] `shouldBe` [moduleH] + it "removes everything if a `valueoperator` declaration have not been found" $ + runDeclaration [moduleHDecl] + [moduleA, moduleB, moduleC, moduleD] `shouldBe` [] + it "extracts modules by filtering `typeoperator` declarations" $ + runDeclaration [moduleIDecl] + [moduleA, moduleC, moduleG, moduleI, moduleF] `shouldBe` [moduleI] + it "removes everything if a `typeoperator` declaration have not been found" $ + runDeclaration [moduleIDecl] + [moduleA, moduleD] `shouldBe` [] + it "extracts module by filtering `kind` declarations" $ + runDeclaration [moduleCDecl] + [moduleA, moduleC, moduleG, moduleI, moduleF] `shouldBe` [moduleC] + it "removes everything if a `kind` declaration have not been found" $ + runDeclaration [moduleCDecl] + [moduleA, moduleD] `shouldBe` [] + it "extracts modules by filtering `value` and `synonym` declarations" $ + runDeclaration [moduleADecl, moduleEDecl] + [moduleA, moduleB, moduleD, moduleE] `shouldBe` [moduleA, moduleB, moduleE] + it "extracts modules by filtering `kind`, `synonym` and `valueoperator` declarations" $ + runDeclaration [moduleADecl, moduleDDecl, moduleHDecl] + [moduleA, moduleB, moduleD, moduleG, moduleE, moduleH] `shouldBe` [moduleA, moduleB, moduleD, moduleH] diff --git a/tests/Language/PureScript/Ide/ImportsSpec.hs b/tests/Language/PureScript/Ide/ImportsSpec.hs index 908531b..e95309f 100644 --- a/tests/Language/PureScript/Ide/ImportsSpec.hs +++ b/tests/Language/PureScript/Ide/ImportsSpec.hs @@ -107,7 +107,7 @@ spec = do addDtorImport i t mn is = prettyPrintImportSection (addExplicitImport' (_idaDeclaration (Test.ideDtor i t Nothing)) mn is) addTypeImport i mn is = - prettyPrintImportSection (addExplicitImport' (_idaDeclaration (Test.ideType i Nothing)) mn is) + prettyPrintImportSection (addExplicitImport' (_idaDeclaration (Test.ideType i Nothing [])) mn is) addKindImport i mn is = prettyPrintImportSection (addExplicitImport' (_idaDeclaration (Test.ideKind i)) mn is) it "adds an implicit unqualified import to a file without any imports" $ @@ -208,7 +208,7 @@ spec = do moduleName = (P.moduleNameFromString "Control.Monad") addImport imports import' = addExplicitImport' import' moduleName imports valueImport ident = _idaDeclaration (Test.ideValue ident Nothing) - typeImport name = _idaDeclaration (Test.ideType name Nothing) + typeImport name = _idaDeclaration (Test.ideType name Nothing []) classImport name = _idaDeclaration (Test.ideTypeClass name P.kindType []) dtorImport name typeName = _idaDeclaration (Test.ideDtor name typeName Nothing) -- expect any list of provided identifiers, when imported, to come out as specified diff --git a/tests/Language/PureScript/Ide/ReexportsSpec.hs b/tests/Language/PureScript/Ide/ReexportsSpec.hs index 2a6952e..731672a 100644 --- a/tests/Language/PureScript/Ide/ReexportsSpec.hs +++ b/tests/Language/PureScript/Ide/ReexportsSpec.hs @@ -13,7 +13,7 @@ import Test.Hspec valueA, typeA, synonymA, classA, dtorA1, dtorA2, kindA :: IdeDeclarationAnn valueA = ideValue "valueA" Nothing -typeA = ideType "TypeA" Nothing +typeA = ideType "TypeA" Nothing [] synonymA = ideSynonym "SynonymA" Nothing Nothing classA = ideTypeClass "ClassA" P.kindType [] dtorA1 = ideDtor "DtorA1" "TypeA" Nothing @@ -27,24 +27,27 @@ env = Map.fromList type Refs = [(P.ModuleName, P.DeclarationRef)] +testSpan :: P.SourceSpan +testSpan = P.internalModuleSourceSpan "<test>" + succTestCases :: [(Text, Refs, [IdeDeclarationAnn])] succTestCases = - [ ("resolves a value reexport", [(mn "A", P.ValueRef (P.Ident "valueA"))], [valueA `annExp` "A"]) + [ ("resolves a value reexport", [(mn "A", P.ValueRef testSpan (P.Ident "valueA"))], [valueA `annExp` "A"]) , ("resolves a type reexport with explicit data constructors" - , [(mn "A", P.TypeRef (P.ProperName "TypeA") (Just [P.ProperName "DtorA1"]))], [typeA `annExp` "A", dtorA1 `annExp` "A"]) + , [(mn "A", P.TypeRef testSpan (P.ProperName "TypeA") (Just [P.ProperName "DtorA1"]))], [typeA `annExp` "A", dtorA1 `annExp` "A"]) , ("resolves a type reexport with implicit data constructors" - , [(mn "A", P.TypeRef (P.ProperName "TypeA") Nothing)], map (`annExp` "A") [typeA, dtorA1, dtorA2]) + , [(mn "A", P.TypeRef testSpan (P.ProperName "TypeA") Nothing)], map (`annExp` "A") [typeA, dtorA1, dtorA2]) , ("resolves a synonym reexport" - , [(mn "A", P.TypeRef (P.ProperName "SynonymA") Nothing)], [synonymA `annExp` "A"]) - , ("resolves a class reexport", [(mn "A", P.TypeClassRef (P.ProperName "ClassA"))], [classA `annExp` "A"]) - , ("resolves a kind reexport", [(mn "A", P.KindRef (P.ProperName "KindA"))], [kindA `annExp` "A"]) + , [(mn "A", P.TypeRef testSpan (P.ProperName "SynonymA") Nothing)], [synonymA `annExp` "A"]) + , ("resolves a class reexport", [(mn "A", P.TypeClassRef testSpan (P.ProperName "ClassA"))], [classA `annExp` "A"]) + , ("resolves a kind reexport", [(mn "A", P.KindRef testSpan (P.ProperName "KindA"))], [kindA `annExp` "A"]) ] failTestCases :: [(Text, Refs)] failTestCases = - [ ("fails to resolve a non existing value", [(mn "A", P.ValueRef (P.Ident "valueB"))]) - , ("fails to resolve a non existing type reexport" , [(mn "A", P.TypeRef (P.ProperName "TypeB") Nothing)]) - , ("fails to resolve a non existing class reexport", [(mn "A", P.TypeClassRef (P.ProperName "ClassB"))]) + [ ("fails to resolve a non existing value", [(mn "A", P.ValueRef testSpan (P.Ident "valueB"))]) + , ("fails to resolve a non existing type reexport" , [(mn "A", P.TypeRef testSpan (P.ProperName "TypeB") Nothing)]) + , ("fails to resolve a non existing class reexport", [(mn "A", P.TypeClassRef testSpan (P.ProperName "ClassB"))]) ] spec :: Spec diff --git a/tests/Language/PureScript/Ide/SourceFileSpec.hs b/tests/Language/PureScript/Ide/SourceFileSpec.hs index 7937c0f..1bf01f4 100644 --- a/tests/Language/PureScript/Ide/SourceFileSpec.hs +++ b/tests/Language/PureScript/Ide/SourceFileSpec.hs @@ -16,55 +16,61 @@ 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) +ann0, ann1, ann2 :: P.SourceAnn +ann0 = (span0, []) +ann1 = (span1, []) +ann2 = (span2, []) + typeAnnotation1, value1, synonym1, class1, class2, data1, data2, valueFixity, typeFixity, foreign1, foreign2, foreign3, member1 :: P.Declaration -typeAnnotation1 = P.TypeDeclaration (P.Ident "value1") P.REmpty -value1 = P.ValueDeclaration (P.Ident "value1") P.Public [] [] -synonym1 = P.TypeSynonymDeclaration (P.ProperName "Synonym1") [] P.REmpty -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", [])] +typeAnnotation1 = P.TypeDeclaration ann1 (P.Ident "value1") P.REmpty +value1 = P.ValueDeclaration ann1 (P.Ident "value1") P.Public [] [] +synonym1 = P.TypeSynonymDeclaration ann1 (P.ProperName "Synonym1") [] P.REmpty +class1 = P.TypeClassDeclaration ann1 (P.ProperName "Class1") [] [] [] [] +class2 = P.TypeClassDeclaration ann1 (P.ProperName "Class2") [] [] [] [member1] +data1 = P.DataDeclaration ann1 P.Newtype (P.ProperName "Data1") [] [] +data2 = P.DataDeclaration ann1 P.Data (P.ProperName "Data2") [] [(P.ProperName "Cons1", [])] valueFixity = P.ValueFixityDeclaration + ann1 (P.Fixity P.Infix 0) (P.Qualified Nothing (Left (P.Ident ""))) (P.OpName "<$>") typeFixity = P.TypeFixityDeclaration + ann1 (P.Fixity P.Infix 0) (P.Qualified Nothing (P.ProperName "")) (P.OpName "~>") -foreign1 = P.ExternDeclaration (P.Ident "foreign1") P.REmpty -foreign2 = P.ExternDataDeclaration (P.ProperName "Foreign2") P.kindType -foreign3 = P.ExternKindDeclaration (P.ProperName "Foreign3") -member1 = P.TypeDeclaration (P.Ident "member1") P.REmpty +foreign1 = P.ExternDeclaration ann1 (P.Ident "foreign1") P.REmpty +foreign2 = P.ExternDataDeclaration ann1 (P.ProperName "Foreign2") P.kindType +foreign3 = P.ExternKindDeclaration ann1 (P.ProperName "Foreign3") +member1 = P.TypeDeclaration ann2 (P.Ident "member1") P.REmpty spec :: Spec spec = do describe "Extracting Spans" $ do it "extracts a span for a value declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] value1) `shouldBe` [(IdeNamespaced IdeNSValue "value1", span1)] + extractSpans value1 `shouldBe` [(IdeNamespaced IdeNSValue "value1", span1)] it "extracts a span for a type synonym declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] synonym1) `shouldBe` [(IdeNamespaced IdeNSType "Synonym1", span1)] + extractSpans synonym1 `shouldBe` [(IdeNamespaced IdeNSType "Synonym1", span1)] it "extracts a span for a typeclass declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] class1) `shouldBe` [(IdeNamespaced IdeNSType "Class1", span1)] + extractSpans class1 `shouldBe` [(IdeNamespaced IdeNSType "Class1", span1)] it "extracts spans for a typeclass declaration and its members" $ - extractSpans span0 (P.PositionedDeclaration span1 [] class2) `shouldBe` [(IdeNamespaced IdeNSType "Class2", span1), (IdeNamespaced IdeNSValue "member1", span2)] + extractSpans class2 `shouldBe` [(IdeNamespaced IdeNSType "Class2", span1), (IdeNamespaced IdeNSValue "member1", span2)] it "extracts a span for a data declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] data1) `shouldBe` [(IdeNamespaced IdeNSType "Data1", span1)] + extractSpans data1 `shouldBe` [(IdeNamespaced IdeNSType "Data1", span1)] it "extracts spans for a data declaration and its constructors" $ - extractSpans span0 (P.PositionedDeclaration span1 [] data2) `shouldBe` [(IdeNamespaced IdeNSType "Data2", span1), (IdeNamespaced IdeNSValue "Cons1", span1)] + extractSpans data2 `shouldBe` [(IdeNamespaced IdeNSType "Data2", span1), (IdeNamespaced IdeNSValue "Cons1", span1)] it "extracts a span for a value operator fixity declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] valueFixity) `shouldBe` [(IdeNamespaced IdeNSValue "<$>", span1)] + extractSpans valueFixity `shouldBe` [(IdeNamespaced IdeNSValue "<$>", span1)] it "extracts a span for a type operator fixity declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] typeFixity) `shouldBe` [(IdeNamespaced IdeNSType "~>", span1)] + extractSpans typeFixity `shouldBe` [(IdeNamespaced IdeNSType "~>", span1)] it "extracts a span for a foreign declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] foreign1) `shouldBe` [(IdeNamespaced IdeNSValue "foreign1", span1)] + extractSpans foreign1 `shouldBe` [(IdeNamespaced IdeNSValue "foreign1", span1)] it "extracts a span for a data foreign declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] foreign2) `shouldBe` [(IdeNamespaced IdeNSType "Foreign2", span1)] + extractSpans foreign2 `shouldBe` [(IdeNamespaced IdeNSType "Foreign2", span1)] it "extracts a span for a foreign kind declaration" $ - extractSpans span0 (P.PositionedDeclaration span1 [] foreign3) `shouldBe` [(IdeNamespaced IdeNSKind "Foreign3", span1)] + extractSpans foreign3 `shouldBe` [(IdeNamespaced IdeNSKind "Foreign3", span1)] describe "Type annotations" $ do it "extracts a type annotation" $ extractTypeAnnotations [typeAnnotation1] `shouldBe` [(P.Ident "value1", P.REmpty)] @@ -98,7 +104,7 @@ getLocation s = do [ ("Test", [ ideValue "sfValue" Nothing `annLoc` valueSS , ideSynonym "SFType" Nothing Nothing `annLoc` synonymSS - , ideType "SFData" Nothing `annLoc` typeSS + , ideType "SFData" Nothing [] `annLoc` typeSS , ideDtor "SFOne" "SFData" Nothing `annLoc` typeSS , ideDtor "SFTwo" "SFData" Nothing `annLoc` typeSS , ideDtor "SFThree" "SFData" Nothing `annLoc` typeSS @@ -109,14 +115,3 @@ getLocation s = do `annLoc` typeOpSS ]) ] - -valueSS, synonymSS, typeSS, classSS, valueOpSS, typeOpSS :: P.SourceSpan -valueSS = ss 3 1 -synonymSS = ss 5 1 -typeSS = ss 7 1 -classSS = ss 8 1 -valueOpSS = ss 12 1 -typeOpSS = ss 13 1 - -ss :: Int -> Int -> P.SourceSpan -ss x y = P.SourceSpan "Test.purs" (P.SourcePos x y) (P.SourcePos x y) diff --git a/tests/Language/PureScript/Ide/StateSpec.hs b/tests/Language/PureScript/Ide/StateSpec.hs index 78f8cea..0a31331 100644 --- a/tests/Language/PureScript/Ide/StateSpec.hs +++ b/tests/Language/PureScript/Ide/StateSpec.hs @@ -13,27 +13,26 @@ import qualified Data.Map as Map valueOperator :: Maybe P.Type -> IdeDeclarationAnn valueOperator = - d . IdeDeclValueOperator . IdeValueOperator (P.OpName "<$>") (P.Qualified (Just (mn "Test")) (Left (P.Ident "function"))) 2 P.Infix + ideValueOp "<$>" (P.Qualified (Just (mn "Test")) (Left "function")) 2 Nothing ctorOperator :: Maybe P.Type -> IdeDeclarationAnn ctorOperator = - d . IdeDeclValueOperator . IdeValueOperator (P.OpName ":") (P.Qualified (Just (mn "Test")) (Right (P.ProperName "Cons"))) 2 P.Infix + ideValueOp ":" (P.Qualified (Just (mn "Test")) (Right "Cons")) 2 Nothing typeOperator :: Maybe P.Kind -> IdeDeclarationAnn typeOperator = - d . IdeDeclTypeOperator . IdeTypeOperator (P.OpName ":") (P.Qualified (Just (mn "Test")) (P.ProperName "List")) 2 P.Infix + ideTypeOp ":" (P.Qualified (Just (mn "Test")) "List") 2 Nothing testModule :: (P.ModuleName, [IdeDeclarationAnn]) -testModule = (mn "Test", [ d (IdeDeclValue (IdeValue (P.Ident "function") P.REmpty)) - , d (IdeDeclDataConstructor (IdeDataConstructor (P.ProperName "Cons") (P.ProperName "List") (P.REmpty))) - , d (IdeDeclType (IdeType (P.ProperName "List") P.kindType)) - , valueOperator Nothing - , ctorOperator Nothing - , typeOperator Nothing - ]) - -d :: IdeDeclaration -> IdeDeclarationAnn -d = IdeDeclarationAnn emptyAnn +testModule = + (mn "Test", + [ ideValue "function" (Just P.REmpty) + , ideDtor "Cons" "List" (Just P.tyString) + , ideType "List" Nothing [] + , valueOperator Nothing + , ctorOperator Nothing + , typeOperator Nothing + ]) testState :: ModuleMap [IdeDeclarationAnn] testState = Map.fromList [testModule] @@ -81,7 +80,7 @@ spec = 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)) + resolveOperatorsForModule testState (snd testModule) `shouldSatisfy` elem (ctorOperator (Just P.tyString)) it "resolves the kind for a type operator" $ resolveOperatorsForModule testState (snd testModule) `shouldSatisfy` elem (typeOperator (Just P.kindType)) describe "resolving instances for type classes" $ do @@ -89,3 +88,8 @@ spec = do resolveInstances (Map.singleton (mn "InstanceModule") ef) moduleMap `shouldSatisfy` elemOf (ix (mn "ClassModule") . ix 0 . idaDeclaration . _IdeDeclTypeClass . ideTCInstances . folded) ideInstance + describe "resolving data constructors" $ do + it "resolves a constructor" $ do + resolveDataConstructorsForModule (snd testModule) + `shouldSatisfy` + elem (ideType "List" Nothing [(P.ProperName "Cons", P.tyString)]) diff --git a/tests/Language/PureScript/Ide/Test.hs b/tests/Language/PureScript/Ide/Test.hs index 8cb8d3e..dd48b8f 100644 --- a/tests/Language/PureScript/Ide/Test.hs +++ b/tests/Language/PureScript/Ide/Test.hs @@ -1,6 +1,7 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PackageImports #-} +{-# LANGUAGE DataKinds #-} module Language.PureScript.Ide.Test where import Control.Concurrent.STM @@ -63,8 +64,8 @@ ida = IdeDeclarationAnn emptyAnn ideValue :: Text -> Maybe P.Type -> IdeDeclarationAnn ideValue i ty = ida (IdeDeclValue (IdeValue (P.Ident i) (fromMaybe P.tyString ty))) -ideType :: Text -> Maybe P.Kind -> IdeDeclarationAnn -ideType pn ki = ida (IdeDeclType (IdeType (P.ProperName pn) (fromMaybe P.kindType ki))) +ideType :: Text -> Maybe P.Kind -> [(P.ProperName 'P.ConstructorName, P.Type)] -> IdeDeclarationAnn +ideType pn ki dtors = ida (IdeDeclType (IdeType (P.ProperName pn) (fromMaybe P.kindType ki) dtors)) ideSynonym :: Text -> Maybe P.Type -> Maybe P.Kind -> IdeDeclarationAnn ideSynonym pn ty kind = ida (IdeDeclTypeSynonym (IdeTypeSynonym (P.ProperName pn) (fromMaybe P.tyString ty) (fromMaybe P.kindType kind))) @@ -98,6 +99,17 @@ ideTypeOp opName ident precedence assoc k = ideKind :: Text -> IdeDeclarationAnn ideKind pn = ida (IdeDeclKind (P.ProperName pn)) +valueSS, synonymSS, typeSS, classSS, valueOpSS, typeOpSS :: P.SourceSpan +valueSS = ss 3 1 +synonymSS = ss 5 1 +typeSS = ss 7 1 +classSS = ss 8 1 +valueOpSS = ss 12 1 +typeOpSS = ss 13 1 + +ss :: Int -> Int -> P.SourceSpan +ss x y = P.SourceSpan "Test.purs" (P.SourcePos x y) (P.SourcePos x y) + mn :: Text -> P.ModuleName mn = P.moduleNameFromString diff --git a/tests/TestDocs.hs b/tests/TestDocs.hs index 0237bfe..d3dbbdb 100644 --- a/tests/TestDocs.hs +++ b/tests/TestDocs.hs @@ -13,7 +13,6 @@ import Control.Arrow (first) import Control.Monad.IO.Class (liftIO) import Data.Foldable -import Data.List ((\\)) import Data.Maybe (fromMaybe) import Data.Monoid import Data.Text (Text) @@ -99,7 +98,7 @@ instance Show (ShowFn a) where data AssertionFailure -- | A declaration was not documented, but should have been = NotDocumented P.ModuleName Text - -- | A child declaration was not documented, but should have been + -- | The expected list of child declarations did not match the actual list | ChildrenNotDocumented P.ModuleName Text [Text] -- | A declaration was documented, but should not have been | Documented P.ModuleName Text @@ -152,9 +151,9 @@ runAssertion assertion linksCtx Docs.Module{..} = Nothing -> Fail (NotDocumented mn decl) Just actualChildren -> - case children \\ actualChildren of - [] -> Pass - cs -> Fail (ChildrenNotDocumented mn decl cs) + if children == actualChildren + then Pass + else Fail (ChildrenNotDocumented mn decl actualChildren) ShouldNotBeDocumented mn decl -> case findChildren decl (declarationsFor mn) of @@ -406,6 +405,11 @@ testCases = , ("Desugar", [ ValueShouldHaveTypeSignature (n "Desugar") "test" (renderedType "forall a b. X (a -> b) a -> b") ]) + + , ("ChildDeclOrder", + [ ShouldBeDocumented (n "ChildDeclOrder") "Two" ["First", "Second", "showTwo", "fooTwo"] + , ShouldBeDocumented (n "ChildDeclOrder") "Foo" ["foo1", "foo2", "fooTwo", "fooInt"] + ]) ] where diff --git a/tests/support/bower.json b/tests/support/bower.json index 6b67afd..932650f 100644 --- a/tests/support/bower.json +++ b/tests/support/bower.json @@ -8,13 +8,14 @@ "purescript-functions": "3.0.0", "purescript-generics": "4.0.0", "purescript-generics-rep": "5.0.0", + "purescript-lists": "4.6.0", "purescript-newtype": "2.0.0", "purescript-partial": "1.2.0", "purescript-prelude": "3.0.0", "purescript-psci-support": "3.0.0", "purescript-st": "3.0.0", "purescript-symbols": "3.0.0", - "purescript-tailrec": "3.0.0", + "purescript-tailrec": "3.3.0", "purescript-typelevel-prelude": "2.0.0", "purescript-unsafe-coerce": "3.0.0" } |