From 019b35df2f14b6010ea8e65b4feca50633a9227a Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Mon, 21 Aug 2023 10:44:49 -0700 Subject: [PATCH] Add test for resource deictionary mutation --- .../interpreter/container_mutation_test.go | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/runtime/tests/interpreter/container_mutation_test.go b/runtime/tests/interpreter/container_mutation_test.go index a8708971bc..0b5b76799b 100644 --- a/runtime/tests/interpreter/container_mutation_test.go +++ b/runtime/tests/interpreter/container_mutation_test.go @@ -1132,6 +1132,34 @@ func TestInterpretContainerMutationWhileIterating(t *testing.T) { assert.True(t, present) assert.Equal(t, interpreter.NewUnmeteredStringValue("baz"), val) }) + + t.Run("resource dictionary, remove", func(t *testing.T) { + t.Parallel() + + inter := parseCheckAndInterpret(t, ` + resource Foo {} + + fun test(): @{String: Foo} { + let dictionary: @{String: Foo} <- {"a": <- create Foo(), "b": <- create Foo(), "c": <- create Foo()} + + var dictionaryRef = &dictionary as &{String: Foo} + + var i = 0 + dictionary.forEachKey(fun (key: String): Bool { + if i == 0 { + destroy dictionaryRef.remove(key: "b") + } + return true + }) + + return <- dictionary + } + `) + + _, err := inter.Invoke("test") + RequireError(t, err) + assert.ErrorAs(t, err, &interpreter.ContainerMutatedDuringIterationError{}) + }) } func TestInterpretInnerContainerMutationWhileIteratingOuter(t *testing.T) {