UNPKG

boolean-expressions

Version:

Boolean expression parser and evaluator. Makes use of the Ohm grammar package with grammar rules found [here](https://github.com/avadavat/boolean-expressions/blob/master/src/grammar/grammarRules.ts).

22 lines (21 loc) 989 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var __1 = __importDefault(require("../")); var generateTestCases_1 = __importDefault(require("./generateTestCases")); var testCases = generateTestCases_1.default(); describe("simple query permutation tests", function () { testCases.forEach(function (testCase) { it("correctly evaluates " + testCase.expression, function () { var b = new __1.default(testCase.expression); var variableNames = b.getVariableNames(); testCase.truthTable.forEach(function (row) { var trueVariables = variableNames.filter(function (_, i) { return row[i]; }); var expectedResult = row[row.length - 1]; expect(b.evaluate(trueVariables)).toEqual(expectedResult); }); }); }); });