From 13f5d27afcfbe205e9bd453bdf6300882558c877 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Fri, 15 Nov 2013 23:34:15 +0100 Subject: [PATCH] First commit with simple colors activated --- .gitignore | 6 +++ LICENSE | 21 ++++++++++ Setup.hs | 2 + holy-project.cabal | 70 ++++++++++++++++++++++++++++++++ src/HolyProject.hs | 3 ++ src/HolyProject/Coconut.hs | 8 ++++ src/HolyProject/Swallow.hs | 4 ++ src/Main.hs | 31 ++++++++++++++ test/HolyProject/Coconut/Test.hs | 31 ++++++++++++++ test/HolyProject/Swallow/Test.hs | 13 ++++++ test/Test.hs | 15 +++++++ 11 files changed, 204 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Setup.hs create mode 100644 holy-project.cabal create mode 100644 src/HolyProject.hs create mode 100644 src/HolyProject/Coconut.hs create mode 100644 src/HolyProject/Swallow.hs create mode 100644 src/Main.hs create mode 100644 test/HolyProject/Coconut/Test.hs create mode 100644 test/HolyProject/Swallow/Test.hs create mode 100644 test/Test.hs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a124cb --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.cabal-sandbox +cabal.sandbox.config +dist +*.swp +*~ +.ghci diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9478de8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013 Yann Esposito (Yogsototh) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Setup.hs b/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/holy-project.cabal b/holy-project.cabal new file mode 100644 index 0000000..7573b2f --- /dev/null +++ b/holy-project.cabal @@ -0,0 +1,70 @@ +-- Initial holy-project.cabal generated by cabal init. For further documentation, +-- see http://haskell.org/cabal/users-guide/ + +name: holy-project +version: 0.1.0.0 +synopsis: Start your Haskell project with cabal, git and tests. +-- description: +homepage: http://github.com/yogsototh/holy-project +license: MIT +license-file: LICENSE +author: Yann Esposito (Yogsototh) +maintainer: Yann.Esposito@gmail.com +-- copyright: +category: Unknown +build-type: Simple +-- extra-source-files: +cabal-version: >=1.10 + +executable holy-project + main-is: Main.hs + -- other-modules: + -- other-extensions: + build-depends: base >=4.6 && <4.7 + , ansi-terminal + -- from Tasty cabal with ansi-terminal + cpp-options: -DCOLORS + hs-source-dirs: src + ghc-options: -Wall + default-language: Haskell2010 + +library + exposed-modules: HolyProject + , HolyProject.Swallow + , HolyProject.Coconut + -- other-modules: + -- other-extensions: + build-depends: base >=4.6 && <4.7 + ghc-options: -Wall + hs-source-dirs: src + default-language: Haskell2010 + +executable test-holy-project + hs-source-dirs: test + ghc-options: -Wall + main-is: Test.hs + default-language: Haskell2010 + build-depends: base ==4.6.*, Cabal >= 1.16.0 + , holy-project + , HUnit + , QuickCheck + , smallcheck + , tasty + , tasty-hunit + , tasty-quickcheck + , tasty-smallcheck +test-suite Tests + hs-source-dirs: test + ghc-options: -Wall + main-is: Test.hs + Type: exitcode-stdio-1.0 + default-language: Haskell2010 + build-depends: base ==4.6.*, Cabal >= 1.16.0 + , holy-project + , HUnit + , QuickCheck + , smallcheck + , tasty + , tasty-hunit + , tasty-quickcheck + , tasty-smallcheck diff --git a/src/HolyProject.hs b/src/HolyProject.hs new file mode 100644 index 0000000..ba3637d --- /dev/null +++ b/src/HolyProject.hs @@ -0,0 +1,3 @@ +module HolyProject where +import HolyProject.Swallow () +import HolyProject.Coconut () diff --git a/src/HolyProject/Coconut.hs b/src/HolyProject/Coconut.hs new file mode 100644 index 0000000..53454e4 --- /dev/null +++ b/src/HolyProject/Coconut.hs @@ -0,0 +1,8 @@ +module HolyProject.Coconut (coconut,coconutfunc,CoconutDataStruct(..)) where +data CoconutDataStruct = CoconutConstr [Integer] deriving (Show) + +coconut :: Integer +coconut = 10 + +coconutfunc :: CoconutDataStruct -> Int +coconutfunc (CoconutConstr l) = length l diff --git a/src/HolyProject/Swallow.hs b/src/HolyProject/Swallow.hs new file mode 100644 index 0000000..ec5b702 --- /dev/null +++ b/src/HolyProject/Swallow.hs @@ -0,0 +1,4 @@ +module HolyProject.Swallow (swallow) where + +swallow :: String -> String -> String +swallow prefix suffix = prefix ++ suffix diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..2a385ec --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,31 @@ +module Main where + +import System.Console.ANSI + +output :: ConsoleIntensity -> ColorIntensity -> Color -> String -> IO () +output bold intensity color str = do + setSGR [ SetColor Foreground intensity color + , SetConsoleIntensity bold + ] + putStr str + setSGR [] + + +bk :: String -> IO () +bk str = output NormalIntensity Dull Green ("Bridgekeeper: " ++ str ++ "\n") +bkn :: String -> IO () +bkn str = output NormalIntensity Dull Green ("Bridgekeeper: " ++ str) +you :: String -> IO () +you str = output NormalIntensity Dull Yellow ("Bridgekeeper: " ++ str ++ "\n") + +intro :: IO () +intro = do + bk "Stop!" + bk "Who would cross the Bridge of Death" + bk "must answer me these questions three," + bk "ere the other side he see." + you "Ask me the questions, bridgekeeper, I am not afraid.\n" + +main :: IO () +main = do + intro diff --git a/test/HolyProject/Coconut/Test.hs b/test/HolyProject/Coconut/Test.hs new file mode 100644 index 0000000..7f3d519 --- /dev/null +++ b/test/HolyProject/Coconut/Test.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} +module HolyProject.Coconut.Test + (coconutSuite) +where + +import Test.Tasty (testGroup, TestTree) +import Test.Tasty.HUnit +import Test.Tasty.SmallCheck as SC + +import HolyProject.Coconut + +-- Make instance of CoconutDataStruct +-- we simply use consN Constr where N is the arity of Constr (SmallCheck) +-- we also needed the +-- {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-} +import Test.SmallCheck.Series +instance Monad m => Serial m CoconutDataStruct where series = cons1 CoconutConstr +-- Now we could test properties with smallcheck on CoconutDataStruct type. + +coconutSuite :: TestTree +coconutSuite = testGroup "coconut" + [ testCase "coconut" testCoconut + , SC.testProperty "coconut property" prop_coconut + ] + +testCoconut :: Assertion +testCoconut = coconut @=? 10 + +prop_coconut :: Property IO +prop_coconut = forAll $ \coconutStruct -> coconutfunc coconutStruct >= 0 diff --git a/test/HolyProject/Swallow/Test.hs b/test/HolyProject/Swallow/Test.hs new file mode 100644 index 0000000..1329c2e --- /dev/null +++ b/test/HolyProject/Swallow/Test.hs @@ -0,0 +1,13 @@ +module HolyProject.Swallow.Test + (swallowSuite) +where +import Test.Tasty (testGroup, TestTree) +import Test.Tasty.HUnit +import HolyProject.Swallow + +swallowSuite :: TestTree +swallowSuite = testGroup "Swallow" + [testCase "swallow test" testSwallow] + +testSwallow :: Assertion +testSwallow = "something" @=? swallow "some" "thing" diff --git a/test/Test.hs b/test/Test.hs new file mode 100644 index 0000000..ce19fdb --- /dev/null +++ b/test/Test.hs @@ -0,0 +1,15 @@ +module Main where + +import Test.Tasty (defaultMain,testGroup,TestTree) + +import HolyProject.Swallow.Test +import HolyProject.Coconut.Test + +main :: IO () +main = defaultMain tests + +tests :: TestTree +tests = testGroup "All Tests" + [ swallowSuite + , coconutSuite + ]