fix(dossier): a tag can be preceded by a -

This commit is contained in:
Paul Chavard 2022-10-21 14:01:18 +02:00
parent 4f30581962
commit d7c5dcf8bb
2 changed files with 19 additions and 1 deletions

View file

@ -32,8 +32,16 @@ module TagsSubstitutionConcern
lit('--')
end
define_combinator :tag_text_first_char do
any_char.that_fail(lit('-') | tag_delimiter | eol)
end
define_combinator :tag_text_char do
any_char.that_fail(tag_delimiter | eol)
end
define_combinator :tag_text do
join(many(any_char.that_fail(tag_delimiter | eol))).fmap do |str|
join(single(tag_text_first_char) + many(tag_text_char)).fmap do |str|
str.force_encoding('utf-8').encode
end
end

View file

@ -509,5 +509,15 @@ describe TagsSubstitutionConcern, type: :model do
{ text: " encore du text\n" + "---\n" + " encore du text" }
])
end
it 'allow for - before tag' do
tokens = TagsSubstitutionConcern::TagsParser.parse("hello --yolo-- world ---numéro-du - dossier--")
expect(tokens).to eq([
{ text: "hello " },
{ tag: "yolo" },
{ text: " world -" },
{ tag: "numéro-du - dossier" }
])
end
end
end