0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Few more tests

This commit is contained in:
Aaron 2009-03-23 18:55:32 -04:00
parent 7e86cd69f3
commit a6f3402e0d
2 changed files with 35 additions and 18 deletions

View File

@ -250,7 +250,7 @@ namespace mongo {
for ( vector<Mod>::const_iterator i = mods_.begin(); i != mods_.end(); ++i ) {
const Mod& m = *i;
BSONElement e = obj.getFieldDotted(m.fieldName);
uassert( "Cannot apply $inc modifier to non-number", m.op != Mod::INC || e.isNumber() );
uassert( "Cannot apply $inc modifier to non-number", m.op != Mod::INC || e.isNumber() || e.eoo() );
if ( e.isNumber() && m.elt.isNumber() )
continue;
if ( m.elt.valuesize() == e.valuesize() )
@ -373,6 +373,7 @@ namespace mongo {
++m;
++p;
} else if ( cmp < 0 ) {
// Here may be $inc or $set
b2.appendAs( m->elt, m->fieldName );
++m;
} else if ( cmp > 0 ) {
@ -382,20 +383,6 @@ namespace mongo {
}
b2.appendSelf( b );
//
// const Mod *mod = modForField( e.fieldName() );
// if ( !mod ) {
// b.append( e );
// } else if ( mod->op == Mod::INC ) {
// if ( e.type() == NumberInt )
// b.append( e.fieldName(), int( e.number() + mod->getn() ) );
// else
// b.append( e.fieldName(), double( e.number() + mod->getn() ) );
// mod->setn( e.number() );
// } else if ( mod->op == Mod::SET ) {
// b.appendAs( mod->elt, e.fieldName() );
// }
// }
return b.obj();
}

View File

@ -190,12 +190,39 @@ namespace UpdateTests {
class SetRecreateDotted : public SetBase {
public:
void run() {
client().insert( ns(), fromjson( "{a:{b:'cdef'}}" ) );
client().insert( ns(), fromjson( "{'_id':0,a:{b:'cdef'}}" ) );
client().update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
ASSERT( !client().findOne( ns(), BSON( "a.b" << "lllll" ) ).isEmpty() );
ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
}
};
class SetMissingDotted : public SetBase {
public:
void run() {
client().insert( ns(), fromjson( "{'_id':0}" ) );
client().update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll'}}" ) ) == 0 );
}
};
class SetAdjacentDotted : public SetBase {
public:
void run() {
client().insert( ns(), fromjson( "{'_id':0,a:{c:4}}" ) );
client().update( ns(), BSONObj(), BSON( "$set" << BSON( "a.b" << "lllll" ) ) );
ASSERT( client().findOne( ns(), BSON( "a.b" << "lllll" ) ).woCompare( fromjson( "{'_id':0,a:{b:'lllll',c:4}}" ) ) == 0 );
}
};
class IncMissing : public SetBase {
public:
void run() {
client().insert( ns(), fromjson( "{'_id':0}" ) );
client().update( ns(), BSONObj(), BSON( "$inc" << BSON( "f" << 3.0 ) ) );
ASSERT( client().findOne( ns(), Query() ).woCompare( fromjson( "{'_id':0,f:3}" ) ) == 0 );
}
};
class All : public UnitTest::Suite {
public:
All() {
@ -214,6 +241,9 @@ namespace UpdateTests {
add< ModDotted >();
add< SetInPlaceDotted >();
add< SetRecreateDotted >();
add< SetMissingDotted >();
add< SetAdjacentDotted >();
add< IncMissing >();
}
};