##// END OF EJS Templates
move repositories helper to_utf8 tests to new CodesetUtilTest (#2371)...
Toshi MARUYAMA -
r7708:b38dc9a301c3
parent child
Show More
@@ -15,12 +15,11
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../../test_helper', __FILE__)
18 require File.expand_path('../../../../test_helper', __FILE__)
19
19
20 class RepositoryHelperTest < ActionView::TestCase
20 class Redmine::CodesetUtilTest < ActiveSupport::TestCase
21 include RepositoriesHelper
22
21
23 def test_from_latin1_to_utf8
22 def test_to_utf8_by_setting_from_latin1
24 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
23 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
25 s1 = "Texte encod\xc3\xa9"
24 s1 = "Texte encod\xc3\xa9"
26 s2 = "Texte encod\xe9"
25 s2 = "Texte encod\xe9"
@@ -30,12 +29,12 class RepositoryHelperTest < ActionView::TestCase
30 s2.force_encoding("ASCII-8BIT")
29 s2.force_encoding("ASCII-8BIT")
31 s3.force_encoding("UTF-8")
30 s3.force_encoding("UTF-8")
32 end
31 end
33 assert_equal s1, to_utf8(s2)
32 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
34 assert_equal s1, to_utf8(s3)
33 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
35 end
34 end
36 end
35 end
37
36
38 def test_from_euc_jp_to_utf8
37 def test_to_utf8_by_setting_from_euc_jp
39 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
38 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
40 s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
39 s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
41 s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
40 s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
@@ -45,12 +44,12 class RepositoryHelperTest < ActionView::TestCase
45 s2.force_encoding("ASCII-8BIT")
44 s2.force_encoding("ASCII-8BIT")
46 s3.force_encoding("UTF-8")
45 s3.force_encoding("UTF-8")
47 end
46 end
48 assert_equal s1, to_utf8(s2)
47 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
49 assert_equal s1, to_utf8(s3)
48 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
50 end
49 end
51 end
50 end
52
51
53 def test_to_utf8_should_be_converted_all_latin1_to_utf8
52 def test_to_utf8_by_setting_should_be_converted_all_latin1
54 with_settings :repositories_encodings => 'ISO-8859-1' do
53 with_settings :repositories_encodings => 'ISO-8859-1' do
55 s1 = "\xc3\x82\xc2\x80"
54 s1 = "\xc3\x82\xc2\x80"
56 s2 = "\xC2\x80"
55 s2 = "\xC2\x80"
@@ -60,25 +59,25 class RepositoryHelperTest < ActionView::TestCase
60 s2.force_encoding("ASCII-8BIT")
59 s2.force_encoding("ASCII-8BIT")
61 s3.force_encoding("UTF-8")
60 s3.force_encoding("UTF-8")
62 end
61 end
63 assert_equal s1, to_utf8(s2)
62 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
64 assert_equal s1, to_utf8(s3)
63 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
65 end
64 end
66 end
65 end
67
66
68 def test_to_utf8_blank_string
67 def test_to_utf8_by_setting_blank_string
69 assert_equal "", to_utf8("")
68 assert_equal "", Redmine::CodesetUtil.to_utf8_by_setting("")
70 assert_equal nil, to_utf8(nil)
69 assert_equal nil, Redmine::CodesetUtil.to_utf8_by_setting(nil)
71 end
70 end
72
71
73 def test_to_utf8_returns_ascii_as_utf8
72 def test_to_utf8_by_setting_returns_ascii_as_utf8
74 s1 = "ASCII"
73 s1 = "ASCII"
75 s2 = s1.dup
74 s2 = s1.dup
76 if s1.respond_to?(:force_encoding)
75 if s1.respond_to?(:force_encoding)
77 s1.force_encoding("UTF-8")
76 s1.force_encoding("UTF-8")
78 s2.force_encoding("ISO-8859-1")
77 s2.force_encoding("ISO-8859-1")
79 end
78 end
80 str1 = to_utf8(s1)
79 str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1)
81 str2 = to_utf8(s2)
80 str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2)
82 assert_equal s1, str1
81 assert_equal s1, str1
83 assert_equal s1, str2
82 assert_equal s1, str2
84 if s1.respond_to?(:force_encoding)
83 if s1.respond_to?(:force_encoding)
@@ -87,12 +86,12 class RepositoryHelperTest < ActionView::TestCase
87 end
86 end
88 end
87 end
89
88
90 def test_to_utf8_invalid_utf8_sequences_should_be_stripped
89 def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped
91 with_settings :repositories_encodings => '' do
90 with_settings :repositories_encodings => '' do
92 # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
91 # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
93 s1 = "Texte encod\xe9 en ISO-8859-1."
92 s1 = "Texte encod\xe9 en ISO-8859-1."
94 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
93 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
95 str = to_utf8(s1)
94 str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
96 if str.respond_to?(:force_encoding)
95 if str.respond_to?(:force_encoding)
97 assert str.valid_encoding?
96 assert str.valid_encoding?
98 assert_equal "UTF-8", str.encoding.to_s
97 assert_equal "UTF-8", str.encoding.to_s
@@ -101,11 +100,11 class RepositoryHelperTest < ActionView::TestCase
101 end
100 end
102 end
101 end
103
102
104 def test_to_utf8_invalid_utf8_sequences_should_be_stripped_ja_jis
103 def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis
105 with_settings :repositories_encodings => 'ISO-2022-JP' do
104 with_settings :repositories_encodings => 'ISO-2022-JP' do
106 s1 = "test\xb5\xfetest\xb5\xfe"
105 s1 = "test\xb5\xfetest\xb5\xfe"
107 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
106 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
108 str = to_utf8(s1)
107 str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
109 if str.respond_to?(:force_encoding)
108 if str.respond_to?(:force_encoding)
110 assert str.valid_encoding?
109 assert str.valid_encoding?
111 assert_equal "UTF-8", str.encoding.to_s
110 assert_equal "UTF-8", str.encoding.to_s
General Comments 0
You need to be logged in to leave comments. Login now