fix(dossier): fix parser with dashes
This commit is contained in:
parent
a462ff3f67
commit
dcbe16603a
2 changed files with 11 additions and 6 deletions
|
@ -41,11 +41,11 @@ module TagsSubstitutionConcern
|
|||
end
|
||||
|
||||
define_combinator :tag_text_first_char do
|
||||
any_char.that_fail(lit('-') | tag_delimiter)
|
||||
any_char.that_fail(lit('-') | tag_delimiter | eol)
|
||||
end
|
||||
|
||||
define_combinator :tag_text_char do
|
||||
any_char.that_fail(tag_delimiter)
|
||||
any_char.that_fail(tag_delimiter | eol)
|
||||
end
|
||||
|
||||
define_combinator :tag_text do
|
||||
|
@ -53,6 +53,10 @@ module TagsSubstitutionConcern
|
|||
str.force_encoding('utf-8').encode.gsub(/[[:space:]]/, ' ')
|
||||
end
|
||||
end
|
||||
|
||||
define_combinator :eol do
|
||||
lit("\r\n") | lit("\n")
|
||||
end
|
||||
end
|
||||
|
||||
DOSSIER_TAGS = [
|
||||
|
|
|
@ -516,7 +516,7 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
|
||||
describe 'parser' 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([
|
||||
{ text: "hello world " },
|
||||
{ tag: "public" },
|
||||
|
@ -524,14 +524,15 @@ describe TagsSubstitutionConcern, type: :model do
|
|||
{ tag: "numéro du dossier" },
|
||||
{ text: ", un test" },
|
||||
{ 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
|
||||
|
||||
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([
|
||||
{ text: "hello " },
|
||||
{ text: "-----------------\nhello " },
|
||||
{ tag: "yolo" },
|
||||
{ text: " " },
|
||||
{ tag: "before" },
|
||||
|
|
Loading…
Reference in a new issue