diff options
author | Aaron <aaron@10gen.com> | 2011-06-02 11:00:53 -0400 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2011-06-02 11:00:53 -0400 |
commit | 69ea6ab82248388168c0f747bcb60e1c502f8b75 (patch) | |
tree | e23905b416a1bd9a181644c39640ea209cf19cd2 /jstests/andor.js | |
parent | c2f4f2c8da17af6f4699fe2e34d4405cf600bbea (diff) | |
download | mongo-69ea6ab82248388168c0f747bcb60e1c502f8b75.tar.gz |
SERVER-1089 tests for nested and/or cases
Diffstat (limited to 'jstests/andor.js')
-rw-r--r-- | jstests/andor.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/jstests/andor.js b/jstests/andor.js new file mode 100644 index 00000000000..7e87ffb749d --- /dev/null +++ b/jstests/andor.js @@ -0,0 +1,59 @@ +// SERVER-1089 Test and/or nesting + +t = db.jstests_andor; +t.drop(); + +// not ok +function ok( q ) { + assert.eq( 1, t.find( q ).itcount() ); +} + +// throws +function throws( q ) { + // count() will currently just return 0 rather than assert. + assert.throws( function() { t.find( q ).itcount(); } ); +} + +t.save( {a:1} ); + +function test() { + + ok( {a:1} ); + + ok( {$and:[{a:1}]} ); + ok( {$or:[{a:1}]} ); + + ok( {$and:[{$and:[{a:1}]}]} ); + throws( {$or:[{$or:[{a:1}]}]} ); + + ok( {$and:[{$or:[{a:1}]}]} ); + ok( {$or:[{$and:[{a:1}]}]} ); + + ok( {$and:[{$and:[{$or:[{a:1}]}]}]} ); + ok( {$and:[{$or:[{$and:[{a:1}]}]}]} ); + ok( {$or:[{$and:[{$and:[{a:1}]}]}]} ); + + throws( {$or:[{$and:[{$or:[{a:1}]}]}]} ); + + // now test $nor + + ok( {$and:[{a:1}]} ); + ok( {$nor:[{a:2}]} ); + + ok( {$and:[{$and:[{a:1}]}]} ); + throws( {$nor:[{$nor:[{a:1}]}]} ); + + ok( {$and:[{$nor:[{a:2}]}]} ); + ok( {$nor:[{$and:[{a:2}]}]} ); + + ok( {$and:[{$and:[{$nor:[{a:2}]}]}]} ); + ok( {$and:[{$nor:[{$and:[{a:2}]}]}]} ); + ok( {$nor:[{$and:[{$and:[{a:2}]}]}]} ); + + throws( {$nor:[{$and:[{$nor:[{a:1}]}]}]} ); + +} + +test(); +t.ensureIndex( {a:1} ); +test();
\ No newline at end of file |