UNPKG

expression-language

Version:

Javascript implementation of symfony/expression-language

35 lines (34 loc) 1.6 kB
"use strict"; var _Parser = require("../Parser"); var _ExpressionLanguage = _interopRequireDefault(require("../ExpressionLanguage")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Tests for ExpressionLanguage.lint and using flags through the high-level API */ describe('ExpressionLanguage.lint and flags', () => { test('lint passes for valid expression', () => { const el = new _ExpressionLanguage.default(); el.lint('foo["some_key"].callFunction(a ? b)', ['foo', 'a', 'b']); }); test('lint throws by default for unknown variable and function', () => { const el = new _ExpressionLanguage.default(); expect(() => el.lint('myFn(foo)')).toThrow(); }); test('lint allows unknown variables when flag is set', () => { const el = new _ExpressionLanguage.default(); el.lint('foo.bar', [], _Parser.IGNORE_UNKNOWN_VARIABLES); }); test('lint allows unknown functions when flag is set', () => { const el = new _ExpressionLanguage.default(); el.lint('foo()', [], _Parser.IGNORE_UNKNOWN_FUNCTIONS); }); test('lint allows both unknown function and variable when both flags set', () => { const el = new _ExpressionLanguage.default(); el.lint('foo(bar)', [], _Parser.IGNORE_UNKNOWN_FUNCTIONS | _Parser.IGNORE_UNKNOWN_VARIABLES); }); test('lint supports deprecated null names by converting to IGNORE_UNKNOWN_VARIABLES', () => { const el = new _ExpressionLanguage.default(); // Should not throw because names === null maps to IGNORE_UNKNOWN_VARIABLES internally el.lint('foo.bar', null, 0); }); });