From 99ecc7e37da56f8129a2aa645e67abd645b9282b Mon Sep 17 00:00:00 2001 From: Leo Liu <467195537@qq.com> Date: Sun, 31 Jul 2022 19:33:39 +0800 Subject: [PATCH] [fix] fix tests break --- src/Language/Markdown/Parser.idr | 30 +++++++++++++++++++++++++++++- test/src/Test/Parser.idr | 4 ++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Language/Markdown/Parser.idr b/src/Language/Markdown/Parser.idr index bdbf82d..e40c092 100644 --- a/src/Language/Markdown/Parser.idr +++ b/src/Language/Markdown/Parser.idr @@ -25,6 +25,11 @@ private mergeBare : List Inline -> List Inline mergeBare = foldr consBare [] +private +isT : Token MarkdownTokenKind -> Bool +isT (Tok MKAsterisk _) = True +isT _ = True + mutual private document : Grammar state MarkdownToken True Markdown @@ -57,7 +62,11 @@ mutual private inlineComp : Grammar state MarkdownToken True Inline - inlineComp = code <|> bold <|> textSpace <|> textNumberSign <|> italic <|> bare + inlineComp = code <|> codeFail + <|> bold <|> boldFail + <|> italic <|> italicFail + <|> textSpace <|> textNumberSign + <|> bare private code : Grammar state MarkdownToken True Inline @@ -67,12 +76,24 @@ mutual _ <- match MKBackQuote pure $ MCode $ concat1 vals + private + codeFail : Grammar state MarkdownToken True Inline + codeFail = do + _ <- match MKBackQuote + pure $ MBare "`" + private italic : Grammar state MarkdownToken True Inline italic = do _ <- match MKAsterisk vals <- some $ match MKText _ <- match MKAsterisk + -- _ <- (eof <|> (nextIs "lala" isT)) pure $ MItalic $ concat1 vals + private + italicFail : Grammar state MarkdownToken True Inline + italicFail = do + _ <- match MKAsterisk + pure $ MBare "*" private bold : Grammar state MarkdownToken True Inline @@ -82,6 +103,13 @@ mutual _ <- match MKAsterisk _ <- match MKAsterisk pure $ MBold $ concat1 vals + + private + boldFail : Grammar state MarkdownToken True Inline + boldFail = do + _ <- match MKAsterisk + _ <- match MKAsterisk + pure $ MBare "**" bare : Grammar state MarkdownToken True Inline bare = do vals <- some $ (match MKText <|> match MKSpace) diff --git a/test/src/Test/Parser.idr b/test/src/Test/Parser.idr index bd23b1c..55f00b1 100644 --- a/test/src/Test/Parser.idr +++ b/test/src/Test/Parser.idr @@ -36,8 +36,8 @@ testBold : List Test testBold = [ test "测试普通粗体" $ assertBlocks "**bold**" [MLine [MBold "bold"]] , test "测试粗体失败" $ assertBlocks "**bold" [MLine [MBare "**bold"]] - , test "测试粗体失败1" $ assertBlocks "**bold" [MLine [MBare "**bold*"]] - , test "测试粗体失败2" $ assertBlocks "**bold" [MLine [MBare "*bold**"]] + , test "测试粗体失败1" $ assertBlocks "**bold*" [MLine [MBare "**bold*"]] + , test "测试粗体失败2" $ assertBlocks "*bold**" [MLine [MItalic "bold", MBare("*")]] , test "测试多个粗体" $ assertBlocks "**bold** normal **bold** " [MLine [MBold "bold",MBare " normal ",MBold "bold", MBare " "]] , test "测试标题中的粗体" $ assertBlocks "## I am **BOLD**" [MHeading 2 [MBare "I am ", MBold "BOLD"]] ]