Skip to content

Commit

Permalink
more complex circular references tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
bfontaine committed Feb 17, 2014
1 parent 01f7bca commit cf702ae
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion test/arraydb-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,51 @@ describe( 'ArrayDB objects', function() {
expect(a.query({ query: q }).length ).to.equal( 1 );
});

// TODO add more complex circular references
it( 'should handle deep circular references', function() {

var o = { foo: 42 },
q = { foo: 42 },
a;

o.bar = { foo: 42, bar: o };
q.bar = q;

a = new ArrayDB( o, { foo: 42 }, { foo: 43 } );

expect(a.query({ query: q }).length ).to.equal( 1 );
});

it( 'should not match a circular-referenced query '
+ 'with a non-circular-referenced object', function() {

var circ = { foo: 42 },
normal = { foo: 42, bar: { foo: 42, bar: { foo: 42 } } },
a;

circ.bar = circ;

a = new ArrayDB( normal, { foo: 56 }, null );

// as a pattern, `circ` doesn’t match `normal`
expect(a.query({ query: circ }).length ).to.equal( 0 );

});

it( 'should be able to match a non-circular-referenced query '
+ 'with a circular-referenced object', function() {

var circ = { foo: 42 },
normal = { foo: 42, bar: { foo: 42, bar: { foo: 42 } } },
a;

circ.bar = circ;

a = new ArrayDB( circ, { foo: 56 }, null );

// as a pattern, `normal` matches `circ`
expect(a.query({ query: normal }).length ).to.equal( 1 );

});

describe( 'in strict mode', function() {

Expand Down

0 comments on commit cf702ae

Please sign in to comment.