First commit with simple colors activated

This commit is contained in:
Yann Esposito (Yogsototh) 2013-11-15 23:34:15 +01:00
commit 13f5d27afc
11 changed files with 204 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
.cabal-sandbox
cabal.sandbox.config
dist
*.swp
*~
.ghci

21
LICENSE Normal file
View file

@ -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.

2
Setup.hs Normal file
View file

@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain

70
holy-project.cabal Normal file
View file

@ -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

3
src/HolyProject.hs Normal file
View file

@ -0,0 +1,3 @@
module HolyProject where
import HolyProject.Swallow ()
import HolyProject.Coconut ()

View file

@ -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

View file

@ -0,0 +1,4 @@
module HolyProject.Swallow (swallow) where
swallow :: String -> String -> String
swallow prefix suffix = prefix ++ suffix

31
src/Main.hs Normal file
View file

@ -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

View file

@ -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

View file

@ -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"

15
test/Test.hs Normal file
View file

@ -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
]