diff options
| author | Jemma Issroff <jemmaissroff@gmail.com> | 2023-11-27 11:12:24 -0500 |
|---|---|---|
| committer | Jemma Issroff <jemmaissroff@gmail.com> | 2023-11-27 15:14:40 -0500 |
| commit | ec5eddf695e9bc3414c8628a6311ffb856fa7374 (patch) | |
| tree | cc45220c9253cbaa9ce405c54ec525ca5bfa2295 /test/ruby | |
| parent | 13b7cddc2b7fb224065677b9c0030898ebbeb21e (diff) | |
[PRISM] Compile IndexAndWriteNode
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_compile_prism.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 96aad1ab5b..2ee078673f 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -238,6 +238,28 @@ module Prism assert_prism_eval("$pit = 1") end + def test_IndexAndWriteNode + 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) + 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_IndexOrWriteNode assert_prism_eval("[0][0] ||= 1") assert_prism_eval("[nil][0] ||= 1") |
