diff options
author | George Wangensteen <george.wangensteen@10gen.com> | 2019-06-19 15:24:38 -0400 |
---|---|---|
committer | George Wangensteen <george.wangensteen@10gen.com> | 2019-06-28 16:01:59 -0400 |
commit | b651ed3dc6ae61332bb3193afef1cfa41bf5df53 (patch) | |
tree | d2fd427998d5ec995aeaa4faf8d13e597e745aa5 /src/mongo/db/pipeline/document_source_project_test.cpp | |
parent | abe43b7aaddd8254c51eb2c8bfce99b9e11f8fee (diff) | |
download | mongo-b651ed3dc6ae61332bb3193afef1cfa41bf5df53.tar.gz |
SERVER-41750 refactor renamed paths API.
Diffstat (limited to 'src/mongo/db/pipeline/document_source_project_test.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document_source_project_test.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/document_source_project_test.cpp b/src/mongo/db/pipeline/document_source_project_test.cpp index ad0eecfe573..34b04a1ce2e 100644 --- a/src/mongo/db/pipeline/document_source_project_test.cpp +++ b/src/mongo/db/pipeline/document_source_project_test.cpp @@ -41,6 +41,7 @@ #include "mongo/db/pipeline/document_source_mock.h" #include "mongo/db/pipeline/document_source_project.h" #include "mongo/db/pipeline/document_value_test_util.h" +#include "mongo/db/pipeline/semantic_analysis.h" #include "mongo/db/pipeline/value.h" #include "mongo/unittest/unittest.h" @@ -266,6 +267,29 @@ TEST_F(ProjectStageTest, CanUseRemoveSystemVariableToConditionallyExcludeProject ASSERT(project->getNext().isEOF()); } +TEST_F(ProjectStageTest, ProjectionCorrectlyReportsRenamesForwards) { + auto project = DocumentSourceProject::create(fromjson("{'renamedB' : '$b'}"), getExpCtx()); + auto renames = + semantic_analysis::renamedPaths({"b"}, *project, semantic_analysis::Direction::kForward); + // renamedPaths should return a mapping of old name->new name for each path in interestingPaths + // if the paths are all unmodified (but possibly renamed). Because path b is preserved, but + // renamed (to renamedB) we expect a renamedPaths to return a mapping from b->renamedB. + auto single_rename = renames->extract("b"); + ASSERT_FALSE(single_rename.empty()); + ASSERT_EQUALS(single_rename.mapped(), "renamedB"); + ASSERT_TRUE(renames->empty()); +} + +TEST_F(ProjectStageTest, ProjectionCorrectlyReportsRenamesBackwards) { + auto project = DocumentSourceProject::create(fromjson("{'renamedB' : '$b'}"), getExpCtx()); + auto renames = semantic_analysis::renamedPaths( + {"renamedB"}, *project, semantic_analysis::Direction::kBackward); + auto single_rename = renames->extract("renamedB"); + ASSERT_FALSE(single_rename.empty()); + ASSERT_EQUALS(single_rename.mapped(), "b"); + ASSERT_TRUE(renames->empty()); +} + /** * Creates BSON for a DocumentSourceProject that represents projecting a new computed field nested * 'depth' levels deep. |