summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-11-27 12:48:51 -0500
committerJemma Issroff <jemmaissroff@gmail.com>2023-11-27 15:14:40 -0500
commitba26c6eae0c51dc07beb5b5c7c5651ef4589f351 (patch)
tree5fb86d470c9a0bda917f4852109403c80d6d8659 /test/ruby
parentec5eddf695e9bc3414c8628a6311ffb856fa7374 (diff)
[PRISM] Compile IndexOperatorWriteNode
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_compile_prism.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb
index 2ee078673f..78c62c3b67 100644
--- a/test/ruby/test_compile_prism.rb
+++ b/test/ruby/test_compile_prism.rb
@@ -281,6 +281,31 @@ module Prism
CODE
end
+ def test_IndexOperatorWriteNode
+ assert_prism_eval("[0][0] += 1")
+
+ # Testing `[]` with a block passed in
+ assert_prism_eval(<<-CODE)
+ class CustomHash < Hash
+ def [](key, &block)
+ block ? super(block.call(key)) : super(key)
+ end
+
+ def []=(key, value, &block)
+ block ? super(block.call(key), value) : super(key, value)
+ end
+ end
+
+ hash = CustomHash.new
+
+ # Call the custom method with a block that modifies
+ # the key before assignment
+ hash["KEY"] = "test"
+ hash["key", &(Proc.new { _1.upcase })] &&= "value"
+ hash
+ CODE
+ end
+
def test_InstanceVariableAndWriteNode
assert_prism_eval("@pit = 0; @pit &&= 1")
end