feat(tags): replace regexp based parser with a parser combinator

This commit is contained in:
Paul Chavard 2022-10-04 18:53:28 +02:00
parent 32cdff820f
commit 432c4690b5
5 changed files with 137 additions and 52 deletions

View file

@ -383,13 +383,13 @@ describe TagsSubstitutionConcern, type: :model do
context 'when generating a document for a dossier that is not termine' do
let(:dossier) { create(:dossier) }
let(:template) { '--motivation-- --date de décision--' }
let(:template) { 'text --motivation-- --date de décision--' }
let(:state) { Dossier.states.fetch(:en_instruction) }
subject { template_concern.send(:replace_tags, template, dossier) }
it "does not treat motivation or date de décision as tags" do
is_expected.to eq('--motivation-- --date de décision--')
is_expected.to eq('text --motivation-- --date de décision--')
end
end
@ -495,4 +495,19 @@ describe TagsSubstitutionConcern, type: :model do
it { is_expected.to eq([["public", procedure.draft_revision.types_de_champ.first.stable_id], ['yolo']]) }
end
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")
expect(tokens).to eq([
{ text: "hello world " },
{ tag: "public" },
{ text: ", " },
{ tag: "numéro du dossier" },
{ text: ", un test" },
{ tag: "yolo" },
{ text: " encore du text\n" + "---\n" + " encore du text" }
])
end
end
end