Skip to content

Commit acca902

Browse files
deepillamattbaileyuk
authored andcommitted
Move clone test cases to the JavaScript test suite.
1 parent 2a88ef8 commit acca902

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

test/implementation-tests.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,37 @@ describe("Functions with side-effects", () => {
179179
});
180180
});
181181

182-
describe("Tests that bind Javascript functions", () => {
182+
describe("Tests that use the $clone() function", () => {
183+
// $clone() allows jsonata-js to play nicely with Node-RED.
184+
// It's not part of the JSONata standard.
185+
// See https://github.com/jsonata-js/jsonata/issues/207.
186+
describe('clone undefined', function () {
187+
it('should return undefined', function () {
188+
var expr = jsonata('$clone(foo)');
189+
var result = expr.evaluate(testdata2);
190+
var expected = undefined;
191+
expect(result).to.deep.equal(expected);
192+
});
193+
});
194+
195+
describe('clone empty object', function () {
196+
it('should return empty object', function () {
197+
var expr = jsonata('$clone({})');
198+
var result = expr.evaluate(testdata2);
199+
var expected = {};
200+
expect(result).to.deep.equal(expected);
201+
});
202+
});
203+
204+
describe('clone object', function () {
205+
it('should return same object', function () {
206+
var expr = jsonata('$clone({"a": 1})');
207+
var result = expr.evaluate(testdata2);
208+
var expected = {"a": 1};
209+
expect(result).to.deep.equal(expected);
210+
});
211+
});
212+
183213
describe("transform expression with overridden $clone function", function() {
184214
it("should return result object", function() {
185215
var expr = jsonata('Account ~> |Order|{"Product":"blah"},nomatch|');
@@ -207,6 +237,19 @@ describe("Tests that bind Javascript functions", () => {
207237
});
208238
});
209239

240+
describe('transform expression with overridden $clone value', function () {
241+
it('should throw error', function () {
242+
var expr = jsonata('( $clone := 5; $ ~> |Account.Order.Product|{"blah":"foo"}| )');
243+
expect(function () {
244+
expr.evaluate(testdata2);
245+
})
246+
.to.throw()
247+
.to.deep.contain({ position: 21, code: 'T2013' });
248+
});
249+
});
250+
});
251+
252+
describe("Tests that bind Javascript functions", () => {
210253
// These involve binding of functions
211254
describe("Override implementation of $now()", function() {
212255
it("should return result object", function() {

test/test-suite/groups/function-clone/case000.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/test-suite/groups/function-clone/case001.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/test-suite/groups/function-clone/case002.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/test-suite/groups/transforms/case012.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)