Skip to content

Commit

Permalink
more tests passing, _id in front
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed May 14, 2009
1 parent 2ada81b commit 3247006
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
20 changes: 10 additions & 10 deletions jstests/count.js
Expand Up @@ -3,21 +3,21 @@ t = db.jstests_count;
t.drop(); t.drop();
t.save( { i: 1 } ); t.save( { i: 1 } );
t.save( { i: 2 } ); t.save( { i: 2 } );
assert.eq( 1, t.find( { i: 1 } ).count() ); assert.eq( 1, t.find( { i: 1 } ).count(), "A" );
assert.eq( 1, t.count( { i: 1 } ) ); assert.eq( 1, t.count( { i: 1 } ) , "B" );
assert.eq( 2, t.find().count() ); assert.eq( 2, t.find().count() , "C" );
assert.eq( 2, t.find( undefined ).count() ); assert.eq( 2, t.find( undefined ).count() , "D" );
assert.eq( 2, t.find( null ).count() ); assert.eq( 2, t.find( null ).count() , "E" );
assert.eq( 2, t.count() ); assert.eq( 2, t.count() , "F" );


t.drop(); t.drop();
t.save( {a:true,b:false} ); t.save( {a:true,b:false} );
t.ensureIndex( {b:1,a:1} ); t.ensureIndex( {b:1,a:1} );
assert.eq( 1, t.find( {a:true,b:false} ).count() ); assert.eq( 1, t.find( {a:true,b:false} ).count() , "G" );
assert.eq( 1, t.find( {b:false,a:true} ).count() ); assert.eq( 1, t.find( {b:false,a:true} ).count() , "H" );


t.drop(); t.drop();
t.save( {a:true,b:false} ); t.save( {a:true,b:false} );
t.ensureIndex( {b:1,a:1,c:1} ); t.ensureIndex( {b:1,a:1,c:1} );
assert.eq( 1, t.find( {a:true,b:false} ).count() ); assert.eq( 1, t.find( {a:true,b:false} ).count() , "I" );
assert.eq( 1, t.find( {b:false,a:true} ).count() ); assert.eq( 1, t.find( {b:false,a:true} ).count() , "J" );
10 changes: 5 additions & 5 deletions jstests/objid1.js
Expand Up @@ -2,12 +2,12 @@ t = db.objid1;
t.drop(); t.drop();


b = new ObjectId(); b = new ObjectId();
assert( b.str , "objid1 test1" ); assert( b.str , "A" );


a = ObjectId( b.str ); a = new ObjectId( b.str );
assert.eq( a.str , b.str ); assert.eq( a.str , b.str , "B" );


t.save( { a : a } ) t.save( { a : a } )
assert( t.findOne().a.isObjectId ); assert( t.findOne().a.isObjectId , "C" );
assert.eq( a.str , t.findOne().a.str ); assert.eq( a.str , t.findOne().a.str , "D" );


2 changes: 1 addition & 1 deletion jstests/objid3.js
Expand Up @@ -3,7 +3,7 @@ t.drop();


t.save( { a : "bob" , _id : 517 } ); t.save( { a : "bob" , _id : 517 } );
for ( var k in t.findOne() ){ for ( var k in t.findOne() ){
assert.eq( k , "_id" ); assert.eq( k , "_id" , "keys out of order" );
break; break;
} }


7 changes: 7 additions & 0 deletions scripting/engine_spidermonkey.cpp
Expand Up @@ -109,6 +109,11 @@ namespace mongo {


BSONObjBuilder b; BSONObjBuilder b;


jsval theid = getProperty( o , "_id" );
if ( ! JSVAL_IS_VOID( theid ) ){
append( b , "_id" , theid );
}

JSIdArray * properties = JS_Enumerate( _context , o ); JSIdArray * properties = JS_Enumerate( _context , o );
assert( properties ); assert( properties );


Expand All @@ -117,6 +122,8 @@ namespace mongo {
jsval nameval; jsval nameval;
assert( JS_IdToValue( _context ,id , &nameval ) ); assert( JS_IdToValue( _context ,id , &nameval ) );
string name = toString( nameval ); string name = toString( nameval );
if ( name == "_id" )
continue;
append( b , name , getProperty( o , name.c_str() ) ); append( b , name , getProperty( o , name.c_str() ) );
} }


Expand Down

0 comments on commit 3247006

Please sign in to comment.