[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
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
2 changed files with 23 additions and 1 deletions

View file

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

View file

@ -137,6 +137,28 @@ public class MfmTests
MfmSerializer.Serialize(res).Should().BeEquivalentTo(input); 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] [TestMethod]
public void Benchmark() public void Benchmark()
{ {