gettext 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,6 +35,16 @@ end
35
35
  class @@anon::AC1; end
36
36
  module @@anon::AM1; end
37
37
 
38
+ module TestClassInfoSandbox
39
+ class << self
40
+ def clear
41
+ constants.each do |name|
42
+ remove_const(name)
43
+ end
44
+ end
45
+ end
46
+ end
47
+
38
48
  class TestClassInfo < Test::Unit::TestCase
39
49
  include GetText::ClassInfo
40
50
 
@@ -70,7 +80,7 @@ class TestClassInfo < Test::Unit::TestCase
70
80
  =end
71
81
  end
72
82
 
73
- def test_rellated_classes_with_all_classes
83
+ def test_related_classes_with_all_classes
74
84
  assert_equal [M1, Object], related_classes(M1, [M1])
75
85
  assert_equal [M1, Object], related_classes(M1::M3::M4, [M1])
76
86
  assert_equal [M1::M3, Object], related_classes(M1::M3::M4, [M1::M3])
@@ -84,4 +94,35 @@ class TestClassInfo < Test::Unit::TestCase
84
94
  def test_ruby19
85
95
  assert_equal Object, GetText::ClassInfo.normalize_class(Module.new)
86
96
  end
97
+
98
+ sub_test_case "related_classes" do
99
+ def setup
100
+ unless Module.respond_to?(:prepend, true)
101
+ omit("Module#prepend is required")
102
+ end
103
+
104
+ TestClassInfoSandbox.module_eval(<<-SOURCE)
105
+ module Prepended
106
+ end
107
+
108
+ class Base
109
+ prepend Prepended
110
+ end
111
+ SOURCE
112
+ end
113
+
114
+ def teardown
115
+ TestClassInfoSandbox.clear
116
+ end
117
+
118
+ def test_prepend
119
+ assert_equal([
120
+ TestClassInfoSandbox::Base,
121
+ TestClassInfoSandbox,
122
+ TestClassInfoSandbox::Prepended,
123
+ Object,
124
+ ],
125
+ related_classes(TestClassInfoSandbox::Base))
126
+ end
127
+ end
87
128
  end
data/test/test_po.rb CHANGED
@@ -257,7 +257,25 @@ msgstr ""
257
257
  PO
258
258
  end
259
259
 
260
+ def test_reference
261
+ @po.order = :reference
262
+ assert_equal(<<-PO, @po.to_s)
263
+ #: hello.rb:1
264
+ msgid "Hello"
265
+ msgstr ""
266
+
267
+ #: hello.rb:2
268
+ msgid "World"
269
+ msgstr ""
270
+
271
+ #: hello.rb:3
272
+ msgid "Hello World"
273
+ msgstr ""
274
+ PO
275
+ end
276
+
260
277
  def test_references
278
+ raise "Remove :references support!" if GetText::VERSION >= "4.0.0"
261
279
  @po.order = :references
262
280
  assert_equal(<<-PO, @po.to_s)
263
281
  #: hello.rb:1
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
4
- # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2012-2014 Kouhei Sutou <kou@clear-code.com>
5
5
  # Copyright (C) 2010 masone (Christian Felder) <ema@rh-productions.ch>
6
6
  # Copyright (C) 2009 Masao Mutoh
7
7
  #
@@ -375,6 +375,52 @@ EOP
375
375
  end
376
376
 
377
377
  class TestOptions < self
378
+ class TestIncludeTranslatorComment < self
379
+ def setup
380
+ @entry = GetText::POEntry.new(:normal)
381
+ @entry.msgid = "hello"
382
+ @entry.translator_comment = "translator comment"
383
+ end
384
+
385
+ def test_default
386
+ assert_equal(<<-PO, @entry.to_s)
387
+ # translator comment
388
+ msgid "hello"
389
+ msgstr ""
390
+ PO
391
+ end
392
+
393
+ def test_false
394
+ assert_equal(<<-PO, @entry.to_s(:include_translator_comment => false))
395
+ msgid "hello"
396
+ msgstr ""
397
+ PO
398
+ end
399
+ end
400
+
401
+ class TestIncludeExtractedComment < self
402
+ def setup
403
+ @entry = GetText::POEntry.new(:normal)
404
+ @entry.msgid = "hello"
405
+ @entry.extracted_comment = "extracted comment"
406
+ end
407
+
408
+ def test_default
409
+ assert_equal(<<-PO, @entry.to_s)
410
+ #. extracted comment
411
+ msgid "hello"
412
+ msgstr ""
413
+ PO
414
+ end
415
+
416
+ def test_false
417
+ assert_equal(<<-PO, @entry.to_s(:include_extracted_comment => false))
418
+ msgid "hello"
419
+ msgstr ""
420
+ PO
421
+ end
422
+ end
423
+
378
424
  class TestIncludeReferenceComment < self
