From f4965108f89aba8ade3b45038ef6ef088773bc02 Mon Sep 17 00:00:00 2001 From: Mael Date: Mon, 4 Mar 2019 18:55:51 +0100 Subject: [PATCH] :white_check_mark: Test des expressions --- package.json | 1 + source/engine/treat.js | 2 +- test/expressions.test.js | 33 +++++++++++++++++++ .../expressions.yaml | 17 +++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 test/expressions.test.js rename source/engine/expressions-tests.yaml => test/expressions.yaml (56%) diff --git a/package.json b/package.json index fc5ce9548..03aa0e593 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "test-one": "yarn mocha-webpack --webpack-config source/webpack.test.js --require source-map-support/register --include componentTestSetup.js --require mock-local-storage --require test/helpers/browser.js", "test-components": "mocha-webpack --webpack-config source/webpack.test.js --require source-map-support/register --include componentTestSetup.js --require mock-local-storage ---require test/helpers/browser.js \"source/components/**/*.test.js\" --watch", "test-lib": "yarn test-common --grep 'library'", + "test-expressions": "yarn test-common --grep 'Expressions'", "compile-lib": "yarn webpack --config source/webpack.lib.js", "compile-dev": "FR_SITE='http://localhost:5000${path}' EN_SITE='http://localhost:5001${path}' yarn run compile", "mon-entreprise:serve": "PORT=5000 serve --config serve.mon-entreprise.json", diff --git a/source/engine/treat.js b/source/engine/treat.js index 3db14c38b..e0a1a710d 100644 --- a/source/engine/treat.js +++ b/source/engine/treat.js @@ -54,7 +54,7 @@ import { treatVariableTransforms } from './treatVariable' -let nearley = () => new Parser(Grammar.ParserRules, Grammar.ParserStart) +export let nearley = () => new Parser(Grammar.ParserRules, Grammar.ParserStart) export let treatString = (rules, rule) => rawNode => { /* On a affaire à un string, donc à une expression infixe. diff --git a/test/expressions.test.js b/test/expressions.test.js new file mode 100644 index 000000000..750f48305 --- /dev/null +++ b/test/expressions.test.js @@ -0,0 +1,33 @@ +import { expect } from 'chai' +import { enrichRule } from '../source/engine/rules' +import { analyse, parseAll } from '../source/engine/traverse' +import { collectMissingVariables } from '../source/engine/generateQuestions' +import * as R from 'ramda' +import { isNumeric } from '../source/utils' +import expressions from './expressions.yaml' +import { nearley } from 'Engine/treat' + +describe('Expressions', () => + expressions.map(expression => + it(expression, () => { + let result = nearley().feed(expression).results + + expect(result).to.not.be.empty + + return null + //TODO + + let [parseResult, ...additionnalResults] = result + + if ( + additionnalResults && + additionnalResults.length > 0 && + parseResult.category !== 'boolean' + ) { + expect(target.nodeValue).to.be.closeTo(valeur, 0.001) + expect(target).to.have.property('nodeValue', valeur) + + expect(missing).to.eql(expectedMissing) + } + }) + )) diff --git a/source/engine/expressions-tests.yaml b/test/expressions.yaml similarity index 56% rename from source/engine/expressions-tests.yaml rename to test/expressions.yaml index f301be410..0a9ab6ad0 100644 --- a/source/engine/expressions-tests.yaml +++ b/test/expressions.yaml @@ -1,7 +1,16 @@ +# A list of leaf expressions treated by our Nearley.js grammar +# For the moment, we just check if those are recognized + # CalcExpression - salaire de base * 3 - Salariat . salaire de base * 3 + +- 1 - taux +- salaire + 2000 + +# not working yet +# - salaire de base * 3 * 12 - congés non pris / 25 # Comparison @@ -11,10 +20,16 @@ # BooleanVariableExpression - Salariat . CDD . événements . CDD poursuivi en CDD -- ! événements . CDD poursuivi en CDD +- ≠ événements . CDD poursuivi en CDD # ModifedVariable # - salaire de base (> annuel) # - salaire de base --> annuel # - salaire de base annuel - salaire de base [annuel] + +- 0.1% + +- entreprise . catégorie d'activité = 'artisanale' + +- 11.5% * plafond sécurité sociale temps plein