diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-02-25 21:15:24 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-02-25 21:15:24 +0900 |
| commit | 192f3df9a1fca043801e42febcd4b105fa1d5733 (patch) | |
| tree | 2e83f49a75fb581e522a7d388c5cc86f978cd1a7 /mrbgems/mruby-binding-core/test | |
| parent | f1c2096f8ed966cf055d1a32271748b5fad4ffe0 (diff) | |
| parent | 927615e1f072d8fff3d9b84660cdce15a239e36c (diff) | |
| download | mruby-192f3df9a1fca043801e42febcd4b105fa1d5733.tar.gz mruby-192f3df9a1fca043801e42febcd4b105fa1d5733.zip | |
Merge pull request #5362 from dearblue/binding
Binding
Diffstat (limited to 'mrbgems/mruby-binding-core/test')
| -rw-r--r-- | mrbgems/mruby-binding-core/test/binding-core.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/mrbgems/mruby-binding-core/test/binding-core.rb b/mrbgems/mruby-binding-core/test/binding-core.rb new file mode 100644 index 000000000..066e79b18 --- /dev/null +++ b/mrbgems/mruby-binding-core/test/binding-core.rb @@ -0,0 +1,40 @@ +assert("Kernel.#binding") do + assert_kind_of Binding, binding +end + +assert("Binding#local_variables") do + block = Proc.new do |a| + b = 1 + binding + 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 |
