annotate .svn/pristine/15/1562dffbb640b06caf248c7277e18410c01feded.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class Redmine::CodesetUtilTest < ActiveSupport::TestCase
Chris@1296 21
Chris@1296 22 def test_to_utf8_by_setting_from_latin1
Chris@1296 23 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
Chris@1296 24 s1 = "Texte encod\xc3\xa9"
Chris@1296 25 s2 = "Texte encod\xe9"
Chris@1296 26 s3 = s2.dup
Chris@1296 27 if s1.respond_to?(:force_encoding)
Chris@1296 28 s1.force_encoding("UTF-8")
Chris@1296 29 s2.force_encoding("ASCII-8BIT")
Chris@1296 30 s3.force_encoding("UTF-8")
Chris@1296 31 end
Chris@1296 32 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
Chris@1296 33 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
Chris@1296 34 end
Chris@1296 35 end
Chris@1296 36
Chris@1296 37 def test_to_utf8_by_setting_from_euc_jp
Chris@1296 38 with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
Chris@1296 39 s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
Chris@1296 40 s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
Chris@1296 41 s3 = s2.dup
Chris@1296 42 if s1.respond_to?(:force_encoding)
Chris@1296 43 s1.force_encoding("UTF-8")
Chris@1296 44 s2.force_encoding("ASCII-8BIT")
Chris@1296 45 s3.force_encoding("UTF-8")
Chris@1296 46 end
Chris@1296 47 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
Chris@1296 48 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
Chris@1296 49 end
Chris@1296 50 end
Chris@1296 51
Chris@1296 52 def test_to_utf8_by_setting_should_be_converted_all_latin1
Chris@1296 53 with_settings :repositories_encodings => 'ISO-8859-1' do
Chris@1296 54 s1 = "\xc3\x82\xc2\x80"
Chris@1296 55 s2 = "\xC2\x80"
Chris@1296 56 s3 = s2.dup
Chris@1296 57 if s1.respond_to?(:force_encoding)
Chris@1296 58 s1.force_encoding("UTF-8")
Chris@1296 59 s2.force_encoding("ASCII-8BIT")
Chris@1296 60 s3.force_encoding("UTF-8")
Chris@1296 61 end
Chris@1296 62 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
Chris@1296 63 assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
Chris@1296 64 end
Chris@1296 65 end
Chris@1296 66
Chris@1296 67 def test_to_utf8_by_setting_blank_string
Chris@1296 68 assert_equal "", Redmine::CodesetUtil.to_utf8_by_setting("")
Chris@1296 69 assert_equal nil, Redmine::CodesetUtil.to_utf8_by_setting(nil)
Chris@1296 70 end
Chris@1296 71
Chris@1296 72 def test_to_utf8_by_setting_returns_ascii_as_utf8
Chris@1296 73 s1 = "ASCII"
Chris@1296 74 s2 = s1.dup
Chris@1296 75 if s1.respond_to?(:force_encoding)
Chris@1296 76 s1.force_encoding("UTF-8")
Chris@1296 77 s2.force_encoding("ISO-8859-1")
Chris@1296 78 end
Chris@1296 79 str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1)
Chris@1296 80 str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2)
Chris@1296 81 assert_equal s1, str1
Chris@1296 82 assert_equal s1, str2
Chris@1296 83 if s1.respond_to?(:force_encoding)
Chris@1296 84 assert_equal "UTF-8", str1.encoding.to_s
Chris@1296 85 assert_equal "UTF-8", str2.encoding.to_s
Chris@1296 86 end
Chris@1296 87 end
Chris@1296 88
Chris@1296 89 def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped
Chris@1296 90 with_settings :repositories_encodings => '' do
Chris@1296 91 # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
Chris@1296 92 s1 = "Texte encod\xe9 en ISO-8859-1."
Chris@1296 93 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
Chris@1296 94 str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
Chris@1296 95 if str.respond_to?(:force_encoding)
Chris@1296 96 assert str.valid_encoding?
Chris@1296 97 assert_equal "UTF-8", str.encoding.to_s
Chris@1296 98 end
Chris@1296 99 assert_equal "Texte encod? en ISO-8859-1.", str
Chris@1296 100 end
Chris@1296 101 end
Chris@1296 102
Chris@1296 103 def test_to_utf8_by_setting_invalid_utf8_sequences_should_be_stripped_ja_jis
Chris@1296 104 with_settings :repositories_encodings => 'ISO-2022-JP' do
Chris@1296 105 s1 = "test\xb5\xfetest\xb5\xfe"
Chris@1296 106 s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
Chris@1296 107 str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
Chris@1296 108 if str.respond_to?(:force_encoding)
Chris@1296 109 assert str.valid_encoding?
Chris@1296 110 assert_equal "UTF-8", str.encoding.to_s
Chris@1296 111 end
Chris@1296 112 assert_equal "test??test??", str
Chris@1296 113 end
Chris@1296 114 end
Chris@1296 115 end