From 586fca472d804aad8e8e60125c78fa67086f66b6 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 8 Apr 2021 14:47:37 +0000 Subject: [PATCH] CloneContext: Fix CloneWithoutTransform() Add tests Change-Id: I39630336fc3e12ee9484783b5b374b9c3f5587ab Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47221 Commit-Queue: Ben Clayton Reviewed-by: Antonio Maiorano --- src/clone_context.h | 4 ++-- src/clone_context_test.cc | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/clone_context.h b/src/clone_context.h index 34e366b27c..e3d8b14884 100644 --- a/src/clone_context.h +++ b/src/clone_context.h @@ -124,14 +124,14 @@ class CloneContext { // version instead of making yet another copy. auto it = cloned_.find(a); if (it != cloned_.end()) { - return CheckedCast(it->second); + return CheckedCast(it->second); } // First time clone and no replacer transforms matched. // Clone with T::Clone(). auto* c = a->Clone(this); cloned_.emplace(a, c); - return CheckedCast(c); + return CheckedCast(c); } /// Clones the Source `s` into `dst` diff --git a/src/clone_context_test.cc b/src/clone_context_test.cc index 3b306805f8..5f8582e48b 100644 --- a/src/clone_context_test.cc +++ b/src/clone_context_test.cc @@ -243,6 +243,24 @@ TEST(CloneContext, CloneWithReplaceAll_Symbols) { EXPECT_EQ(cloned_root->b->b->name, cloned.Symbols().Get("transformedb>")); } +TEST(CloneContext, CloneWithoutTransform) { + ProgramBuilder builder; + auto* original_node = + builder.create(builder.Symbols().Register("root")); + Program original(std::move(builder)); + + ProgramBuilder cloned; + CloneContext ctx(&cloned, &original); + ctx.ReplaceAll([&](Node*) { + return cloned.create( + builder.Symbols().Register("")); + }); + + auto* cloned_node = ctx.CloneWithoutTransform(original_node); + EXPECT_NE(cloned_node, original_node); + EXPECT_EQ(cloned_node->name, cloned.Symbols().Get("root")); +} + TEST(CloneContext, CloneWithReplace) { ProgramBuilder builder; auto* original_root =