Skip to content

Commit

Permalink
Add test for resource deictionary mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Dec 1, 2023
1 parent fb14cbe commit 019b35d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions runtime/tests/interpreter/container_mutation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 019b35d

Please sign in to comment.