379
425
  def setup
380
426
  @entry = GetText::POEntry.new(:normal)
@@ -398,6 +444,95 @@ msgstr ""
398
444
  end
399
445
  end
400
446
 
447
+ class TestIncludeFlagComment < self
448
+ def setup
449
+ @entry = GetText::POEntry.new(:normal)
450
+ @entry.msgid = "hello"
451
+ @entry.flag = "fuzzy"
452
+ end
453
+
454
+ def test_default
455
+ assert_equal(<<-PO, @entry.to_s)
456
+ #, fuzzy
457
+ msgid "hello"
458
+ msgstr ""
459
+ PO
460
+ end
461
+
462
+ def test_false
463
+ assert_equal(<<-PO, @entry.to_s(:include_flag_comment => false))
464
+ msgid "hello"
465
+ msgstr ""
466
+ PO
467
+ end
468
+ end
469
+
470
+ class TestIncludePreviousComment < self
471
+ def setup
472
+ @entry = GetText::POEntry.new(:normal)
473
+ @entry.msgid = "hello"
474
+ @entry.previous = "msgid \"Hello\""
475
+ end
476
+
477
+ def test_default
478
+ assert_equal(<<-PO, @entry.to_s)
479
+ #| msgid "Hello"
480
+ msgid "hello"
481
+ msgstr ""
482
+ PO
483
+ end
484
+
485
+ def test_false
486
+ assert_equal(<<-PO, @entry.to_s(:include_previous_comment => false))
487
+ msgid "hello"
488
+ msgstr ""
489
+ PO
490
+ end
491
+ end
492
+
493
+ class TestIncludeAllComments < self
494
+ def setup
495
+ @entry = GetText::POEntry.new(:normal)
496
+ @entry.msgid = "hello"
497
+ @entry.translator_comment = "translator comment"
498
+ @entry.extracted_comment = "extracted comment"
499
+ @entry.references = ["hello.rb:1"]
500
+ @entry.flag = "fuzzy"
501
+ @entry.previous = "msgid \"Hello\""
502
+ end
503
+
504
+ def test_default
505
+ assert_equal(<<-PO, @entry.to_s)
506
+ # translator comment
507
+ #. extracted comment
508
+ #: hello.rb:1
509
+ #, fuzzy
510
+ #| msgid "Hello"
511
+ msgid "hello"
512
+ msgstr ""
513
+ PO
514
+ end
515
+
516
+ def test_false
517
+ assert_equal(<<-PO, @entry.to_s(:include_all_comments => false))
518
+ msgid "hello"
519
+ msgstr ""
520
+ PO
521
+ end
522
+
523
+ def test_false_with_other_include
524
+ options = {
525
+ :include_reference_comment => true,
526
+ :include_all_comments => false,
527
+ }
528
+ assert_equal(<<-PO, @entry.to_s(options))
529
+ #: hello.rb:1
530
+ msgid "hello"
531
+ msgstr ""
532
+ PO
533
+ end
534
+ end
535
+
401
536
  class TestEncoding < self
402
537
  def setup
403
538
  @entry = GetText::POEntry.new(:normal)
@@ -473,6 +608,19 @@ msgstr ""
473
608
  assert_false(entry.obsolete?)
474
609
  end
475
610
  end
611
+
612
+ class TestFuzzy < self
613
+ def test_fuzzy_flag
614
+ entry = GetText::POEntry.new(:normal)
615
+ entry.flag = "fuzzy"
616
+ assert_true(entry.fuzzy?)
617
+ end
618
+
619
+ def test_no_fuzzy_flag
620
+ entry = GetText::POEntry.new(:normal)
621
+ assert_false(entry.fuzzy?)
622
+ end
623
+ end
476
624
  end
477
625
 
478
626
  class TestFormatter < self
