Skip to content

Commit

Permalink
[fix] fix tests break
Browse files Browse the repository at this point in the history
  • Loading branch information
running-grass committed Jul 31, 2022
1 parent 99ee9c7 commit 99ecc7e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
30 changes: 29 additions & 1 deletion src/Language/Markdown/Parser.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/src/Test/Parser.idr
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
]
Expand Down

0 comments on commit 99ecc7e

Please sign in to comment.