[parsing] Fix hashtag detection (ISH-302)

This commit is contained in:
Laura Hausmann 2024-05-02 22:18:04 +02:00
parent bf26ed58ff
commit 69065ef1d7
Signed by: zotan
GPG key ID: D044E84C5BE01605
2 changed files with 23 additions and 1 deletions

View file

@ -243,7 +243,7 @@ module private MfmParser =
let hashtagNode =
previousCharSatisfiesNot isNotWhitespace
>>. skipChar '#'
>>. many1CharsTill letter (nextCharSatisfies isWhitespace <|> eof)
>>. many1CharsTill letter (nextCharSatisfiesNot isLetter)
|>> fun h -> MfmHashtagNode(h) :> MfmNode
let urlNodePlain =

View file

@ -136,6 +136,28 @@ public class MfmTests
res.ToList().Should().Equal(expected, MfmNodeEqual);
MfmSerializer.Serialize(res).Should().BeEquivalentTo(input);
}
[TestMethod]
public void TestHashtag()
{
const string input = "test #test #test's #test. test";
List<MfmNode> expected =
[
new MfmTextNode("test "),
new MfmHashtagNode("test"),
new MfmTextNode(" "),
new MfmHashtagNode("test"),
new MfmTextNode("'s "),
new MfmHashtagNode("test"),
new MfmTextNode(". test"),
];
var res = Mfm.parse(input);
AssertionOptions.FormattingOptions.MaxDepth = 100;
res.ToList().Should().Equal(expected, MfmNodeEqual);
MfmSerializer.Serialize(res).Should().BeEquivalentTo(input);
}
[TestMethod]
public void Benchmark()