tests work

This commit is contained in:
Avi Dessauer 2020-04-30 01:22:45 -04:00
parent 9ebaeb0041
commit 5afe97f553
2 changed files with 31 additions and 7 deletions

View File

@ -22,12 +22,13 @@ data Component = Lib Path | Exe Name Path | Test Name Path
parseComponents :: Parser [Component]
parseComponents =
( do
traceM "do"
h <- parseComponent 0
t <- parseComponents
pure $ h : t
)
<|> (skipToNextLine >> parseComponents)
<|> (endOfInput >> pure [])
<|> (traceM "skip" >> skipToNextLine >> parseComponents)
<|> (traceM "pure" >> pure [])
parseComponent :: Indent -> Parser Component
parseComponent i =
@ -40,7 +41,7 @@ parseLib i =
indent i
>> asciiCI "library"
>> skipToNextLine
>> Lib <$> parsePath i
>> Lib <$> parsePath (i + 1)
parseComponentName :: Parser Name
parseComponentName = do
@ -55,12 +56,22 @@ parseNamed i compType compCon =
_ <- skipSpace <?> "skipSpace"
n <- parseComponentName <?> "N"
skipToNextLine
compCon n <$> parsePath i
compCon n <$> parsePath (i + 1)
<?> T.unpack ("parseNamed " <> compType)
skipToNextLine :: Parser ()
skipToNextLine = skipWhile (not . isEndOfLine) >> endOfLine
skipBlock :: Indent -> Parser ()
skipBlock i =
skipMany $
(indent i >> skipToNextLine)
<|> (skipMany tabOrSpace >> endOfLine)
<|> (skipSpace >> "--" >> skipToNextLine)
tabOrSpace :: Parser Char
tabOrSpace = char ' ' <|> char '\t'
parsePath :: Indent -> Parser Path
parsePath i =
( do
@ -71,7 +82,7 @@ parsePath i =
-- FIXME paths can be in quotes
p <- parseComponentName
skipToNextLine
skipMany $ indent i >> skipToNextLine
skipBlock i
pure p
<?> "hs-source-dirs"
)
@ -85,5 +96,5 @@ parsePath i =
-- | Skip at least n spaces
indent :: Indent -> Parser ()
indent 0 = skipMany space <?> "indent 0"
indent i = space >> indent (i - 1) <?> "indent 0"
indent 0 = skipMany tabOrSpace <?> "indent 0"
indent i = tabOrSpace >> indent (i - 1) <?> "indent 0"

View File

@ -23,6 +23,19 @@ spec = do
$ it "successfully parses library section"
$ libSection ~> parseLib 0
`shouldParse` Lib "src"
describe "Should Succeed"
$ it "successfully parses library section"
$ (exeSection <> testSection <> libSection) ~> parseComponents
`shouldParse` [ Exe "implicit-hie-exe" "app",
Test "implicit-hie-test" "test",
Lib "src"
]
describe "Should Succeed"
$ it
"successfully parses library section"
$ let r = "test\n"
in (libSection <> r) ~?> parseLib 0
`leavesUnconsumed` r
exeSection :: Text
exeSection =