@@ -518,29 +666,37 @@ msgstr ""
518
666
  assert_equal(expected_message, format_message(message))
519
667
  end
520
668
 
669
+ def test_one_line_with_newline
670
+ message = "line\n"
671
+ assert_equal(<<-FORMATTED_MESSAGE, format_message(message))
672
+ ""
673
+ "line\\n"
674
+ FORMATTED_MESSAGE
675
+ end
676
+
521
677
  def test_wrap
522
- message = "long line\n"
678
+ message = "long line"
523
679
  assert_equal(<<-MESSAGE, format_message(message, :max_line_width => 4))
524
680
  ""
525
681
  "long"
526
682
  " lin"
527
- "e\\n"
683
+ "e"
528
684
  MESSAGE
529
685
  end
530
686
 
531
687
  def test_disable_wrap
532
- message = "long line\n"
688
+ message = "long line"
533
689
  assert_equal(<<-MESSAGE, format_message(message, :max_line_width => 0))
534
- "long line\\n"
690
+ "long line"
535
691
  MESSAGE
536
692
  end
537
693
 
538
694
  def test_multilines_disable_wrap
539
- message = "long\nline\n"
695
+ message = "long\nline"
540
696
  assert_equal(<<-MESSAGE, format_message(message, :max_line_width => 0))
541
697
  ""
542
698
  "long\\n"
543
- "line\\n"
699
+ "line"
544
700
  MESSAGE
545
701
  end
546
702
 
