require 'contest' require 'ronn/document' class DocumentTest < Test::Unit::TestCase SIMPLE_FILE = "#{File.dirname(__FILE__)}/basic_document.ronn" test "new with path" do doc = Ronn::Document.new(SIMPLE_FILE) assert_equal File.read(SIMPLE_FILE), doc.data end test "new with path and block" do doc = Ronn::Document.new('hello.1.ronn') { "# hello(1) -- hello world" } assert_equal "# hello(1) -- hello world", doc.data end test "new with path and block but missing name section" do doc = Ronn::Document.new('foo.7.ronn') { '' } assert_equal 'foo', doc.name assert_equal '7', doc.section end test "new with non conventional path and missing name section" do doc = Ronn::Document.new('bar.ronn') { '' } assert_equal 'bar', doc.name assert_equal nil, doc.section assert_equal "./bar.html", doc.path_for('html') assert_equal "./bar", doc.path_for('roff') assert_equal "./bar", doc.path_for('') assert_equal "./bar", doc.path_for(nil) end test "new with path and name section mismatch" do doc = Ronn::Document.new('foo/rick.7.ronn') { "# randy(3) -- I'm confused." } assert_equal 'randy', doc.name assert_equal 'rick', doc.path_name assert_equal '3', doc.section assert_equal '7', doc.path_section assert_equal 'rick.7', doc.basename assert_equal 'foo/rick.7.bar', doc.path_for(:bar) end test "new with no path and a name section" do doc = Ronn::Document.new { "# brandy(5) -- wootderitis" } assert_equal nil, doc.path_name assert_equal nil, doc.path_section assert_equal 'brandy', doc.name assert_equal '5', doc.section assert_equal 'brandy.5', doc.basename assert_equal 'brandy.5.foo', doc.path_for(:foo) end 1.upto(5) do |i| dashes = '-' * i test "new with no path and #{i} dashes in name" do doc = Ronn::Document.new { "# brandy #{dashes} wootderitis" } assert_equal 'brandy', doc.name assert_equal nil, doc.section assert_equal 'wootderitis', doc.tagline end test "new with no path and a name section and #{i} dashes in name" do doc = Ronn::Document.new { "# brandy(5) #{dashes} wootderitis" } assert_equal 'brandy', doc.name assert_equal '5', doc.section assert_equal 'wootderitis', doc.tagline end end context "simple conventionally named document" do setup do @doc = Ronn::Document.new('hello.1.ronn') { "# hello(1) -- hello world" } end should "load data" do assert_equal "# hello(1) -- hello world", @doc.data end should "extract the manual page name from the filename or document" do assert_equal 'hello', @doc.name end should "extract the manual page section from the filename or document" do assert_equal '1', @doc.section end should "convert to an HTML fragment with no wrap div" do assert_equal %[
hello
- hello world
hello
- hello world
hello
- hello world