File: gettext_test_cgi.rb

package info (click to toggle)
libgettext-ruby 1.7.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,892 kB
  • ctags: 1,198
  • sloc: ruby: 6,738; ansic: 67; makefile: 38; sql: 14; sh: 6
file content (66 lines) | stat: -rw-r--r-- 2,086 bytes parent folder | download
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
require 'test/unit'
require 'gettext/cgi'
require 'stringio'

class TestGetTextCGI < Test::Unit::TestCase
  def setup_cgi(str)
    $stdin = StringIO.new(str)
    cgi = CGI.new
    Locale.cgi = cgi
  end

  def test_system
    #query string
    setup_cgi("lang=ja_JP")
    assert_equal("ja_JP", Locale.system.to_str)
    setup_cgi("lang=ja-jp")
    assert_equal("ja_JP", Locale.system.to_str)
    assert_equal("ja-JP", Locale.system.to_iso3066)
    setup_cgi("lang=ja-jp")
    assert_equal("ja_JP", Locale.system.to_str)
    assert_equal("ja-JP", Locale.system.to_iso3066)
    setup_cgi("")
    ENV["HTTP_ACCEPT_LANGUAGE"] = ""
    ENV["HTTP_ACCEPT_CHARSET"] = ""
    assert_equal("en", Locale.system.to_str)
    assert_equal("en", Locale.system.to_iso3066)

    #cockie
    setup_cgi("Set-Cookie: lang=en-us")
    assert_equal("en_US", Locale.system.to_str)

    #accept language
    setup_cgi("")
    ENV["HTTP_ACCEPT_LANGUAGE"] = "ja,en-us;q=0.7,en;q=0.3"
    assert_equal("ja", Locale.system.to_str)
    assert_equal("ja", Locale.system.to_iso3066)
    ENV["HTTP_ACCEPT_LANGUAGE"] = "en-us,ja;q=0.7,en;q=0.3"
    assert_equal("en_US", Locale.system.to_str)
    assert_equal("en-US", Locale.system.to_iso3066)
    ENV["HTTP_ACCEPT_LANGUAGE"] = "en"
    assert_equal("en", Locale.system.to_str)
    assert_equal("en", Locale.system.to_iso3066)

    #accept charset
    ENV["HTTP_ACCEPT_CHARSET"] = "Shift_JIS"
    assert_equal("Shift_JIS", Locale.system.charset)
    ENV["HTTP_ACCEPT_CHARSET"] = "EUC-JP,*,utf-8"
    assert_equal("EUC-JP", Locale.system.charset)
    ENV["HTTP_ACCEPT_CHARSET"] = "*"
    assert_equal("UTF-8", Locale.system.charset)
    ENV["HTTP_ACCEPT_CHARSET"] = ""
    assert_equal("UTF-8", Locale.system.charset)
  end

  def test_default
    Locale.set_default(nil)
    Locale.set_default(Locale::Object.new("ja_JP", nil, "EUC-JP"))
    setup_cgi("")
    ENV["HTTP_ACCEPT_LANGUAGE"] = ""
    ENV["HTTP_ACCEPT_CHARSET"] = ""
    assert_equal("ja_JP", Locale.default.to_str)
    assert_equal("EUC-JP", Locale.default.charset)
    Locale.set_default(nil)
  end

end