test/test_detect_general.rb in locale-2.0.5 vs test/test_detect_general.rb in locale-2.0.6
- old
+ new
@@ -1,21 +1,43 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
+# Copyright (C) 2012 Hleb Valoshka
+# Copyright (C) 2009-2010 Masao Mutoh
+#
+# License: Ruby's or LGPL
+#
+# This library is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
require 'locale'
require 'test/unit'
class TestDetectGeneral < Test::Unit::TestCase
def setup
+ Locale.init
Locale.clear_all
ENV["LC_ALL"] = nil
- ENV["LC_MESSAGES"] = nil
+ ENV["LC_CTYPES"] = nil
ENV["LANG"] = nil
ENV["LANGUAGE"] = nil
end
def test_lc_all
ENV["LC_ALL"] = "ja_JP.eucJP"
- ENV["LC_MESSAGES"] = "zh_CN.UTF-8" #Ignored.
+ ENV["LC_CTYPES"] = "zh_CN.UTF-8" #Ignored.
ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
ENV["LANGUAGE"] = nil
lang = Locale.current[0]
assert_equal Locale::Tag::Posix, lang.class
@@ -27,11 +49,11 @@
assert_equal "eucJP", Locale.charset
end
def test_lc_messages
ENV["LC_ALL"] = nil
- ENV["LC_MESSAGES"] = "ja_JP.eucJP"
+ ENV["LC_CTYPES"] = "ja_JP.eucJP"
ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
ENV["LANGUAGE"] = nil
lang = Locale.current[0]
assert_equal Locale::Tag::Posix, lang.class
@@ -43,11 +65,11 @@
assert_equal "eucJP", Locale.charset
end
def test_lang
ENV["LC_ALL"] = nil
- ENV["LC_MESSAGES"] = nil
+ ENV["LC_CTYPES"] = nil
ENV["LANG"] = "ja_JP.eucJP"
ENV["LANGUAGE"] = nil
lang = Locale.current[0]
assert_equal Locale::Tag::Posix, lang.class
@@ -59,11 +81,11 @@
assert_equal "eucJP", Locale.charset
end
def test_lang_complex
ENV["LC_ALL"] = "zh_CN.UTF-8" # Ignored.
- ENV["LC_MESSAGES"] = "ko_KR.UTF-8" #Ingored.
+ ENV["LC_CTYPES"] = "ko_KR.UTF-8" #Ingored.
ENV["LANG"] = "en_US.UTF-8" # Ignored.
ENV["LANGUAGE"] ="ja_JP.eucJP:zh_CN.UTF-8"
lang = Locale.current[0]
assert_equal Locale::Tag::Posix, lang.class
@@ -100,10 +122,39 @@
Locale::Tag::Posix.new("ja", "JP")]), tags
assert_equal "Shift_JIS", Locale.charset
end
+ def test_language_strip
+ ENV["LC_ALL"] = "ja_JP.Shift_JIS"
+ ENV["LANGUAGE"] = nil
+
+ tags = Locale.current
+ assert_equal 1, tags.size
+ assert_equal Locale::Tag::Posix, tags[0].class
+ assert_equal "ja", tags.language
+ assert_equal "ja", tags[0].language
+ Locale.clear
+ ENV["LANGUAGE"] = ""
+
+ tags = Locale.current
+ assert_equal 1, tags.size
+ assert_equal Locale::Tag::Posix, tags[0].class
+ assert_equal "ja", tags.language
+ assert_equal "ja", tags[0].language
+ Locale.clear
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP"
+
+ tags = Locale.current
+ assert_equal 2, tags.size
+ assert_equal Locale::Tag::Posix, tags[0].class
+ assert_equal Locale::Tag::Posix, tags[1].class
+ assert_equal "zh", tags.language
+ assert_equal "zh", tags[0].language
+ assert_equal "ja", tags[1].language
+ end
+
def test_no_charset
ENV["LC_ALL"] = "cs_CZ"
lang = Locale.current[0]
assert_equal Locale::Tag::Posix, lang.class
@@ -147,10 +198,30 @@
assert_equal Locale::Tag.parse("yo_NG"), Locale.default
assert_equal Locale::Tag.parse("fr"), Locale.current[0]
Locale.set_default(nil)
end
+ def test_wrong_envs
+ omit("JRuby never use default") if jruby?
+
+ ENV["LC_ALL"] = nil
+ ENV["LANGUAGE"] = "g"
+ Locale.default = "de"
+ assert_equal Locale::Tag.parse("de"), Locale.current[0]
+
+ ENV["LC_ALL"] = "f"
+ ENV["LANGUAGE"] = nil
+ Locale.default = "fr"
+ assert_equal Locale::Tag.parse("fr"), Locale.current[0]
+
+ ENV["LC_ALL"] = "j"
+ ENV["LANGUAGE"] = nil
+ Locale.default = nil
+ assert_equal Locale::Tag.parse("en"), Locale.current[0]
+
+ end
+
def test_clear
ENV["LC_ALL"] = "ja_JP.Shift_JIS"
ENV["LANGUAGE"] = nil
assert_equal Locale::Tag.parse("ja_JP.Shift_JIS"), Locale.current[0]
@@ -159,6 +230,10 @@
assert_equal Locale::Tag::Posix.parse("zh_CN.UTF-8"), Locale.current[0]
assert_equal Locale::Tag::Posix.parse("ja_JP"), Locale.current[1]
end
+ private
+ def jruby?
+ RUBY_PLATFORM == "java"
+ end
end