Skip to content

Commit 7bebdae

Browse files
committed
added some comments
1 parent 09fcc13 commit 7bebdae

File tree

1 file changed

+12
-0
lines changed
  • chapter24/parsing-ini-config-files/src/Data

1 file changed

+12
-0
lines changed

chapter24/parsing-ini-config-files/src/Data/Ini.hs

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Text.RawString.QQ
1515
import Text.Trifecta
1616

1717

18+
-- Example string to test our header parser
1819
headerEx :: String
1920
headerEx = "[blah]"
2021

@@ -27,6 +28,7 @@ parseBracketPair p = char '[' *> p <* char ']'
2728
parseHeader :: Parser Header
2829
parseHeader = parseBracketPair (Header <$> some letter)
2930

31+
-- Example string to test our assignment parser
3032
assignmentEx :: String
3133
assignmentEx = "name=person"
3234

@@ -45,9 +47,11 @@ parseAssignment = do
4547
skipEOL
4648
return (name, value)
4749

50+
-- Example string to test our comment parser
4851
commentEx :: String
4952
commentEx = "; comment on ini files looks like this"
5053

54+
-- Example string to test our assignment parser
5155
commentEx' :: String
5256
commentEx' = "; also; like this;"
5357

@@ -59,13 +63,15 @@ skipComments =
5963
skipEOL
6064
)
6165

66+
-- Example string to test our section parser
6267
sectionEx :: String
6368
sectionEx = [r|
6469
; ignore me
6570
[states]
6671
donut=happy
6772
|]
6873

74+
-- A slightly more complex section example. Stress that section.
6975
sectionEx' :: String
7076
sectionEx' = [r|
7177
; example 2
@@ -110,6 +116,12 @@ maybeSuccess :: Result a -> Maybe a
110116
maybeSuccess (Success a) = Just a
111117
maybeSuccess _ = Nothing
112118

119+
-- We can go ahead and test all the above parsers in ghci/repl
120+
-- with the given example strings or any other strings which constitutes a valid
121+
-- ini file
122+
-- But we can also test the whole thing by writing tests using the example strings
123+
-- The tests, of course, are also persistent and can be run later to verify a
124+
-- refactoring or other changes
113125
main :: IO ()
114126
main = hspec $ do
115127
describe "Assignment pairings" $

0 commit comments

Comments
 (0)