test/test_detect_general.rb in locale-2.1.1 vs test/test_detect_general.rb in locale-2.1.2
- old
+ new
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
+# Copyright (C) 2012-2015 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2012 Hleb Valoshka
# Copyright (C) 2009-2010 Masao Mutoh
#
# License: Ruby's or LGPL
#
@@ -135,62 +135,139 @@
# Use the LANG value (locale charmap don't use LANGUAGE)
assert_equal "UTF-8", Locale.charset
end
- def test_language
- ENV["LC_ALL"] = "ja_JP.Shift_JIS"
- ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP"
+ sub_test_case "#language" do
+ test "LC_ALL" do
+ ENV["LC_ALL"] = "ja_JP.Shift_JIS"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP"
- tags = Locale.current
- assert_equal Locale::Tag::Posix, tags[0].class
- assert_equal Locale::Tag::Posix, tags[1].class
+ tags = Locale.current
+ assert_equal Locale::Tag::Posix, tags[0].class
+ assert_equal Locale::Tag::Posix, tags[1].class
- assert_equal "zh", tags.language
- assert_equal "CN", tags.region
- assert_equal "UTF-8", tags.charset
+ assert_equal "zh", tags.language
+ assert_equal "CN", tags.region
+ assert_equal "UTF-8", tags.charset
- assert_equal "zh", tags[0].language
- assert_equal "CN", tags[0].region
- assert_equal "UTF-8", tags[0].charset
+ assert_equal "zh", tags[0].language
+ assert_equal "CN", tags[0].region
+ assert_equal "UTF-8", tags[0].charset
- assert_equal "ja", tags[1].language
- assert_equal "JP", tags[1].region
- assert_equal nil, tags[1].charset
+ assert_equal "ja", tags[1].language
+ assert_equal "JP", tags[1].region
+ assert_equal nil, tags[1].charset
- assert_equal Locale::TagList.new([Locale::Tag::Posix.new("zh", "CN", "UTF-8"),
- Locale::Tag::Posix.new("ja", "JP")]), tags
+ assert_equal Locale::TagList.new([Locale::Tag::Posix.new("zh", "CN", "UTF-8"),
+ Locale::Tag::Posix.new("ja", "JP")]), tags
- assert_equal "Shift_JIS", Locale.charset
- end
+ assert_equal "Shift_JIS", Locale.charset
+ end
- def test_language_strip
- ENV["LC_ALL"] = "ja_JP.Shift_JIS"
- ENV["LANGUAGE"] = nil
+ test "LC_ALL=C" do
+ ENV["LC_ALL"] = "C"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP" # ignored
- 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"] = ""
+ assert_equal([Locale::Tag::Simple.new("en")],
+ Locale.current)
+ end
- 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"
+ test "LC_MESSAGES=C" do
+ ENV["LC_MESSAGES"] = "C"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP" # ignored
- 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
+ assert_equal([Locale::Tag::Simple.new("en")],
+ Locale.current)
+ end
+
+ test "LANG=C" do
+ ENV["LANG"] = "C"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP" # ignored
+
+ assert_equal([Locale::Tag::Simple.new("en")],
+ Locale.current)
+ end
+
+ test "LC_ALL and LC_MESSAGES=C" do
+ ENV["LC_ALL"] = "ja_JP.Shift_JIS"
+ ENV["LC_MESSAGES"] = "C"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP"
+
+ assert_equal([
+ Locale::Tag::Posix.new("zh", "CN", "UTF-8"),
+ Locale::Tag::Posix.new("ja", "JP"),
+ ],
+ Locale.current)
+ end
+
+ test "LC_ALL and LANG=C" do
+ ENV["LC_ALL"] = "ja_JP.Shift_JIS"
+ ENV["LANG"] = "C"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP"
+
+ assert_equal([
+ Locale::Tag::Posix.new("zh", "CN", "UTF-8"),
+ Locale::Tag::Posix.new("ja", "JP"),
+ ],
+ Locale.current)
+ end
+
+ test "LC_ALL=C and LC_MESSAGES" do
+ ENV["LC_ALL"] = "C"
+ ENV["LC_MESSAGES"] = "ja_JP.Shift_JIS"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP" # ignored
+
+ assert_equal([Locale::Tag::Simple.new("en")],
+ Locale.current)
+ end
+
+ test "LC_ALL=C and LANG" do
+ ENV["LC_ALL"] = "C"
+ ENV["LANG"] = "ja_JP.Shift_JIS"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP" # ignored
+
+ assert_equal([Locale::Tag::Simple.new("en")],
+ Locale.current)
+ end
+
+ test "LC_MESSAGES=C and LANG" do
+ ENV["LC_MESSAGES"] = "C"
+ ENV["LANG"] = "ja_JP.Shift_JIS"
+ ENV["LANGUAGE"] = "zh_CN.UTF-8:ja_JP" # ignored
+
+ assert_equal([Locale::Tag::Simple.new("en")],
+ Locale.current)
+ end
+
+ test "strip" do
+ 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
end
def test_no_charset
ENV["LC_ALL"] = "cs_CZ"