test/test_msgthr.rb in msgthr-1.1.0 vs test/test_msgthr.rb in msgthr-1.2.0

- old
+ new

@@ -4,12 +4,19 @@ require 'msgthr' class TestMsgthr < Test::Unit::TestCase def test_msgthr thr = Msgthr.new + parent_child = '' + # Note that C is added after B, + # hence it's message will be empty after adding B + expected_parent_child = '->B' thr.add('a', %w(c b), 'abc') - thr.add('b', %w(c), 'B') + thr.add('b', %w(c), 'B') do |parent, child| + parent_child = "#{parent.msg}->#{child.msg}" + end + assert_equal parent_child, expected_parent_child thr.add('c', nil, 'c') thr.add('D', nil, 'D') thr.add('d', %w(missing), 'd') rset = thr.thread! rootset = thr.order! { |c| c.sort_by!(&:mid) } @@ -93,6 +100,48 @@ 0 [0] a 1 [0] b EOF assert_equal exp, out end + + def test_add_child_callback + thr = Msgthr.new + threads = {} + [1, 11, 12, 2, 21, 211].each{ |id| threads[id] = [id]} + my_add = lambda do |id, refs, msg| + thr.add(id, refs, msg) do |parent, child| + threads[child.mid] = threads[parent.mid] + end + end + # Create the following structure + # 1 + # \ + # | 1.1 + # \ + # 1.2 + # 2 + # \ + # 2.1 + # \ + # 2.1.1 + my_add.call(1, nil, '1') + my_add.call(11, [1], '1.1') + my_add.call(12, [1], '1.2') + my_add.call(2, nil, '2') + my_add.call(21, [2], '2.1') + my_add.call(211, [21], '2.1.1') + + thr.thread! + thr.rootset.each do |cnt| + threads[cnt.mid][0] = cnt.msg + end + + assert_equal threads[1], threads[11] + assert_equal threads[1], threads[12] + assert_equal threads[2], threads[21] + assert_equal threads[2], threads[211] + assert_equal threads[21], threads[211] + assert_equal threads[1][0], '1' + assert_equal threads[2][0], '2' + end + end