diff options
author | PhilFreeman <> | 2016-11-08 18:03:00 (GMT) |
---|---|---|
committer | hdiff <hdiff@hdiff.luite.com> | 2016-11-08 18:03:00 (GMT) |
commit | ab4b395c66e5fb609628ec32fc9142fafc083207 (patch) | |
tree | 432c87153702073fdac385e799131906faabc4b0 /tests | |
parent | e5b503a26b0ba5a50755c25430e73c644877fdbe (diff) |
version 0.10.20.10.2
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Language/PureScript/Ide/FilterSpec.hs | 2 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/Imports/IntegrationSpec.hs | 8 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/ImportsSpec.hs | 55 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/MatcherSpec.hs | 2 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/ReexportsSpec.hs | 10 | ||||
-rw-r--r-- | tests/Language/PureScript/Ide/StateSpec.hs | 12 | ||||
-rw-r--r-- | tests/TestCompiler.hs | 5 | ||||
-rw-r--r-- | tests/TestUtils.hs | 32 | ||||
-rw-r--r-- | tests/support/bower.json | 3 |
9 files changed, 98 insertions, 31 deletions
diff --git a/tests/Language/PureScript/Ide/FilterSpec.hs b/tests/Language/PureScript/Ide/FilterSpec.hs index cc705f8..3b4cfc2 100644 --- a/tests/Language/PureScript/Ide/FilterSpec.hs +++ b/tests/Language/PureScript/Ide/FilterSpec.hs @@ -9,7 +9,7 @@ import qualified Language.PureScript as P import Test.Hspec value :: Text -> IdeDeclarationAnn -value s = IdeDeclarationAnn emptyAnn (IdeValue (P.Ident (toS s)) P.REmpty) +value s = IdeDeclarationAnn emptyAnn (IdeDeclValue (IdeValue (P.Ident (toS s)) P.REmpty)) moduleA, moduleB :: Module moduleA = (P.moduleNameFromString "Module.A", [value "function1"]) diff --git a/tests/Language/PureScript/Ide/Imports/IntegrationSpec.hs b/tests/Language/PureScript/Ide/Imports/IntegrationSpec.hs index 1d7abbb..61021cc 100644 --- a/tests/Language/PureScript/Ide/Imports/IntegrationSpec.hs +++ b/tests/Language/PureScript/Ide/Imports/IntegrationSpec.hs @@ -6,12 +6,12 @@ module Language.PureScript.Ide.Imports.IntegrationSpec where import Protolude import qualified Data.Text as T -import qualified Data.Text.IO as TIO import qualified Language.PureScript.Ide.Integration as Integration import Test.Hspec import System.Directory import System.FilePath +import System.IO.UTF8 (readUTF8FileT) setup :: IO () setup = void (Integration.reset *> Integration.loadAll) @@ -27,7 +27,7 @@ withSupportFiles test = do outputFileShouldBe :: [Text] -> IO () outputFileShouldBe expectation = do outFp <- (</> "src" </> "ImportsSpecOut.tmp") <$> Integration.projectDirectory - outRes <- TIO.readFile outFp + outRes <- readUTF8FileT outFp shouldBe (T.lines outRes) expectation spec :: Spec @@ -57,10 +57,10 @@ spec = beforeAll_ setup . describe "Adding imports" $ do outputFileShouldBe (sourceFileSkeleton ["import ImportsSpec1 (class ATypeClass)"]) it "adds an explicit unqualified import (dataconstructor)" $ do withSupportFiles (Integration.addImport "MyJust") - outputFileShouldBe (sourceFileSkeleton ["import ImportsSpec1 (MyMaybe(MyJust))"]) + outputFileShouldBe (sourceFileSkeleton ["import ImportsSpec1 (MyMaybe(..))"]) it "adds an explicit unqualified import (newtype)" $ do withSupportFiles (Integration.addImport "MyNewtype") - outputFileShouldBe (sourceFileSkeleton ["import ImportsSpec1 (MyNewtype(MyNewtype))"]) + outputFileShouldBe (sourceFileSkeleton ["import ImportsSpec1 (MyNewtype(..))"]) it "adds an explicit unqualified import (typeclass member function)" $ do withSupportFiles (Integration.addImport "typeClassFun") outputFileShouldBe (sourceFileSkeleton ["import ImportsSpec1 (typeClassFun)"]) diff --git a/tests/Language/PureScript/Ide/ImportsSpec.hs b/tests/Language/PureScript/Ide/ImportsSpec.hs index 7cea546..bba7441 100644 --- a/tests/Language/PureScript/Ide/ImportsSpec.hs +++ b/tests/Language/PureScript/Ide/ImportsSpec.hs @@ -68,11 +68,13 @@ spec = do describe "import commands" $ do let simpleFileImports = let (_, _, i, _) = splitSimpleFile in i addValueImport i mn is = - prettyPrintImportSection (addExplicitImport' (IdeValue (P.Ident i) wildcard) mn is) + prettyPrintImportSection (addExplicitImport' (IdeDeclValue (IdeValue (P.Ident i) wildcard)) mn is) addOpImport op mn is = - prettyPrintImportSection (addExplicitImport' (IdeValueOperator op (P.Qualified Nothing (Left (P.Ident ""))) 2 P.Infix Nothing) mn is) + prettyPrintImportSection (addExplicitImport' (IdeDeclValueOperator (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) + prettyPrintImportSection (addExplicitImport' (IdeDeclDataConstructor (IdeDataConstructor (P.ProperName i) t wildcard)) mn is) + addTypeImport i mn is = + prettyPrintImportSection (addExplicitImport' (IdeDeclType (IdeType (P.ProperName i) P.Star)) mn is) it "adds an implicit unqualified import" $ shouldBe (addImplicitImport' simpleFileImports (P.moduleNameFromString "Data.Map")) @@ -100,20 +102,26 @@ spec = do shouldBe (addOpImport (P.OpName "<~>") (P.moduleNameFromString "Data.Array") explicitImports) [ "import Prelude" - , "import Data.Array ((<~>), tail)" + , "import Data.Array (tail, (<~>))" ] + it "adds a type with constructors without automatically adding an open import of said constructors " $ + shouldBe + (addTypeImport "Maybe" (P.moduleNameFromString "Data.Maybe") simpleFileImports) + [ "import Prelude" + , "import Data.Maybe (Maybe)" + ] it "adds the type for a given DataConstructor" $ shouldBe (addDtorImport "Just" (P.ProperName "Maybe") (P.moduleNameFromString "Data.Maybe") simpleFileImports) [ "import Prelude" - , "import Data.Maybe (Maybe(Just))" + , "import Data.Maybe (Maybe(..))" ] it "adds a dataconstructor to an existing type import" $ do let Right (_, _, typeImports, _) = sliceImportSection (withImports ["import Data.Maybe (Maybe)"]) shouldBe (addDtorImport "Just" (P.ProperName "Maybe") (P.moduleNameFromString "Data.Maybe") typeImports) [ "import Prelude" - , "import Data.Maybe (Maybe(Just))" + , "import Data.Maybe (Maybe(..))" ] it "doesn't add a dataconstructor to an existing type import with open dtors" $ do let Right (_, _, typeImports, _) = sliceImportSection (withImports ["import Data.Maybe (Maybe(..))"]) @@ -128,3 +136,38 @@ spec = do [ "import Prelude" , "import Data.Array (tail)" ] + + describe "explicit import sorting" $ do + -- given some basic import skeleton + let Right (_, _, baseImports, _) = sliceImportSection $ withImports ["import Control.Monad (ap)"] + moduleName = (P.moduleNameFromString "Control.Monad") + addImport imports import' = addExplicitImport' import' moduleName imports + valueImport ident = (IdeDeclValue (IdeValue (P.Ident ident) wildcard)) + typeImport name = (IdeDeclType (IdeType (P.ProperName name) P.Star)) + classImport name = (IdeDeclTypeClass (P.ProperName name)) + dtorImport name typeName = (IdeDeclDataConstructor (IdeDataConstructor (P.ProperName name) (P.ProperName typeName) wildcard)) + -- expect any list of provided identifiers, when imported, to come out as specified + expectSorted imports expected = shouldBe + (ordNub $ map + (prettyPrintImportSection . foldl addImport baseImports) + (permutations imports)) + [expected] + it "sorts class" $ + expectSorted (map classImport ["Applicative", "Bind"]) + ["import Prelude", "import Control.Monad (class Applicative, class Bind, ap)"] + it "sorts value" $ + expectSorted (map valueImport ["unless", "where"]) + ["import Prelude", "import Control.Monad (ap, unless, where)"] + it "sorts type, value" $ + expectSorted + ((map valueImport ["unless", "where"]) ++ (map typeImport ["Foo", "Bar"])) + ["import Prelude", "import Control.Monad (Bar, Foo, ap, unless, where)"] + it "sorts class, type, value" $ + expectSorted + ((map valueImport ["unless", "where"]) ++ (map typeImport ["Foo", "Bar"]) ++ (map classImport ["Applicative", "Bind"])) + ["import Prelude", "import Control.Monad (class Applicative, class Bind, Bar, Foo, ap, unless, where)"] + it "sorts types with constructors, using open imports for the constructors" $ + expectSorted + -- the imported names don't actually have to exist! + (map (uncurry dtorImport) [("Just", "Maybe"), ("Nothing", "Maybe"), ("SomeOtherConstructor", "SomeDataType")]) + ["import Prelude", "import Control.Monad (Maybe(..), SomeDataType(..), ap)"] diff --git a/tests/Language/PureScript/Ide/MatcherSpec.hs b/tests/Language/PureScript/Ide/MatcherSpec.hs index 6a8b2df..f7a7f45 100644 --- a/tests/Language/PureScript/Ide/MatcherSpec.hs +++ b/tests/Language/PureScript/Ide/MatcherSpec.hs @@ -13,7 +13,7 @@ import Language.PureScript.Ide.Util import Test.Hspec value :: Text -> IdeDeclarationAnn -value s = withEmptyAnn (IdeValue (P.Ident (toS s)) P.REmpty) +value s = withEmptyAnn (IdeDeclValue (IdeValue (P.Ident (toS s)) P.REmpty)) firstResult, secondResult, fiult :: Match IdeDeclarationAnn firstResult = Match (P.moduleNameFromString "Match", value "firstResult") diff --git a/tests/Language/PureScript/Ide/ReexportsSpec.hs b/tests/Language/PureScript/Ide/ReexportsSpec.hs index f0e03c4..f273938 100644 --- a/tests/Language/PureScript/Ide/ReexportsSpec.hs +++ b/tests/Language/PureScript/Ide/ReexportsSpec.hs @@ -18,11 +18,11 @@ d :: IdeDeclaration -> IdeDeclarationAnn d = IdeDeclarationAnn emptyAnn valueA, typeA, classA, dtorA1, dtorA2 :: IdeDeclarationAnn -valueA = d (IdeValue (P.Ident "valueA") P.REmpty) -typeA = d (IdeType (P.ProperName "TypeA") P.Star) -classA = d (IdeTypeClass (P.ProperName "ClassA")) -dtorA1 = d (IdeDataConstructor (P.ProperName "DtorA1") (P.ProperName "TypeA") P.REmpty) -dtorA2 = d (IdeDataConstructor (P.ProperName "DtorA2") (P.ProperName "TypeA") P.REmpty) +valueA = d (IdeDeclValue (IdeValue (P.Ident "valueA") P.REmpty)) +typeA = d (IdeDeclType (IdeType(P.ProperName "TypeA") P.Star)) +classA = d (IdeDeclTypeClass (P.ProperName "ClassA")) +dtorA1 = d (IdeDeclDataConstructor (IdeDataConstructor (P.ProperName "DtorA1") (P.ProperName "TypeA") P.REmpty)) +dtorA2 = d (IdeDeclDataConstructor (IdeDataConstructor (P.ProperName "DtorA2") (P.ProperName "TypeA") P.REmpty)) env :: Map P.ModuleName [IdeDeclarationAnn] env = Map.fromList diff --git a/tests/Language/PureScript/Ide/StateSpec.hs b/tests/Language/PureScript/Ide/StateSpec.hs index 87b50d2..2779662 100644 --- a/tests/Language/PureScript/Ide/StateSpec.hs +++ b/tests/Language/PureScript/Ide/StateSpec.hs @@ -11,20 +11,20 @@ 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 + d . IdeDeclValueOperator . 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 + d . IdeDeclValueOperator . 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 + d . IdeDeclTypeOperator . 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) +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.Star)) , valueOperator Nothing , ctorOperator Nothing , typeOperator Nothing diff --git a/tests/TestCompiler.hs b/tests/TestCompiler.hs index 019b428..a11babe 100644 --- a/tests/TestCompiler.hs +++ b/tests/TestCompiler.hs @@ -31,6 +31,7 @@ import Data.List (sort, stripPrefix, intercalate, groupBy, sortBy, minimumBy) import Data.Maybe (mapMaybe) import Data.Time.Clock (UTCTime()) import Data.Tuple (swap) +import qualified Data.Text as T import qualified Data.Map as M @@ -71,7 +72,7 @@ spec = do supportPurs <- supportFiles "purs" supportPursFiles <- readInput supportPurs supportExterns <- runExceptT $ do - modules <- ExceptT . return $ P.parseModulesFromFiles id supportPursFiles + modules <- ExceptT . return $ P.parseModulesFromFiles id (map (fmap T.pack) supportPursFiles) foreigns <- inferForeignModules modules externs <- ExceptT . fmap fst . runTest $ P.make (makeActions foreigns) (map snd modules) return (zip (map snd modules) externs) @@ -194,7 +195,7 @@ compile -> IO (Either P.MultipleErrors [P.ExternsFile], P.MultipleErrors) compile supportExterns inputFiles check = silence $ runTest $ do fs <- liftIO $ readInput inputFiles - ms <- P.parseModulesFromFiles id fs + ms <- P.parseModulesFromFiles id (map (fmap T.pack) fs) foreigns <- inferForeignModules ms liftIO (check (map snd ms)) let actions = makeActions foreigns diff --git a/tests/TestUtils.hs b/tests/TestUtils.hs index f1a2522..6c8e099 100644 --- a/tests/TestUtils.hs +++ b/tests/TestUtils.hs @@ -53,16 +53,24 @@ updateSupportCode = do -- supportModules :: [String] supportModules = - [ "Control.Applicative" + [ "Control.Alt" + , "Control.Alternative" + , "Control.Applicative" , "Control.Apply" , "Control.Bind" , "Control.Category" + , "Control.Comonad" + , "Control.Extend" + , "Control.Lazy" + , "Control.Monad" + , "Control.Monad.Eff" , "Control.Monad.Eff.Class" , "Control.Monad.Eff.Console" , "Control.Monad.Eff.Unsafe" - , "Control.Monad.Eff" , "Control.Monad.ST" - , "Control.Monad" + , "Control.MonadPlus" + , "Control.MonadZero" + , "Control.Plus" , "Control.Semigroupoid" , "Data.Boolean" , "Data.BooleanAlgebra" @@ -71,14 +79,27 @@ supportModules = , "Data.Eq" , "Data.EuclideanRing" , "Data.Field" - , "Data.Function.Uncurried" , "Data.Function" + , "Data.Function.Uncurried" , "Data.Functor" + , "Data.Functor.Invariant" + , "Data.Generic.Rep" + , "Data.Generic.Rep.Monoid" + , "Data.Generic.Rep.Eq" + , "Data.Generic.Rep.Ord" + , "Data.Generic.Rep.Semigroup" , "Data.HeytingAlgebra" + , "Data.Monoid" + , "Data.Monoid.Additive" + , "Data.Monoid.Conj" + , "Data.Monoid.Disj" + , "Data.Monoid.Dual" + , "Data.Monoid.Endo" + , "Data.Monoid.Multiplicative" , "Data.NaturalTransformation" , "Data.Newtype" - , "Data.Ord.Unsafe" , "Data.Ord" + , "Data.Ord.Unsafe" , "Data.Ordering" , "Data.Ring" , "Data.Semigroup" @@ -90,6 +111,7 @@ supportModules = , "Partial.Unsafe" , "Prelude" , "Test.Assert" + , "Test.Main" ] pushd :: forall a. FilePath -> IO a -> IO a diff --git a/tests/support/bower.json b/tests/support/bower.json index 7bbaebd..d2f01dd 100644 --- a/tests/support/bower.json +++ b/tests/support/bower.json @@ -8,6 +8,7 @@ "purescript-prelude": "1.1.0", "purescript-st": "1.0.0-rc.1", "purescript-partial": "1.1.2", - "purescript-newtype": "0.1.0" + "purescript-newtype": "0.1.0", + "purescript-generics-rep": "2.0.0" } } |