Skip to content

Commit 2895c27

Browse files
committed
fix(woql): Add evaluate() method for fluent/chained query style
Fixes issue #317 where WOQL.evaluate() only existed as a functional method but was missing from the WOQLQuery prototype for fluent/chained style. ## Problem: Users reported error: "WOQL.limit(...).evaluate is not a function" - WOQL.evaluate() worked: WOQL.evaluate(expr, var) - WOQL.limit().evaluate() failed: "evaluate is not a function" ## Root Cause: - WOQLQuery.prototype.eval() existed for chaining - WOQLQuery.prototype.evaluate() was missing - WOQL.evaluate() functional wrapper existed but called eval() internally ## Solution: Added WOQLQuery.prototype.evaluate() as an alias to eval() for consistency. **Implementation (woqlQuery.js):** ```javascript WOQLQuery.prototype.evaluate = function (arithExp, resultVarName) { return this.eval(arithExp, resultVarName); }; ``` ## Testing: **3 new tests added:** 1. ✅ evaluate() functional style works 2. ✅ evaluate() fluent style works (WOQL.limit(100).evaluate(...)) 3. ✅ evaluate() and eval() produce identical results **All 153 tests passing** ## Usage: ```javascript // Both naming conventions now work in functional style: WOQL.eval(WOQL.times(2, 3), 'result') WOQL.evaluate(WOQL.times(2, 3), 'result') // Both naming conventions now work in fluent style: WOQL.limit(100).eval(WOQL.times(2, 3), 'result') WOQL.limit(100).evaluate(WOQL.times(2, 3), 'result') // ✅ Now works! ``` Resolves #317
1 parent ed94e33 commit 2895c27

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/query/woqlQuery.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,19 @@ WOQLQuery.prototype.eval = function (arithExp, resultVarName) {
920920
return this;
921921
};
922922

923+
/**
924+
* Evaluates the passed arithmetic expression and generates or matches the result value.
925+
* Alias for eval() to support both naming conventions in fluent/chained style.
926+
* @param {object|WOQLQuery|string} arithExp - A WOQL query containing a valid arithmetic expression
927+
* @param {string|number|Var} resultVarName - Either a variable to store the result, or a numeric
928+
* literal to test against the evaluated expression
929+
* @returns {WOQLQuery}
930+
*/
931+
932+
WOQLQuery.prototype.evaluate = function (arithExp, resultVarName) {
933+
return this.eval(arithExp, resultVarName);
934+
};
935+
923936
/**
924937
* Adds the numbers together
925938
* @param {...(string|number|Var)} args - a variable or numeric containing the values to add

test/woql.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,34 @@ describe('woql queries', () => {
190190
expect(woqlObject.json()).to.eql(woqlMathJson.evalJson);
191191
});
192192

193+
it('check the evaluate method (functional style)', () => {
194+
const woqlObject = WOQL.evaluate('1+2', 'b');
195+
expect(woqlObject.json()).to.eql(woqlMathJson.evalJson);
196+
});
197+
198+
it('check the evaluate method (fluent style)', () => {
199+
// Test the reported bug: WOQL.limit(100).evaluate(...)
200+
const woqlObject = WOQL.limit(100).evaluate(WOQL.times(2, 3), 'v:result');
201+
const json = woqlObject.json();
202+
203+
// Should have Limit with nested query
204+
expect(json).to.have.property('@type', 'Limit');
205+
expect(json).to.have.property('limit', 100);
206+
expect(json).to.have.property('query');
207+
208+
// Nested query should be Eval
209+
expect(json.query).to.have.property('@type', 'Eval');
210+
expect(json.query).to.have.property('expression');
211+
expect(json.query.expression).to.have.property('@type', 'Times');
212+
});
213+
214+
it('check evaluate and eval produce identical results', () => {
215+
const withEval = WOQL.limit(10).eval(WOQL.plus(5, 3), 'x');
216+
const withEvaluate = WOQL.limit(10).evaluate(WOQL.plus(5, 3), 'x');
217+
218+
expect(withEval.json()).to.deep.eql(withEvaluate.json());
219+
});
220+
193221
it('check the minus method', () => {
194222
const woqlObject = WOQL.minus('2', '1');
195223
expect(woqlObject.json()).to.eql(woqlMathJson.minusJson);

0 commit comments

Comments
 (0)