fix(dossier): fix parser with dashes

This commit is contained in:
Paul Chavard 2023-01-31 10:40:48 +01:00
parent a462ff3f67
commit dcbe16603a
2 changed files with 11 additions and 6 deletions

View file

@ -41,11 +41,11 @@ module TagsSubstitutionConcern
end end
define_combinator :tag_text_first_char do define_combinator :tag_text_first_char do
any_char.that_fail(lit('-') | tag_delimiter) any_char.that_fail(lit('-') | tag_delimiter | eol)
end end
define_combinator :tag_text_char do define_combinator :tag_text_char do
any_char.that_fail(tag_delimiter) any_char.that_fail(tag_delimiter | eol)
end end
define_combinator :tag_text do define_combinator :tag_text do
@ -53,6 +53,10 @@ module TagsSubstitutionConcern
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ') str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
end end
end end
define_combinator :eol do
lit("\r\n") | lit("\n")
end
end end
DOSSIER_TAGS = [ DOSSIER_TAGS = [

View file

@ -516,7 +516,7 @@ describe TagsSubstitutionConcern, type: :model do
describe 'parser' do describe 'parser' do
it do it do
tokens = TagsSubstitutionConcern::TagsParser.parse("hello world --public--, --numéro du dossier--, un test--yolo-- encore du text\n---\n encore du text") tokens = TagsSubstitutionConcern::TagsParser.parse("hello world --public--, --numéro du dossier--, un test--yolo-- encore du text\n---\n encore du text --- et encore du text\n--tag--")
expect(tokens).to eq([ expect(tokens).to eq([
{ text: "hello world " }, { text: "hello world " },
{ tag: "public" }, { tag: "public" },
@ -524,14 +524,15 @@ describe TagsSubstitutionConcern, type: :model do
{ tag: "numéro du dossier" }, { tag: "numéro du dossier" },
{ text: ", un test" }, { text: ", un test" },
{ tag: "yolo" }, { tag: "yolo" },
{ text: " encore du text\n" + "---\n" + " encore du text" } { text: " encore du text\n" + "---\n" + " encore du text --- et encore du text\n" },
{ tag: "tag" }
]) ])
end end
it 'allow for - before tag' do it 'allow for - before tag' do
tokens = TagsSubstitutionConcern::TagsParser.parse("hello --yolo-- -- before-- --after -- -- around -- world ---numéro-du - dossier--") tokens = TagsSubstitutionConcern::TagsParser.parse("-----------------\nhello --yolo-- -- before-- --after -- -- around -- world ---numéro-du - dossier--")
expect(tokens).to eq([ expect(tokens).to eq([
{ text: "hello " }, { text: "-----------------\nhello " },
{ tag: "yolo" }, { tag: "yolo" },
{ text: " " }, { text: " " },
{ tag: "before" }, { tag: "before" },