Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First batch of unit tests for Reader.Internals.

  • Loading branch information...
commit 73e4659ee3a0fc06220fd020d68641c58f8a44f2 1 parent d77801b
@magthe authored
Showing with 92 additions and 3 deletions.
  1. +2 −2 hsini.cabal
  2. +3 −1 tst/Main.hs
  3. +87 −0 tst/ReaderI.hs
View
4 hsini.cabal
@@ -24,9 +24,9 @@ library
Executable test
main-is : Main.hs
hs-source-dirs : tst, src
- other-modules : Ini
+ other-modules : Ini ReaderI
if flag(Test)
- build-depends : HTF
+ build-depends : HTF, HUnit
buildable : True
ghc-options : -fhpc
else
View
4 tst/Main.hs
@@ -4,7 +4,9 @@ import System.Environment ( getArgs )
import Test.Framework
import qualified Ini as I
+import qualified ReaderI as RI
main = do
args <- getArgs
- runTestWithArgs args I.allHTFTests
+ -- runTestWithArgs args [I.allHTFTests, RI.allHTFTests]
+ runTestWithArgs args [RI.allHTFTests]
View
87 tst/ReaderI.hs
@@ -0,0 +1,87 @@
+{-# OPTIONS_GHC -F -pgmF htfpp #-}
+
+module ReaderI where
+
+import Test.Framework
+import Test.HUnit.Base
+import Text.ParserCombinators.Parsec as P
+
+import Data.Ini.Reader.Internals
+
+-- Convenience function that translates a parser result to something that's
+-- easier to check.
+p2E p s t = let
+ res = P.parse p s t
+ in case res of
+ Left _ -> Left "bad"
+ Right e -> Right e
+
+-- {{{1 secParser
+test_secParserBasic = let
+ expected = Right $ SectionL "foo"
+ actual = p2E secParser "sec" "[foo]\n"
+ in assertEqual expected actual
+
+test_secParserDropSpace = let
+ expected = Right $ SectionL "foo"
+ actual = p2E secParser "sec" "[ \tfoo\t ]\n"
+ in assertEqual expected actual
+
+test_secParserDropTrailing = let
+ expected = Right $ SectionL "foo"
+ actual = p2E secParser "sec" "[foo] \t foobar\n"
+ in assertEqual expected actual
+
+-- {{{1 optLineParser
+test_optLineParserBasic = let
+ expected = Right $ OptionL "foo" "bar"
+ actual = p2E optLineParser "optLine" "foo=bar\n"
+ in assertEqual expected actual
+
+test_optLineParserDropSpace = let
+ expected = Right $ OptionL "foo" "bar"
+ actual = p2E optLineParser "optLine" "foo\t \t=\t \t bar\n"
+ in assertEqual expected actual
+
+test_optLineParserKeepSpace = let
+ expected = Right $ OptionL "foo" "bar \t \t"
+ actual = p2E optLineParser "optLine" "foo\t \t=\t \t bar \t \t\n"
+ in assertEqual expected actual
+
+-- {{{1 optContParser
+test_optContParserSpace = let
+ expected = Right $ OptionContL "foo"
+ actual = p2E optContParser "optCont" " foo\n"
+ in assertEqual expected actual
+
+test_optContParserTab = let
+ expected = Right $OptionContL "foo"
+ actual = p2E optContParser "optCont" "\tfoo\n"
+ in assertEqual expected actual
+
+test_optContParserKeepTrailing = let
+ expected = Right $ OptionContL "foo \t\t"
+ actual = p2E optContParser "optCont" "\tfoo \t\t\n"
+ in assertEqual expected actual
+
+-- {{{1 noiseParser
+test_noiseParserEmptyLine = let
+ expected = Right CommentL
+ actual = p2E noiseParser "noise" "\n"
+ in assertEqual expected actual
+
+test_noiseParserComment = let
+ expected = Right CommentL
+ actual = p2E noiseParser "noise" "# a comment\n"
+ in assertEqual expected actual
+
+test_noiseParserNonEmpty = let
+ expected = Left "bad"
+ actual = p2E noiseParser "noise" " \n"
+ in assertEqual expected actual
+
+-- {{{1 iniParser
+-- TBD
+
+-- {{{1 buildConfig
+-- TBD
Please sign in to comment.
Something went wrong with that request. Please try again.