Sha256: 4ec6780f184fe5f8a441e436d2b322174ccb576d787fec548e7ea22100eff320

Contents?: true

Size: 2 KB

Versions: 24

Compression:

Stored size: 2 KB

Contents

require 'test/unit'

require 'rd/tree'
require 'rd/element'
require 'rd/rd-struct'
require 'rd/loose-struct'

include RD

class TestTree < Test::Unit::TestCase
  def test_new_with_document_struct
    tr = Tree.new_with_document_struct(DocumentStructure::RD, ["test/data"])
    assert_equal(nil, tr.root)
    assert_equal(["test/data"], tr.include_paths)
  end

  def test_set_root
    tr = Tree.new_with_document_struct(DocumentStructure::RD)
    de = DocumentElement.new
    tr.set_root(de)
    assert_equal(de, tr.root)
    assert_equal(tr, de.tree)    
  end

  def test_each_element
    tr = Tree.new_with_document_struct(DocumentStructure::RD)
    de = DocumentElement.new
    tr.root = de
    exp = [de]
    i = 0
    tr.each_element do |b|
      assert_equal(exp[i], b)
    end
    
    tr_emp = Tree.new_with_document_struct(DocumentStructure::RD)
    assert_equal(nil, tr_emp.each_element)
  end

  def test_make_root
    tr = Tree.new_with_document_struct(DocumentStructure::RD)
    res = tr.make_root
    assert(tr.root)
    assert_equal(tr.root, res)
    
    tr2 = Tree.new_with_document_struct(DocumentStructure::RD)
    res2 = tr2.make_root do
      new TextBlock
    end
    assert(tr2.root)
    assert_equal("<RD::DocumentElement>\n  <RD::TextBlock>", tr2.root.inspect)
    assert_equal(tr2.root, res2)
  end

  def test_check_valid
    tr = Tree.new_with_document_struct(DocumentStructure::RD)
    de = DocumentElement.new
    tr.root = de
    de.build do
      new Headline, 1 do
        new StringElement, "label"
      end
      new TextBlock do
        new Emphasis do
          new StringElement, "emphasis"
        end
      end
    end
    assert_equal(true, tr.check_valid)

    tr_fail = Tree.new_with_document_struct(DocumentStructure::RD)
    de_fail = DocumentElement.new
    tr_fail.root = de_fail
    tb_fail = TextBlock.new
    tb_fail.build(DocumentStructure::LOOSE) do
      new Headline, 1
    end
    de_fail.add_child(tb_fail)
    assert_raises(RuntimeError) do
      tr_fail.check_valid
    end
  end
end

Version data entries

24 entries across 23 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/rdtool-0.6.38/test/test-tree.rb
tdiary-5.0.8 vendor/bundle/gems/rdtool-0.6.38/test/test-tree.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/rdtool-0.6.38/test/test-tree.rb
tdiary-5.0.5 vendor/bundle/gems/rdtool-0.6.38/test/test-tree.rb
tdiary-5.0.4 vendor/bundle/gems/rdtool-0.6.38/test/test-tree.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/rdtool-0.6.38/test/test-tree.rb
tdiary-3.2.2.20130518 vendor/rdtool-0.6.38/test/test-tree.rb
tdiary-3.2.2.20130508 vendor/rdtool-0.6.38/test/test-tree.rb
tdiary-3.2.2.20130507 vendor/rdtool-0.6.38/test/test-tree.rb
rdtool-0.6.38 test/test-tree.rb
rdtool-0.6.37 test/test-tree.rb
rdtool-0.6.36 test/test-tree.rb
rdtool-0.6.35 test/test-tree.rb
rdtool-0.6.34 test/test-tree.rb
rdtool-0.6.33 test/test-tree.rb
rdtool-0.6.32 test/test-tree.rb
rdtool-0.6.31 test/test-tree.rb
rdtool-0.6.30 test/test-tree.rb
rdtool-0.6.29 test/test-tree.rb
rdtool-0.6.28 test/test-tree.rb