From 94dbd2c54ed960e645ccad88b88525e938bd7cd2 Mon Sep 17 00:00:00 2001 From: David Bruant Date: Sat, 26 Apr 2025 19:55:08 +0200 Subject: [PATCH] tests passing --- scripts/odf/fillOdtTemplate.js | 22 ++++++++++++---------- tests/fill-odt-template.js | 12 ++++++------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/scripts/odf/fillOdtTemplate.js b/scripts/odf/fillOdtTemplate.js index d1c2071..dcb1157 100644 --- a/scripts/odf/fillOdtTemplate.js +++ b/scripts/odf/fillOdtTemplate.js @@ -261,25 +261,27 @@ function fillTemplatedOdtElement(rootElement, data, Node){ if(match){ // split 3-way : before-match, match and after-match - let afterMatchTextNode - if(match[0].length < remainingText.length){ - afterMatchTextNode = currentNode.splitText(match.index + match[0].length) + let afterMatchTextNode = currentNode.splitText(match.index + match[0].length) if(afterMatchTextNode.textContent && afterMatchTextNode.textContent.length >= 1){ remainingText = afterMatchTextNode.textContent } else{ remainingText = '' } - } + + // per spec, currentNode now contains before-match and match text + + if(match.index > 0){ + currentNode.splitText(match.index) + } - // per spec, currentNode now contains before-match and match text - if(match.index > 0){ - currentNode.splitText(match.index) + if(afterMatchTextNode){ + currentNode = afterMatchTextNode + } } - - if(afterMatchTextNode){ - currentNode = afterMatchTextNode + else{ + remainingText = '' } } else{ diff --git a/tests/fill-odt-template.js b/tests/fill-odt-template.js index 14d5869..ec06b9a 100644 --- a/tests/fill-odt-template.js +++ b/tests/fill-odt-template.js @@ -73,7 +73,7 @@ Pâtes à lasagne (fraîches !) }); -test.skip('Filling with {#each} and non-iterable value results in no error and empty result', async t => { +test('Filling with {#each} and non-iterable value results in no error and empty result', async t => { const templatePath = join(import.meta.dirname, './fixtures/enum-courses.odt') const templateContent = `🧺 La liste de courses incroyable 🧺 @@ -103,7 +103,7 @@ test.skip('Filling with {#each} and non-iterable value results in no error and e }); -test.skip('template filling with {#each} generating a list', async t => { +test('template filling with {#each} generating a list', async t => { const templatePath = join(import.meta.dirname, './fixtures/liste-courses.odt') const templateContent = `🧺 La liste de courses incroyable 🧺 @@ -140,7 +140,7 @@ test.skip('template filling with {#each} generating a list', async t => { }); -test.skip('template filling with 2 sequential {#each}', async t => { +test('template filling with 2 sequential {#each}', async t => { const templatePath = join(import.meta.dirname, './fixtures/liste-fruits-et-légumes.odt') const templateContent = `Liste de fruits et légumes @@ -192,7 +192,7 @@ Poivron 🫑 }); -test.skip('template filling with nested {#each}s', async t => { +test('template filling with nested {#each}s', async t => { const templatePath = join(import.meta.dirname, './fixtures/légumes-de-saison.odt') const templateContent = `Légumes de saison @@ -305,7 +305,7 @@ Les nombres : 1 1 2 3 5 8 13 21  !! -test.skip('template filling of a table', async t => { +test('template filling of a table', async t => { const templatePath = join(import.meta.dirname, './fixtures/tableau-simple.odt') const templateContent = `Évolution énergie en kWh par personne en France @@ -366,7 +366,7 @@ Année }); -test.skip('template filling preserves images', async t => { +test('template filling preserves images', async t => { const templatePath = join(import.meta.dirname, './fixtures/template-avec-image.odt') const data = {