File: test_mo.rb

package info (click to toggle)
ruby-gettext 3.2.9-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,400 kB
  • sloc: ruby: 9,375; makefile: 8
file content (37 lines) | stat: -rw-r--r-- 919 bytes parent folder | download | duplicates (4)
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
# -*- coding: utf-8 -*-

require 'gettext/mo'

class TestMo < Test::Unit::TestCase
  def test_not_exist_msgid
    mo = load_mo("_.mo")
    assert_equal(nil, mo["notexistent"])
  end

  def test_untranslated
    mo = load_mo("untranslated.mo")
    assert_false(mo.has_key?("untranslated"))
    assert_equal(nil, mo["untranslated"])
  end

  def test_non_ascii
    mo = load_mo("non_ascii.mo")
    assert_equal("Hello in Japanese", mo["こんにちは"])
  end

  def test_invalid_charset
    mo = load_mo("hello.mo", "ISO-8859-1")
    assert_equal("?????", mo["Hello"])
  end

  def test_backslash
    mo = load_mo("backslash.mo")
    assert_equal("'\\'は'\\\\'とエスケープするべきです。",
                 mo["You should escape '\\' as '\\\\'."])
  end

  def load_mo(file, output_charset=nil)
    output_charset ||= "UTF-8"
    GetText::MO.open("locale/ja/LC_MESSAGES/#{file}", output_charset)
  end
end