summaryrefslogtreecommitdiff
path: root/test/rdoc/test_rdoc_generator_pot_po_entry.rb
blob: 36b85df864fd5bca42b3f459faab6092851e64f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# frozen_string_literal: false
require 'rdoc/test_case'

class TestRDocGeneratorPOTPOEntry < RDoc::TestCase

  def test_msgid_normal
    assert_equal <<-'ENTRY', entry("Hello", {}).to_s
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_msgid_multiple_lines
    assert_equal <<-'ENTRY', entry("Hello\nWorld", {}).to_s
msgid ""
"Hello\n"
"World"
msgstr ""
    ENTRY
  end

  def test_msgid_tab
    assert_equal <<-'ENTRY', entry("Hello\tWorld", {}).to_s
msgid "Hello\tWorld"
msgstr ""
    ENTRY
  end

  def test_msgid_back_slash
    assert_equal <<-'ENTRY', entry("Hello \\ World", {}).to_s
msgid "Hello \\ World"
msgstr ""
    ENTRY
  end

  def test_msgid_double_quote
    assert_equal <<-'ENTRY', entry("Hello \"World\"!", {}).to_s
msgid "Hello \"World\"!"
msgstr ""
    ENTRY
  end

  def test_translator_comment_normal
    options = {:translator_comment => "Greeting"}
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
# Greeting
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_translator_comment_multiple_lines
    options = {:translator_comment => "Greeting\nfor morning"}
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
# Greeting
# for morning
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_extracted_comment_normal
    options = {:extracted_comment => "Object"}
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
#. Object
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_extracted_comment_multiple_lines
    options = {:extracted_comment => "Object\nMorning#greeting"}
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
#. Object
#. Morning#greeting
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_references_normal
    options = {:references => [["lib/rdoc.rb", 29]]}
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
#: lib/rdoc.rb:29
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_references_multiple
    options = {:references => [["lib/rdoc.rb", 29], ["lib/rdoc/i18n.rb", 9]]}
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
#: lib/rdoc.rb:29
#: lib/rdoc/i18n.rb:9
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_flags_normal
    options = {:flags => ["fuzzy"]}
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
#, fuzzy
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_flags_multiple
    options = {:flags => ["fuzzy", "ruby-format"]}
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
#, fuzzy,ruby-format
msgid "Hello"
msgstr ""
    ENTRY
  end

  def test_full
    options = {
      :translator_comment => "Greeting",
      :extracted_comment  => "Morning#greeting",
      :references         => [["lib/rdoc.rb", 29]],
      :flags              => ["fuzzy"],
    }
    assert_equal <<-'ENTRY', entry("Hello", options).to_s
# Greeting
#. Morning#greeting
#: lib/rdoc.rb:29
#, fuzzy
msgid "Hello"
msgstr ""
    ENTRY
  end

  private
  def entry(msgid, options)
    RDoc::Generator::POT::POEntry.new(msgid, options)
  end

end