aboutsummaryrefslogtreecommitdiffstats
path: root/test/rdoc/test_rdoc_i18n_text.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-05 01:41:25 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-09-05 01:41:25 +0000
commitd42d6e690e3f553b971322eae783ac6b0d4d9692 (patch)
tree2004bf4517ee7b81466c300cf30092e62e65467e /test/rdoc/test_rdoc_i18n_text.rb
parent670c6e8ce9d4a12bb4832e10fab27365398649bf (diff)
downloadruby-d42d6e690e3f553b971322eae783ac6b0d4d9692.tar.gz
* lib/rdoc.rb, lib/rdoc, test/rdoc: Update to RDoc 4.2.0.alpha(313287)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47391 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rdoc/test_rdoc_i18n_text.rb')
-rw-r--r--test/rdoc/test_rdoc_i18n_text.rb123
1 files changed, 123 insertions, 0 deletions
diff --git a/test/rdoc/test_rdoc_i18n_text.rb b/test/rdoc/test_rdoc_i18n_text.rb
new file mode 100644
index 0000000000..3168b57d95
--- /dev/null
+++ b/test/rdoc/test_rdoc_i18n_text.rb
@@ -0,0 +1,123 @@
+require 'rdoc/test_case'
+
+class TestRDocI18nText < RDoc::TestCase
+
+ def test_multiple_paragraphs
+ paragraph1 = <<-PARAGRAPH.strip
+RDoc produces HTML and command-line documentation for Ruby projects. RDoc
+includes the +rdoc+ and +ri+ tools for generating and displaying documentation
+from the command-line.
+ PARAGRAPH
+
+ paragraph2 = <<-PARAGRAPH.strip
+This command generates documentation for all the Ruby and C source
+files in and below the current directory. These will be stored in a
+documentation tree starting in the subdirectory +doc+.
+ PARAGRAPH
+
+ raw = <<-RAW
+#{paragraph1}
+
+#{paragraph2}
+ RAW
+
+ expected = [
+ {
+ :type => :paragraph,
+ :paragraph => paragraph1,
+ :line_no => 1,
+ },
+ {
+ :type => :paragraph,
+ :paragraph => paragraph2,
+ :line_no => 5,
+ },
+ ]
+ assert_equal expected, extract_messages(raw)
+ end
+
+ def test_translate_multiple_paragraphs
+ paragraph1 = <<-PARAGRAPH.strip
+Paragraph 1.
+ PARAGRAPH
+ paragraph2 = <<-PARAGRAPH.strip
+Paragraph 2.
+ PARAGRAPH
+
+ raw = <<-RAW
+#{paragraph1}
+
+#{paragraph2}
+ RAW
+
+ expected = <<-TRANSLATED
+Paragraphe 1.
+
+Paragraphe 2.
+ TRANSLATED
+ assert_equal expected, translate(raw)
+ end
+
+ def test_translate_not_transalted_message
+ nonexistent_paragraph = <<-PARAGRAPH.strip
+Nonexistent paragraph.
+ PARAGRAPH
+
+ raw = <<-RAW
+#{nonexistent_paragraph}
+ RAW
+
+ expected = <<-TRANSLATED
+#{nonexistent_paragraph}
+ TRANSLATED
+ assert_equal expected, translate(raw)
+ end
+
+ def test_translate_keep_empty_lines
+ raw = <<-RAW
+Paragraph 1.
+
+
+
+
+Paragraph 2.
+ RAW
+
+ expected = <<-TRANSLATED
+Paragraphe 1.
+
+
+
+
+Paragraphe 2.
+ TRANSLATED
+ assert_equal expected, translate(raw)
+ end
+
+ private
+
+ def extract_messages(raw)
+ text = RDoc::I18n::Text.new(raw)
+ messages = []
+ text.extract_messages do |message|
+ messages << message
+ end
+ messages
+ end
+
+ def locale
+ locale = RDoc::I18n::Locale.new('fr')
+ messages = locale.instance_variable_get(:@messages)
+ messages['markdown'] = 'markdown (markdown in fr)'
+ messages['Hello'] = 'Bonjour (Hello in fr)'
+ messages['Paragraph 1.'] = 'Paragraphe 1.'
+ messages['Paragraph 2.'] = 'Paragraphe 2.'
+ locale
+ end
+
+ def translate(raw)
+ text = RDoc::I18n::Text.new(raw)
+ text.translate(locale)
+ end
+
+end