diff options
author | Mathias Stearn <mathias@10gen.com> | 2012-12-06 12:20:54 -0500 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2012-12-10 18:54:05 -0500 |
commit | cb7bd2463a04d9e5716c55584b19d3d8acb8a6c4 (patch) | |
tree | f7207699921123dc6f88dbe696452e0420ce5354 /src/mongo/dbtests | |
parent | 459467c7cf47b57d8990eeb41c65b4e203e15b65 (diff) | |
download | mongo-cb7bd2463a04d9e5716c55584b19d3d8acb8a6c4.tar.gz |
Optimize ExpressionFieldPath and give better semantics
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r-- | src/mongo/dbtests/documentsourcetests.cpp | 9 | ||||
-rw-r--r-- | src/mongo/dbtests/expressiontests.cpp | 11 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp index e4dc5519f73..4ce3c9e2385 100644 --- a/src/mongo/dbtests/documentsourcetests.cpp +++ b/src/mongo/dbtests/documentsourcetests.cpp @@ -1389,11 +1389,14 @@ namespace DocumentSourceTests { } }; - /** A missing nested object within an array is not supported. */ - class MissingObjectWithinArray : public InvalidOperationBase { + /** A missing nested object within an array returns an empty array. */ + class MissingObjectWithinArray : public CheckResultsBase { void populateData() { client.insert( ns, BSON( "_id" << 0 << "a" << BSON_ARRAY( 1 ) ) ); - client.insert( ns, BSON( "_id" << 1 << "a" << BSON_ARRAY( 0 ) ) ); + client.insert( ns, BSON( "_id" << 1 << "a" << BSON_ARRAY( BSON("b" << 1) ) ) ); + } + string expectedResultSetString() { + return "[{_id:0,a:[1]},{_id:1,a:[{b:1}]}]"; } BSONObj sortSpec() { return BSON( "a.b" << 1 ); } }; diff --git a/src/mongo/dbtests/expressiontests.cpp b/src/mongo/dbtests/expressiontests.cpp index 9f7ad2c0305..f93d2fc391a 100644 --- a/src/mongo/dbtests/expressiontests.cpp +++ b/src/mongo/dbtests/expressiontests.cpp @@ -1068,7 +1068,7 @@ namespace ExpressionTests { public: void run() { intrusive_ptr<Expression> expression = ExpressionFieldPath::create( "a.b" ); - assertBinaryEqual( fromjson( "{'':[null]}" ), + assertBinaryEqual( fromjson( "{'':[]}" ), toBson( expression->evaluate ( fromBson( fromjson( "{a:[null]}" ) ) ) ) ); } @@ -1079,7 +1079,7 @@ namespace ExpressionTests { public: void run() { intrusive_ptr<Expression> expression = ExpressionFieldPath::create( "a.b" ); - assertBinaryEqual( fromjson( "{'':[undefined]}" ), + assertBinaryEqual( fromjson( "{'':[]}" ), toBson( expression->evaluate ( fromBson( fromjson( "{a:[undefined]}" ) ) ) ) ); } @@ -1090,8 +1090,9 @@ namespace ExpressionTests { public: void run() { intrusive_ptr<Expression> expression = ExpressionFieldPath::create( "a.b" ); - ASSERT_THROWS( expression->evaluate( fromBson( fromjson( "{a:[1]}" ) ) ), - UserException ); + assertBinaryEqual( fromjson( "{'':[]}" ), + toBson( expression->evaluate + ( fromBson( fromjson( "{a:[1]}" ) ) ) ) ); } }; @@ -1111,7 +1112,7 @@ namespace ExpressionTests { public: void run() { intrusive_ptr<Expression> expression = ExpressionFieldPath::create( "a.b" ); - assertBinaryEqual( fromjson( "{'':[9,null,undefined,20]}" ), + assertBinaryEqual( fromjson( "{'':[9,20]}" ), toBson( expression->evaluate ( fromBson( fromjson ( "{a:[{b:9},null,undefined,{g:4},{b:20},{}]}" |