class RSTBuidlerTest

Public Instance Methods

column_helper(review) click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 325
def column_helper(review)
  compile_block(review)
end
setup() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 11
def setup
  @builder = RSTBuilder.new()
  @config = ReVIEW::Configure.values
  @config.merge!({
                   "secnolevel" => 2,
                   "language" => "ja",
                 })
  @book = Book::Base.new(nil)
  @book.config = @config
  @compiler = ReVIEW::Compiler.new(@builder)
  @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
  location = Location.new(nil, nil)
  @builder.bind(@compiler, @chapter, location)

  @builder.instance_eval do
    # to ignore lineno in original method
    def warn(msg)
      puts msg
    end
  end
  I18n.setup(@config["language"])
end
test_block_raw0() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 295
def test_block_raw0
  actual = compile_block("//raw[<>!\"\\n& ]\n")
  expected = %Q(<>!\"\n& )
  assert_equal expected.chomp, actual
end
test_block_raw1() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 301
def test_block_raw1
  actual = compile_block("//raw[|top|<>!\"\\n& ]\n")
  expected = ''
  assert_equal expected.chomp, actual
end
test_block_raw2() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 307
def test_block_raw2
  actual = compile_block("//raw[|top, latex|<>!\"\\n& ]\n")
  expected = ''
  assert_equal expected.chomp, actual
end
test_block_raw3() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 313
def test_block_raw3
  actual = compile_block("//raw[|latex, idgxml|<>!\"\\n& ]\n")
  expected = ''
  assert_equal expected.chomp, actual
end
test_block_raw4() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 319
def test_block_raw4
  actual = compile_block("//raw[|top <>!\"\\n& ]\n")
  expected = %Q(|top <>!\"\n& )
  assert_equal expected.chomp, actual
end
test_column_ref() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 329
  def test_column_ref
    review =<<-EOS
===[column]{foo} test

inside column

=== next level

this is @<column>{foo}.
EOS
    expected =<<-EOS
.. column:: test

   inside column


next level
--------------------

this is test.

EOS

    assert_equal expected, column_helper(review)
  end
test_comment() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 172
def test_comment
  actual = compile_block("//comment[コメント]")
  assert_equal %Q|\n|, actual
end
test_comment_for_draft() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 177
def test_comment_for_draft
  @config["draft"] = true
  actual = compile_block("//comment[コメント]")
  assert_equal %Q|\n|, actual
end
test_emlistnum() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 199
def test_emlistnum
  actual = compile_block("//emlistnum[this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
  assert_equal %Q|this is @<b>{test}<&>_\n\n.. code-block:: none\n   :linenos:\n\n   foo\n   bar\n\n|, actual
end
test_flushright() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 162
def test_flushright
  actual = compile_block("//flushright{\nfoo\nbar\n\nbuz\n//}\n")
  assert_equal %Q|.. flushright::\n\n   foobar\nbuz\n\n|, actual
end
test_headline_level1() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 34
def test_headline_level1
  actual = compile_block("={test} this is test.\n")
  assert_equal %Q|.. _test:\n\n==========================\nthis is test.\n==========================\n\n|, actual
end
test_headline_level1_without_secno() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 39
def test_headline_level1_without_secno
  @config["secnolevel"] = 0
  actual = compile_block("={test} this is test.\n")
  assert_equal %Q|.. _test:\n\n==========================\nthis is test.\n==========================\n\n|, actual
end
test_headline_level2() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 45
def test_headline_level2
  actual = compile_block("=={test} this is test.\n")
  assert_equal %Q|.. _test:\n\nthis is test.\n==========================\n\n|, actual
end
test_headline_level3() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 50
def test_headline_level3
  actual = compile_block("==={test} this is test.\n")
  assert_equal %Q|.. _test:\n\nthis is test.\n--------------------------\n\n|, actual
end
test_headline_level3_with_secno() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 55
def test_headline_level3_with_secno
  @config["secnolevel"] = 3
  actual = compile_block("==={test} this is test.\n")
  assert_equal %Q|.. _test:\n\nthis is test.\n--------------------------\n\n|, actual
end
test_href() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 61
def test_href
  actual = compile_inline("@<href>{http://github.com, GitHub}")
  assert_equal %Q| `GitHub <http://github.com>`_ |, actual
end
test_href_without_label() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 66
def test_href_without_label
  actual = compile_inline("@<href>{http://github.com}")
  assert_equal %Q| `http://github.com <http://github.com>`_ |, actual
end
test_image() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 238
def test_image
  def @chapter.image(id)
    item = Book::ImageIndex::Item.new("sampleimg",1)
    item.instance_eval{@path="./images/chap1-sampleimg.png"}
    item
  end

  actual = compile_block("//image[sampleimg][sample photo]{\nfoo\n//}\n")
  assert_equal %Q|.. _sampleimg:\n\n.. figure:: images/-/sampleimg.png\n\n   sample photo\n\n|, actual
end
test_image_with_metric() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 249
def test_image_with_metric
  def @chapter.image(id)
    item = Book::ImageIndex::Item.new("sampleimg",1)
    item.instance_eval{@path="./images/chap1-sampleimg.png"}
    item
  end

  actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\nfoo\n//}\n")
  assert_equal %Q|.. _sampleimg:\n\n.. figure:: images/-/sampleimg.png\n   :scale:120.0%\n\n   sample photo\n\n|, actual
end
test_inline_b() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 106
def test_inline_b
  actual = compile_inline("test @<b>{inline test} test2")
  assert_equal %Q|test  **inline test**  test2|, actual
end
test_inline_b_and_escape() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 111
def test_inline_b_and_escape
  actual = compile_inline("test @<b>{inline<&;\\ test} test2")
  assert_equal %Q|test  **inline<&;\\ test**  test2|, actual
end
test_inline_br() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 91
def test_inline_br
  actual = compile_inline("@<br>{}")
  assert_equal %Q|\n|, actual
end
test_inline_comment() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 136
def test_inline_comment
  actual = compile_inline("test @<comment>{コメント} test2")
  assert_equal %Q|test  test2|, actual
end
test_inline_comment_for_draft() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 141
def test_inline_comment_for_draft
  @config["draft"] = true
  actual = compile_inline("test @<comment>{コメント} test2")
  assert_equal %Q|test コメント test2|, actual
end
test_inline_i() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 96
def test_inline_i
  actual = compile_inline("test @<i>{inline test} test2")
  assert_equal %Q|test  *inline test*  test2|, actual
end
test_inline_i_and_escape() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 101
def test_inline_i_and_escape
  actual = compile_inline("test @<i>{inline<&;\\ test} test2")
  assert_equal %Q|test  *inline<&;\\ test*  test2|, actual
end
test_inline_in_table() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 147
def test_inline_in_table
  actual = compile_block("//table{\n★1☆\t▲2☆\n------------\n★3☆\t▲4☆<>&\n//}\n")
  assert_equal %Q|   * - ★1☆\n     - ▲2☆\n   * - ★3☆\n     - ▲4☆<>&\n\n|, actual
end
test_inline_kw() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 81
def test_inline_kw
  actual = compile_inline("@<kw>{ISO, International Organization for Standardization } @<kw>{Ruby<>}")
  assert_equal %Q| **ISO(International Organization for Standardization)**   **Ruby<>** |, actual
end
test_inline_maru() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 86
def test_inline_maru
  actual = compile_inline("@<maru>{1}@<maru>{20}@<maru>{A}@<maru>{z}")
  assert_equal %Q| :maru:`1`  :maru:`20`  :maru:`A`  :maru:`z` |, actual
end
test_inline_raw() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 71
def test_inline_raw
  actual = compile_inline("@<raw>{@<tt>{inline\}}")
  assert_equal %Q|@<tt>{inline}|, actual
end
test_inline_raw0() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 271
def test_inline_raw0
  assert_equal "normal", compile_inline("@<raw>{normal}")
end
test_inline_raw1() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 275
def test_inline_raw1
  assert_equal "body", compile_inline("@<raw>{|top|body}")
end
test_inline_raw2() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 279
def test_inline_raw2
  assert_equal "body", compile_inline("@<raw>{|top, latex|body}")
end
test_inline_raw3() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 283
def test_inline_raw3
  assert_equal "body", compile_inline("@<raw>{|idgxml, html|body}")
end
test_inline_raw4() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 287
def test_inline_raw4
  assert_equal "|top body", compile_inline("@<raw>{|top body}")
end
test_inline_raw5() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 291
def test_inline_raw5
  assert_equal "nor\nmal", compile_inline("@<raw>{|top|nor\\nmal}")
end
test_inline_ruby() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 76
def test_inline_ruby
  actual = compile_inline("@<ruby>{coffin,bed}")
  assert_equal %Q| :ruby:`coffin`<bed>`_ |, actual
end
test_inline_tt() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 116
def test_inline_tt
  actual = compile_inline("test @<tt>{inline test} test2@<tt>{\\}}")
  assert_equal %Q|test  ``inline test``  test2 ``}`` |, actual
end
test_inline_ttb() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 126
def test_inline_ttb
  actual = compile_inline("test @<ttb>{inline test} test2")
  assert_equal %Q|test  ``inline test``  test2|, actual
end
test_inline_tti() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 121
def test_inline_tti
  actual = compile_inline("test @<tti>{inline test} test2")
  assert_equal %Q|test  ``inline test``  test2|, actual
end
test_inline_uchar() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 131
def test_inline_uchar
  actual = compile_inline("test @<uchar>{2460} test2")
  assert_equal %Q|test ① test2|, actual
end
test_list() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 183
def test_list
  def @chapter.list(id)
    Book::ListIndex::Item.new("test",1)
  end
  actual = compile_block("//list[samplelist][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
  assert_equal %Q|.. _samplelist:\n\n-foo\n-bar\n|, actual
end
test_listnum() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 191
def test_listnum
  def @chapter.list(id)
    Book::ListIndex::Item.new("test",1)
  end
  actual = compile_block("//listnum[test][this is @<b>{test}<&>_]{\nfoo\nbar\n//}\n")
  assert_equal %Q|.. _test:\n\n1\n2\n\n|, actual
end
test_major_blocks() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 204
def test_major_blocks
  actual = compile_block("//note{\nA\n\nB\n//}\n//note[caption]{\nA\n//}")
  expected = %Q(.. note::\n\n   A\nB\n\n.. note::\n\n   caption\n   A\n\n)
  assert_equal expected, actual

  actual = compile_block("//memo{\nA\n\nB\n//}\n//memo[caption]{\nA\n//}")
  expected = %Q(.. memo::\n\n   A\nB\n\n.. memo::\n\n   caption\n   A\n\n)
  assert_equal expected, actual

  actual = compile_block("//info{\nA\n\nB\n//}\n//info[caption]{\nA\n//}")
  expected = %Q(.. info::\n\n   A\nB\n\n.. info::\n\n   caption\n   A\n\n)
  assert_equal expected, actual

  actual = compile_block("//important{\nA\n\nB\n//}\n//important[caption]{\nA\n//}")
  expected = %Q(.. important::\n\n   A\nB\n\n.. important::\n\n   caption\n   A\n\n)
  assert_equal expected, actual

  actual = compile_block("//caution{\nA\n\nB\n//}\n//caution[caption]{\nA\n//}")
  expected = %Q(.. caution::\n\n   A\nB\n\n.. caution::\n\n   caption\n   A\n\n)
  assert_equal expected, actual

  actual = compile_block("//notice{\nA\n\nB\n//}\n//notice[caption]{\nA\n//}")
  expected = %Q(.. notice::\n\n   A\nB\n\n.. notice::\n\n   caption\n   A\n\n)
  assert_equal expected, actual

  actual = compile_block("//warning{\nA\n\nB\n//}\n//warning[caption]{\nA\n//}")
  expected = %Q(.. warning::\n\n   A\nB\n\n.. warning::\n\n   caption\n   A\n\n)
  assert_equal expected, actual

  actual = compile_block("//tip{\nA\n\nB\n//}\n//tip[caption]{\nA\n//}")
  expected = %Q(.. tip::\n\n   A\nB\n\n.. tip::\n\n   caption\n   A\n\n)
  assert_equal expected, actual
end
test_noindent() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 167
def test_noindent
  actual = compile_block("//noindent\nfoo\nbar\n\nfoo2\nbar2\n")
  assert_equal %Q|foobar\n\nfoo2bar2\n\n|, actual
end
test_paragraph() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 152
def test_paragraph
  actual = compile_block("foo\nbar\n")
  assert_equal %Q|foobar\n\n|, actual
end
test_tabbed_paragraph() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 157
def test_tabbed_paragraph
  actual = compile_block("\tfoo\nbar\n")
  assert_equal %Q|\tfoobar\n\n|, actual
end
test_texequation() click to toggle source
# File ../../../../../test/test_rstbuilder.rb, line 260
  def test_texequation
    actual = compile_block("//texequation{\n\\sin\n1^{2}\n//}\n")
    expected = <<-EOS
.. math::

   \\sin   1^{2}

EOS
    assert_equal expected, actual
  end
warn(msg) click to toggle source

to ignore lineno in original method

# File ../../../../../test/test_rstbuilder.rb, line 27
def warn(msg)
  puts msg
end