summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2023-11-27 08:04:24 -0500
committerJemma Issroff <jemmaissroff@gmail.com>2023-11-27 15:14:40 -0500
commit13b7cddc2b7fb224065677b9c0030898ebbeb21e (patch)
treefbd82b3b2aa76a99abf4a3de66da95ac5e84e0c4 /test/ruby
parent4d71f70fd1cd0e11d9698e52411cd55045044c34 (diff)
[PRISM] Compile IndexOrWriteNode
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_compile_prism.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb
index a01666ee54..96aad1ab5b 100644
--- a/test/ruby/test_compile_prism.rb
+++ b/test/ruby/test_compile_prism.rb
@@ -238,6 +238,27 @@ module Prism
assert_prism_eval("$pit = 1")
end
+ def test_IndexOrWriteNode
+ assert_prism_eval("[0][0] ||= 1")
+ assert_prism_eval("[nil][0] ||= 1")
+
+ # Testing `[]` with a block passed in
+ assert_prism_eval(<<-CODE)
+ class CustomHash < Hash
+ def []=(key, value, &block)
+ super(block.call(key), value)
+ end
+ end
+
+ hash = CustomHash.new
+
+ # Call the custom method with a block that modifies
+ # the key before assignment
+ hash["key", &(Proc.new { _1.upcase })] ||= "value"
+ hash
+ CODE
+ end
+
def test_InstanceVariableAndWriteNode
assert_prism_eval("@pit = 0; @pit &&= 1")
end