From 796226a218a46057579740527dc3e81acca04774 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 15:01:22 +0000 Subject: [PATCH 1/2] Initial plan From a4f772cba03754aef405e02fa3df74df6cf67c0e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Jan 2026 15:05:13 +0000 Subject: [PATCH 2/2] Add comprehensive unit tests for add function covering all branches Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com> --- test/functions/functions-binary-ops.ts | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/functions/functions-binary-ops.ts b/test/functions/functions-binary-ops.ts index 53d47a51..12aaa5a5 100644 --- a/test/functions/functions-binary-ops.ts +++ b/test/functions/functions-binary-ops.ts @@ -16,6 +16,52 @@ describe('Binary Operators TypeScript Test', function () { assert.strictEqual(parser.evaluate('2 + undefined'), undefined); assert.strictEqual(parser.evaluate('undefined + 2'), undefined); }); + it('should concatenate non-numeric strings', function () { + const parser = new Parser(); + assert.strictEqual(parser.evaluate('"hello" + "world"'), 'helloworld'); + assert.strictEqual(parser.evaluate('"foo" + "bar"'), 'foobar'); + assert.strictEqual(parser.evaluate('"test" + "123"'), 'test123'); + }); + it('should add numeric strings as numbers', function () { + const parser = new Parser(); + assert.strictEqual(parser.evaluate('"5" + "3"'), 8); + assert.strictEqual(parser.evaluate('"10" + "20"'), 30); + assert.strictEqual(parser.evaluate('"0" + "5"'), 5); + }); + it('should concatenate arrays', function () { + const parser = new Parser(); + assert.deepStrictEqual(parser.evaluate('[1, 2] + [3, 4]'), [1, 2, 3, 4]); + assert.deepStrictEqual(parser.evaluate('[1] + [2, 3]'), [1, 2, 3]); + assert.deepStrictEqual(parser.evaluate('[] + [1, 2]'), [1, 2]); + }); + it('should merge objects', function () { + const parser = new Parser(); + assert.deepStrictEqual(parser.evaluate('{a: 1} + {b: 2}'), { a: 1, b: 2 }); + assert.deepStrictEqual(parser.evaluate('{x: 10} + {y: 20}'), { x: 10, y: 20 }); + assert.deepStrictEqual(parser.evaluate('{a: 1, b: 2} + {c: 3}'), { a: 1, b: 2, c: 3 }); + }); + it('should handle object merging with overlapping keys', function () { + const parser = new Parser(); + assert.deepStrictEqual(parser.evaluate('{a: 1} + {a: 2}'), { a: 2 }); + assert.deepStrictEqual(parser.evaluate('{x: 10, y: 20} + {y: 30}'), { x: 10, y: 30 }); + }); + it('should handle null values correctly', function () { + const parser = new Parser(); + assert.deepStrictEqual(parser.evaluate('null + null'), {}); + }); + it('should convert numeric values to numbers before adding', function () { + const parser = new Parser(); + assert.strictEqual(parser.evaluate('true + 1'), 2); + assert.strictEqual(parser.evaluate('false + 5'), 5); + assert.strictEqual(parser.evaluate('1 + true'), 2); + }); + it('should throw error for incompatible types', function () { + const parser = new Parser(); + assert.throws(() => parser.evaluate('5 + [1, 2]'), /Cannot add values of incompatible types/); + assert.throws(() => parser.evaluate('"text" + {a: 1}'), /Cannot add values of incompatible types/); + assert.throws(() => parser.evaluate('[1, 2] + {a: 1}'), /Cannot add values of incompatible types/); + assert.throws(() => parser.evaluate('5 + {x: 1}'), /Cannot add values of incompatible types/); + }); }); describe('- (subtraction)', function () {