@@ -0,0 +1,397 @@
1
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # License: Ruby's or LGPL
4
+ #
5
+ # This library is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ require "stringio"
19
+ require "tempfile"
20
+
21
+ require "gettext/tools/msgcat"
22
+
23
+ class TestToolsMsgCat < Test::Unit::TestCase
24
+ private
25
+ def run_msgcat(input_pos, *options)
26
+ inputs = input_pos.collect do |po|
27
+ input = Tempfile.new("msgcat-input")
28
+ input.write(po)
29
+ input.close
30
+ input
31
+ end
32
+ output = Tempfile.new("msgcat-output")
33
+ command_line = ["--output", output.path]
34
+ command_line.concat(options)
35
+ command_line.concat(inputs.collect(&:path))
36
+ @stdout, @stderr = capture_output do
37
+ GetText::Tools::MsgCat.run(*command_line)
38
+ end
39
+ output.read
40
+ end
41
+
42
+ def capture_output
43
+ original_stdout = $stdout
44
+ original_stderr = $stderr
45
+ begin
46
+ stdout = StringIO.new
47
+ stderr = StringIO.new
48
+ $stdout = stdout
49
+ $stderr = stderr
50
+ yield
51
+ [stdout.string, stderr.string]
52
+ ensure
53
+ $stdout = original_stdout
54
+ $stderr = original_stderr
55
+ end
56
+ end
57
+
58
+ class TestHeader < self
59
+ def setup
60
+ @po1 = <<-PO
61
+ msgid ""
62
+ msgstr ""
63
+ "Project-Id-Version: gettext 3.0.0\\n"
64
+ PO
65
+ @po2 = <<-PO
66
+ msgid ""
67
+ msgstr ""
68
+ "Language: ja\\n"
69
+ PO
70
+ end
71
+
72
+ def test_default
73
+ assert_equal(@po1, run_msgcat([@po1, @po2]))
74
+ end
75
+ end
76
+
77
+ class TestNoDuplicated < self
78
+ class TestTranslated < self
79
+ def setup
80
+ @po1 = <<-PO
81
+ msgid "Hello"
82
+ msgstr "Bonjour"
83
+ PO
84
+
85
+ @po2 = <<-PO
86
+ msgid "World"
87
+ msgstr "Monde"
88
+ PO
89
+ end
90
+
91
+ def test_default
92
+ assert_equal(<<-PO.chomp, run_msgcat([@po1, @po2]))
93
+ #{@po1}
94
+ #{@po2}
95
+ PO
96
+ end
97
+ end
98
+ end
99
+
100
+ class TestDuplicated < self
101
+ class TestTranslated < self
102
+ class TestSame < self
103
+ def setup
104
+ @po = <<-PO
105
+ msgid "Hello"
106
+ msgstr "Bonjour"
107
+ PO
108
+ end
109
+
110
+ def test_default
111
+ assert_equal(@po, run_msgcat([@po, @po]))
112
+ end
113
+ end
114
+
115
+ class TestDifferent < self
116
+ def setup
117
+ @po1 = <<-PO
118
+ msgid "Hello"
119
+ msgstr "Bonjour"
120
+ PO
121
+
122
+ @po2 = <<-PO
123
+ msgid "Hello"
124
+ msgstr "Salut"
125
+ PO
126
+ end
127
+
128
+ def test_default
129
+ assert_equal(@po1, run_msgcat([@po1, @po2]))
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ class TestSort < self
136
+ class TestByMsgid < self
137
+ def setup
138
+ @po_alice = <<-PO
139
+ msgid "Alice"
140
+ msgstr ""
141
+ PO
142
+
143
+ @po_bob = <<-PO
144
+ msgid "Bob"
145
+ msgstr ""
146
+ PO
147
+
148
+ @po_charlie = <<-PO
149
+ msgid "Charlie"
150
+ msgstr ""
151
+ PO
152
+ end
153
+
154
+ def test_sort_by_msgid
155
+ sorted_po = <<-PO.chomp
156
+ #{@po_alice}
157
+ #{@po_bob}
158
+ #{@po_charlie}
159
+ PO
160
+ assert_equal(sorted_po,
161
+ run_msgcat([@po_charlie, @po_bob, @po_alice],
162
+ "--sort-by-msgid"))
163
+ end
164
+
165
+ def test_sort_output
166
+ sorted_po = <<-PO.chomp
167
+ #{@po_alice}
168
+ #{@po_bob}
169
+ #{@po_charlie}
170
+ PO
171
+ assert_equal(sorted_po,
172
+ run_msgcat([@po_charlie, @po_bob, @po_alice],
173
+ "--sort-output"))
174
+ end
175
+
176
+ def test_no_sort_output
177
+ not_sorted_po = <<-PO.chomp
178
+ #{@po_charlie}
179
+ #{@po_bob}
180
+ #{@po_alice}
181
+ PO
182
+ assert_equal(not_sorted_po,
183
+ run_msgcat([@po_charlie, @po_bob, @po_alice],
184
+ "--no-sort-output"))
185
+ end
186
+ end
187
+
188
+ class TestByReference < self
189
+ def setup
190
+ @po_a1 = <<-PO
191
+ #: a.rb:1
192
+ msgid "Hello 3"
193
+ msgstr ""
194
+ PO
195
+
196
+ @po_a2 = <<-PO
197
+ #: a.rb:2
198
+ msgid "Hello 2"
199
+ msgstr ""
200
+ PO
201
+
202
+ @po_b1 = <<-PO
203
+ #: b.rb:1
204
+ msgid "Hello 1"
205
+ msgstr ""
206
+ PO
207
+ end
208
+
209
+ def test_sort_by_location
210
+ sorted_po = <<-PO.chomp
211
+ #{@po_a1}
212
+ #{@po_a2}
213
+ #{@po_b1}
214
+ PO
215
+ assert_equal(sorted_po,
216
+ run_msgcat([@po_b1, @po_a2, @po_a1],
217
+ "--sort-by-location"))
218
+ end
219
+
220
+ def test_sort_by_file
221
+ sorted_po = <<-PO.chomp
222
+ #{@po_a1}
223
+ #{@po_a2}
224
+ #{@po_b1}
225
+ PO
226
+ assert_equal(sorted_po,
227
+ run_msgcat([@po_b1, @po_a2, @po_a1],
228
+ "--sort-by-file"))
229
+ end
230
+ end
231
+ end
232
+
233
+ class TestComment < self
234
+ class TestReference < self
235
+ def setup
236
+ @po = <<-PO
237
+ # translator comment
238
+ #: a.rb:1
239
+ msgid "Hello"
240
+ msgstr ""
241
+ PO
242
+ end
243
+
244
+ def test_no_location
245
+ assert_equal(<<-PO, run_msgcat([@po], "--no-location"))
246
+ # translator comment
247
+ msgid "Hello"
248
+ msgstr ""
249
+ PO
250
+ end
251
+ end
252
+
253
+ class TestAll < self
254
+ def setup
255
+ @po = <<-PO
256
+ # translator comment
257
+ #. extracted comment
258
+ #: hello.rb:1
259
+ #, c-format
260
+ #| msgid "Hello"
261
+ msgid "Hello"
262
+ msgstr ""
263
+ PO
264
+ end
265
+
266
+ def test_no_all_comments
267
+ assert_equal(<<-PO, run_msgcat([@po], "--no-all-comments"))
268
+ msgid "Hello"
269
+ msgstr ""
270
+ PO
271
+ end
272
+ end
273
+ end
274
+
275
+ class TestWidth < self
276
+ def setup
277
+ @po = <<-PO
278
+ msgid "long long long long long long long long long long long long long long long line"
279
+ msgstr ""
280
+ PO
281
+ end
282
+
283
+ def test_default
284
+ assert_equal(<<-PO, run_msgcat([@po]))
285
+ msgid ""
286
+ "long long long long long long long long long long long long long long long lin"
287
+ "e"
288
+ msgstr ""
289
+ PO
290
+ end
291
+
292
+ def test_width
293
+ assert_equal(<<-PO, run_msgcat([@po], "--width=40"))
294
+ msgid ""
295
+ "long long long long long long long long "
296
+ "long long long long long long long line"
297
+ msgstr ""
298
+ PO
299
+ end
300
+
301
+
302
+ def test_wrap
303
+ assert_equal(<<-PO, run_msgcat([@po], "--wrap"))
304
+ msgid ""
305
+ "long long long long long long long long long long long long long long long lin"
306
+ "e"
307
+ msgstr ""
308
+ PO
309
+ end
310
+
311
+ def test_no_wrap
312
+ assert_equal(<<-PO, run_msgcat([@po], "--no-wrap"))
313
+ msgid "long long long long long long long long long long long long long long long line"
314
+ msgstr ""
315
+ PO
316
+ end
317
+ end
318
+
319
+ class TestFuzzy < self
320
+ class TestAllFuzzy < self
321
+ def setup
322
+ @po_fuzzy1 = <<-PO
323
+ #, fuzzy
324
+ msgid "Hello"
325
+ msgstr "Bonjour1"
326
+ PO
327
+
328
+ @po_fuzzy2 = <<-PO
329
+ #, fuzzy
330
+ msgid "Hello"
331
+ msgstr "Bonjour2"
332
+ PO
333
+ end
334
+
335
+ def test_default
336
+ assert_equal(<<-PO, run_msgcat([@po_fuzzy1, @po_fuzzy2]))
337
+ #, fuzzy
338
+ msgid "Hello"
339
+ msgstr "Bonjour1"
340
+ PO
341
+ end
342
+
343
+ def test_no_fuzzy
344
+ assert_equal("", run_msgcat([@po_fuzzy1, @po_fuzzy2], "--no-fuzzy"))
345
+ end
346
+ end
347
+
348
+ class TestHaveNoFuzzy < self
349
+ def setup
350
+ @po_fuzzy = <<-PO
351
+ #, fuzzy
352
+ msgid "Hello"
353
+ msgstr "Bonjour1"
354
+ PO
355
+
356
+ @po_not_fuzzy = <<-PO
357
+ msgid "Hello"
358
+ msgstr "Bonjour2"
359
+ PO
360
+ end
361
+
362
+ def test_default
363
+ assert_equal(<<-PO, run_msgcat([@po_fuzzy, @po_not_fuzzy]))
364
+ msgid "Hello"
365
+ msgstr "Bonjour2"
366
+ PO
367
+ end
368
+
369
+ def test_no_fuzzy
370
+ assert_equal(<<-PO, run_msgcat([@po_fuzzy, @po_not_fuzzy], "--no-fuzzy"))
371
+ msgid "Hello"
372
+ msgstr "Bonjour2"
373
+ PO
374
+ end
375
+ end
376
+ end
377
+
378
+ class TestWarning < self
379
+ def setup
380
+ @po_fuzzy = <<-PO
381
+ #, fuzzy
382
+ msgid "Hello World"
383
+ msgstr "Bonjour"
384
+ PO
385
+ end
386
+
387
+ def test_default
388
+ run_msgcat([@po_fuzzy])
389
+ assert_not_empty(@stderr)
390
+ end
391
+
392
+ def test_no_report_warning
393
+ run_msgcat([@po_fuzzy], "--no-report-warning")
394
+ assert_empty(@stderr)
395
+ end
396
+ end
397
+ end