summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-04-11 17:52:30 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-04-11 21:36:35 +0200
commitcd2e1323ef62574f0879e789457248c68ee46326 (patch)
tree680e78636ccd5d6f4605b6a8056055c40746b4d9
parent204169f26907828d5310845a94af7c4ffafa6cd0 (diff)
Parse tags in test preambleHEADmaster
-rw-r--r--src/Parser.hs24
-rw-r--r--src/Parser/Core.hs9
-rw-r--r--src/Test.hs1
3 files changed, 24 insertions, 10 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index d3b8f73..bb8288e 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -43,12 +43,34 @@ parseTestDefinition = label "test definition" $ toplevel ToplevelTest $ do
modify $ \s -> s
{ testContext = SomeExpr $ varExpr SourceLineBuiltin rootNetworkVar
}
- block (\name steps -> return $ Test name $ Scope <$> mconcat steps) header testStep
+ href <- L.indentLevel
+ testName <- header
+ osymbol ":" <* eol <* scn
+
+ ref <- L.indentGuard scn GT href
+ testTags <- preamble ref
+ testSteps <- fmap Scope <$> testBlock ref
+ return Test {..}
+
where
header = do
wsymbol "test"
lexeme $ TL.toStrict <$> takeWhileP (Just "test name") (/=':')
+ preamble :: Pos -> TestParser [ Expr Tag ]
+ preamble ref = fmap catMaybes $ many $ do
+ void $ L.indentGuard scn EQ ref
+ off <- stateOffset <$> getParserState
+ name <- try $ identifier <* osymbol ":"
+ case name of
+ "tag" -> do
+ Just <$> typedExpr <* eol <* scn
+ _ -> do
+ registerParseError $ FancyError off $ S.singleton $ ErrorFail $
+ "unexpected test metadata ‘" <> T.unpack name <> "’"
+ takeWhileP Nothing (/= '\n') *> eol *> scn *> return Nothing
+
+
parseDefinition :: Pos -> TestParser ( VarName, SomeExpr )
parseDefinition href = label "symbol definition" $ do
def@( name, expr ) <- localState $ do
diff --git a/src/Parser/Core.hs b/src/Parser/Core.hs
index 786fb2e..562923d 100644
--- a/src/Parser/Core.hs
+++ b/src/Parser/Core.hs
@@ -250,15 +250,6 @@ localState inner = do
toplevel :: (a -> b) -> TestParser a -> TestParser b
toplevel f = return . f <=< L.nonIndented scn
-block :: (a -> [b] -> TestParser c) -> TestParser a -> TestParser b -> TestParser c
-block merge header item = L.indentBlock scn $ do
- h <- header
- choice
- [ do symbol ":"
- return $ L.IndentSome Nothing (merge h) item
- , L.IndentNone <$> merge h []
- ]
-
listOf :: TestParser a -> TestParser [a]
listOf item = do
x <- item
diff --git a/src/Test.hs b/src/Test.hs
index f1d1f96..d16b997 100644
--- a/src/Test.hs
+++ b/src/Test.hs
@@ -26,6 +26,7 @@ import Script.Shell
data Test = Test
{ testName :: Text
+ , testTags :: [ Expr Tag ]
, testSteps :: Expr (TestStep ())
}