diff options
| author | dearblue <[email protected]> | 2021-02-22 23:32:43 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2021-02-22 23:32:43 +0900 |
| commit | 927615e1f072d8fff3d9b84660cdce15a239e36c (patch) | |
| tree | 14e14aa860b778176435be8d6d666917d891a9d8 /mrbgems/mruby-binding-core/test | |
| parent | 792f6ac6700469ddf9be8f87ca3376082f9af7f3 (diff) | |
| download | mruby-927615e1f072d8fff3d9b84660cdce15a239e36c.tar.gz mruby-927615e1f072d8fff3d9b84660cdce15a239e36c.zip | |
Added other methods for `Binding`
- Added to `mruby-binding-core`
- `Binding#local_variable_defined?`
- `Binding#local_variable_get`
- `Binding#local_variable_set`
- `Binding#local_variables`
- `Binding#receiver`
- `Binding#source_location`
- `Binding#inspect`
- Added to `mruby-proc-binding`
- `Proc#binding`
The reason for separating `Proc#binding` is that core-mrbgems has a method that returns a closure object to minimize possible problems with being able to manipulate internal variables.
By separating it as different mrbgem, each user can judge this problem and incorporate it arbitrarily.
Diffstat (limited to 'mrbgems/mruby-binding-core/test')
| -rw-r--r-- | mrbgems/mruby-binding-core/test/binding-core.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/mrbgems/mruby-binding-core/test/binding-core.rb b/mrbgems/mruby-binding-core/test/binding-core.rb index d93f43619..066e79b18 100644 --- a/mrbgems/mruby-binding-core/test/binding-core.rb +++ b/mrbgems/mruby-binding-core/test/binding-core.rb @@ -9,3 +9,32 @@ assert("Binding#local_variables") do end assert_equal [:a, :b, :block], block.call(0).local_variables.sort end + +assert("Binding#local_variable_set") do + bind = binding + 1.times { + assert_equal(9, bind.local_variable_set(:x, 9)) + assert_raise(NameError) { x } + assert_equal([:bind, :x], bind.local_variables.sort) + } +end + +assert("Binding#local_variable_get") do + bind = binding + x = 1 + 1.times { + y = 2 + assert_equal(1, bind.local_variable_get(:x)) + x = 10 + assert_equal(10, bind.local_variable_get(:x)) + assert_raise(NameError) { bind.local_variable_get(:y) } + assert_equal([:bind, :x], bind.local_variables.sort) + } +end + +assert("Binding#source_location") do + skip unless -> {}.source_location + + bind, source_location = binding, [__FILE__, __LINE__] + assert_equal source_location, bind.source_location +end |
