CloneContext: Fix CloneWithoutTransform()

Add tests

Change-Id: I39630336fc3e12ee9484783b5b374b9c3f5587ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47221
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-04-08 14:47:37 +00:00 committed by Commit Bot service account
parent 9328d94572
commit 586fca472d
2 changed files with 20 additions and 2 deletions

View File

@ -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<T>(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<T>(c);
}
/// Clones the Source `s` into `dst`

View File

@ -243,6 +243,24 @@ TEST(CloneContext, CloneWithReplaceAll_Symbols) {
EXPECT_EQ(cloned_root->b->b->name, cloned.Symbols().Get("transformed<b->b>"));
}
TEST(CloneContext, CloneWithoutTransform) {
ProgramBuilder builder;
auto* original_node =
builder.create<Node>(builder.Symbols().Register("root"));
Program original(std::move(builder));
ProgramBuilder cloned;
CloneContext ctx(&cloned, &original);
ctx.ReplaceAll([&](Node*) {
return cloned.create<Replacement>(
builder.Symbols().Register("<unexpected-node>"));
});
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 =