Permalink
Browse files

merge in pull request #19. thanks @mklinik! Closes #19

  • Loading branch information...
2 parents fcde8ca + 61d4ca4 commit 579a76f547879eae26a773532ffd896d4530914b @toothbrush committed Apr 23, 2012
Showing with 92 additions and 48 deletions.
  1. +1 −3 .ghci
  2. +8 −8 System/DotFS/Core/ExpressionParsers.hs
  3. +1 −1 System/DotFS/Test/Unit.hs
  4. +32 −36 dotfs.cabal
  5. +41 −0 test/ParserSpec.hs
  6. +9 −0 test/Spec.hs
View
4 .ghci
@@ -1,3 +1 @@
-:m + Test.QuickCheck
-:set -isrc
-:l System.DotFS.Test.Tests
+:set -i. -itest
@@ -33,19 +33,19 @@ table = [
pre s f = Prefix (do { reservedOp lex s; return f })
factor :: ParsecT String DFSState Identity DFSExpr
-factor = try (parens lex exprP)
- <|> (try $ (Prim . VInt) <$> integer lex)
- <|> (try $ (Prim . VBool) <$> boolTerm)
- <|> (try $ (Prim . VString) <$> stringLiteral lex)
- <|> (try $ Var <$> identifier lex)
- <|> (try ifTerm)
+factor = (parens lex exprP)
+ <|> ((Prim . VInt) <$> integer lex)
+ <|> ((Prim . VBool) <$> boolTerm)
+ <|> ((Prim . VString) <$> stringLiteral lex)
+ <|> (Var <$> identifier lex)
+ <|> ifTerm
<?> "simple expression or variable"
boolTerm :: forall u. ParsecT String u Identity Bool
-boolTerm = do { _ <- symbol lex "true"
+boolTerm = do { _ <- reserved lex "true"
; return True
}
- <|> do { _ <- symbol lex "false"
+ <|> do { _ <- reserved lex "false"
; return False
}
@@ -1,4 +1,4 @@
-{-# OPTIONS_GHC -fno-warn-unused-imports -fforce-recomp -fth #-}
+{-# OPTIONS_GHC -fno-warn-unused-imports -fforce-recomp -fth -fno-warn-orphans #-}
module System.DotFS.Test.Unit where
import System.DotFS.Test.Utility -- our TH functions
View
@@ -34,7 +34,20 @@ Test-Suite test-dotfs
default-language: Haskell98
main-is: System/DotFS/Test/Main.hs
-Library
+Executable dotfs
+ default-language: Haskell98
+ ghc-options: -threaded
+ main-is: System/DotFS/DotFS.hs
+ build-depends: bytestring >=0.9,
+ base >= 4 && < 5,
+ HFuse > 0.2.4,
+ directory>=1,
+ unix >= 2.3,
+ filepath >=1.1,
+ parsec,
+ containers,
+ transformers,
+ process
other-modules: System.DotFS.Core.BodyParser,
System.DotFS.Core.ExpressionParsers,
System.DotFS.Core.Constants,
@@ -53,42 +66,25 @@ Library
System.DotFS.Util.Options,
System.DotFS.Util.Sanity,
System.DotFS.Util.Version
+test-suite spec
+ default-language:
+ Haskell98
+ type:
+ exitcode-stdio-1.0
+ ghc-options:
+ -Wall -Werror
+ hs-source-dirs:
+ ., test
+ main-is:
+ Spec.hs
+ build-depends:
+ base
+ , hspec
+ , HUnit
+ , parsec
+ , transformers
+ , containers
- default-language: Haskell98
- build-depends: bytestring >=0.9,
- base >= 4 && < 5,
- HFuse > 0.2.4,
- directory>=1,
- unix >= 2.3,
- filepath >=1.1,
- parsec,
- containers,
- transformers,
- process,
- HUnit >= 1.2 && < 2,
- QuickCheck >= 2.4,
- test-framework >= 0.4.1,
- test-framework-quickcheck2,
- test-framework-hunit,
- parsec >= 3,
- haskell-src,
- template-haskell
-
-Executable dotfs
- default-language: Haskell98
- ghc-options: -threaded
- -- TODO: make this compile cleanly with -Wall
- main-is: System/DotFS/DotFS.hs
- build-depends: bytestring >=0.9,
- base >= 4 && < 5,
- HFuse > 0.2.4,
- directory>=1,
- unix >= 2.3,
- filepath >=1.1,
- parsec,
- containers,
- transformers,
- process
source-repository head
type: git
View
@@ -0,0 +1,41 @@
+{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
+module ParserSpec (main, spec) where
+
+import Test.Hspec.HUnit()
+import Test.Hspec.Monadic
+import Test.HUnit
+import Text.Parsec
+import qualified Data.Map as Map
+
+import System.DotFS.Core.ExpressionParsers
+import System.DotFS.Core.Datatypes
+
+main :: IO ()
+main = hspecX spec
+
+fromRight = either undefined id
+
+emptyEnvironment :: DFSState
+emptyEnvironment = Map.fromList []
+
+spec :: Specs
+spec = do
+ describe "boolTerm" $ do
+ it "parses constant 'true'" $ do
+ assertEqual "" (fromRight $ parse boolTerm "" "true") True
+
+ it "parses constant 'false'" $ do
+ assertEqual "" (fromRight $ parse boolTerm "" "false") False
+
+ describe "factor" $ do
+ it "parses constants 'true' and 'false'" $ do
+ assertEqual "" (fromRight $ runParser factor emptyEnvironment "" "true") (Prim $ VBool True)
+ assertEqual "" (fromRight $ runParser factor emptyEnvironment "" "false") (Prim $ VBool False)
+
+ it "parses prefixes of 'true' and 'false' to identifiers" $ do
+ assertEqual "" (fromRight $ runParser factor emptyEnvironment "" "tr") (Var "tr")
+ assertEqual "" (fromRight $ runParser factor emptyEnvironment "" "fa") (Var "fa")
+
+ it "parses identifiers that start with 'true' and 'false' to identifiers" $ do
+ assertEqual "" (fromRight $ runParser factor emptyEnvironment "" "truee") (Var "truee")
+ assertEqual "" (fromRight $ runParser factor emptyEnvironment "" "falsee") (Var "falsee")
View
@@ -0,0 +1,9 @@
+module Main (main) where
+
+import Test.Hspec.Monadic
+
+import qualified ParserSpec
+
+main :: IO ()
+main = hspecX $ do
+ describe "Parser" ParserSpec.spec

0 comments on commit 579a76f

Please sign in to comment.