# Copyright (C) 2016 all contributors # License: GPL-2.0+ require 'test/unit' require 'msgthr' class TestMsgthr < Test::Unit::TestCase def test_msgthr thr = Msgthr.new thr.add('a', %w(c b), 'abc') thr.add('b', %w(c), 'B') 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) } assert_same rset, rootset assert_equal %w(D c missing), rootset.map(&:mid) assert_equal 'D', rootset[0].msg assert_equal %w(b), rootset[1].children.map(&:mid) out = ''.b thr.walk_thread do |level, container, index| msg = container.msg summary = msg ? msg : "[missing: <#{container.mid}>]" indent = ' ' * level out << sprintf("#{indent} % 3d. %s\n", index, summary) end exp = <] 0. d EOF assert_equal exp, out end def test_order_in_thread thr = Msgthr.new thr.add(1, nil, 'a') thr.add(2, [1], 'b') thr.thread! do |ary| ary.sort_by! do |cont| cur = cont.topmost cur ? cur : 0 end end out = '' thr.walk_thread do |level, container, index| msg = container.msg out << "#{level} [#{index}] #{msg}\n" end exp = <