EdgeVerve / feel

Expression Language for creating and executing business rules in decision table based on DMN 1.1 specification for conformance level 3
MIT License
93 stars 48 forks source link

not(true) seems not to work #33

Open thorek opened 1 year ago

thorek commented 1 year ago

In the following test suite, the tests 'evaluates true = true' and 'evaluates true = false' are evaluated correctly, showing the js-feel implementation seems to work properly, however the tests 'not(true)' and 'not(false)' evaluate to a Function (not to a boolean). If I try to call the function it throws an error "TypeError: Cannot read properties of undefined (reading 'isDate')".

Any help is appreciated.

const feel = require('js-feel/dist/feel');

describe( 'inbuild "not" function', () => {

  it( 'evaluates not(true)', async () => {
    const notTrue = 'not(true)'    
    const ast = await feel.parse( notTrue );
    const result = await ast.build({});
    expect( result ).toBe( false );   // -> Function
  });

  it( 'evaluates not(false)', async () => {
    const notFalse = 'not(false)'    
    const ast = await feel.parse( notFalse );
    const result = await ast.build({});
    expect( result ).toBe( true );   // -> Function
  });

  it( 'evaluates not(true) - with function', async () => {
    const notTrue = 'not(true)'    
    const ast = await feel.parse( notTrue);
    let result = await ast.build({});
    if( typeof result === 'function' ) result = result();
    expect( result ).toBe( false );   // -> "TypeError: Cannot read properties of undefined (reading 'isDate')"
  });

  it( 'evaluates true = true', async () => {
    const notTrue = 'true = true'    
    const ast = await feel.parse( notTrue);
    const result = await ast.build({});
    expect( result ).toBe( true );   // -> ok
  });

  it( 'evaluates true = false', async () => {
    const notTrue = 'true = false'    
    const ast = await feel.parse( notTrue);
    const result = await ast.build({});
    expect( result ).toBe( false );   // -> ok
  });

});
thorek commented 8 months ago

Anyone? I can't believe I'm the only one having an issue with such a basic feature. Am I missing something?