Test des expressions

pull/478/head
Mael 2019-03-04 18:55:51 +01:00
parent e86b7c1f43
commit f4965108f8
4 changed files with 51 additions and 2 deletions

View File

@ -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",

View File

@ -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.

33
test/expressions.test.js Normal file
View File

@ -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)
}
})
))

View File

@ -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