| 1 |
# frozen_string_literal: false |
| 2 |
require 'test/unit' |
| 3 |
require "-test-/st/update" |
| 4 |
|
| 5 |
class Bug::StTable |
| 6 |
class Test_Update < Test::Unit::TestCase |
| 7 |
def setup |
| 8 |
@tbl = Bug::StTable.new |
| 9 |
@tbl[:a] = 1 |
| 10 |
@tbl[:b] = 2 |
| 11 |
end |
| 12 |
|
| 13 |
def test_notfound |
| 14 |
assert_equal(false, @tbl.st_update(:c) {42}) |
| 15 |
assert_equal({a: 1, b: 2, c: 42}, @tbl) |
| 16 |
end |
| 17 |
|
| 18 |
def test_continue |
| 19 |
args = nil |
| 20 |
assert_equal(true, @tbl.st_update(:a) {|*x| args = x; false}) |
| 21 |
assert_equal({a: 1, b: 2}, @tbl, :a) |
| 22 |
assert_equal([:a, 1], args) |
| 23 |
end |
| 24 |
|
| 25 |
def test_delete |
| 26 |
args = nil |
| 27 |
assert_equal(true, @tbl.st_update(:a) {|*x| args = x; nil}) |
| 28 |
assert_equal({b: 2}, @tbl, :a) |
| 29 |
assert_equal([:a, 1], args) |
| 30 |
end |
| 31 |
|
| 32 |
def test_update |
| 33 |
args = nil |
| 34 |
assert_equal(true, @tbl.st_update(:a) {|*x| args = x; 3}) |
| 35 |
assert_equal({a: 3, b: 2}, @tbl, :a) |
| 36 |
assert_equal([:a, 1], args) |
| 37 |
end |
| 38 |
|
| 39 |
def test_pass_objects_in_st_table |
| 40 |
bug7330 = '[ruby-core:49220]' |
| 41 |
key = "abc".freeze |
| 42 |
value = "def" |
| 43 |
@tbl[key] = value |
| 44 |
@tbl.st_update("abc") {|*args| |
| 45 |
assert_same(key, args[0], bug7330) |
| 46 |
assert_same(value, args[1], bug7330) |
| 47 |
nil |
| 48 |
} |
| 49 |
end |
| 50 |
end |
| 51 |
end |