Skip to content

Commit

Permalink
feat: serialize the [résoudre la référence circulaire]
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileRolley committed Jan 25, 2024
1 parent b7b897c commit 160f3b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
27 changes: 9 additions & 18 deletions source/serializeParsedRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ function serializeASTNode(node: ASTNode): SerializedRule {
node.explanation.inversionCandidates.map(serializeASTNode),
}
}
case 'résoudre référence circulaire': {
return {
'résoudre la référence circulaire': 'oui',
...serializedRuleToRawRule(
serializeASTNode(node.explanation.valeur),
),
}
}

default: {
throw new Error(
Expand Down Expand Up @@ -403,24 +411,7 @@ export function serializeParsedRules(
* TODO: a way to keep the [avec] mecanism in the rawNode could be investigated but
* for now it's not a priority.
*/
const syntaxicSugars = [
'avec',
'formule',
'valeur',
'contexte',
'somme',
'moyenne',
'produit',
'une de ces conditions',
'toutes ces conditions',
'est défini',
'est non défini',
'texte',
'le maximum de',
'le minimum de',
'remplace',
'par défaut',
]
const syntaxicSugars = ['avec', 'formule', 'valeur', 'contexte']
const rawRules = {}

for (const [rule, node] of Object.entries(parsedRules)) {
Expand Down
15 changes: 14 additions & 1 deletion test/serializeParsedRules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ describe('API > mecanisms list', () => {
valeur: '50 €',
},
'prix TTC': {
assiette: 'prix HT * (100 % + TVA)',
valeur: 'prix HT * (100 % + TVA)',
},
TVA: {
valeur: '50 %',
Expand Down Expand Up @@ -793,6 +793,19 @@ describe('API > mecanisms list', () => {
expect(serializedRules).toStrictEqual(rules)
})

it('should serialize rule with [résoudre la référence circulaire]', () => {
const rules = {
x: {
valeur: '(4 * x) - 5',
'résoudre la référence circulaire': 'oui',
},
}
const serializedRules = serializeParsedRules(
new Engine(rules).getParsedRules(),
)
expect(serializedRules).toStrictEqual(rules)
})

// TODO
// it('should serialize rule with [private rule]', () => {
// const rules = {
Expand Down

0 comments on commit 160f3b8

Please sign in to comment.