about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorDimid Duchovny <dimidd@gmail.com>2018-01-24 12:12:07 +0200
committerDimid Duchovny <dimidd@gmail.com>2018-01-24 12:12:07 +0200
commit3e38a4910e7a3c17c07f47c4f1b9d556a4a951fd (patch)
treec6131f5efeb99989ca4616a62307e91a728b4450
parent1c701717d10879d492d8b55fb8ca2f1c53d7e13f (diff)
downloadmsgthr-3e38a4910e7a3c17c07f47c4f1b9d556a4a951fd.tar.gz
Signed-off-by: Dimid Duchovny <dimidd@gmail.com>
-rw-r--r--test/test_msgthr.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/test_msgthr.rb b/test/test_msgthr.rb
index 0f31762..62b92d9 100644
--- a/test/test_msgthr.rb
+++ b/test/test_msgthr.rb
@@ -102,4 +102,46 @@ EOF
 EOF
     assert_equal exp, out
   end
+
+  def test_add_child_callback
+    thr = Msgthr.new
+    threads = {}
+    [1, 1.1, 1.2, 2, 2.1, 2.11].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