kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.8 KiB
136 lines
4.8 KiB
12 years ago
|
#-- copyright
|
||
|
# OpenProject is a project management system.
|
||
10 years ago
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
12 years ago
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License version 3.
|
||
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program 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 General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
#
|
||
12 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
|
# ChiliProject is a project management system.
|
||
14 years ago
|
#
|
||
14 years ago
|
# Copyright (C) 2010-2011 the ChiliProject Team
|
||
14 years ago
|
#
|
||
14 years ago
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
14 years ago
|
#
|
||
10 years ago
|
require 'legacy_spec_helper'
|
||
14 years ago
|
|
||
11 years ago
|
describe Redmine::CodesetUtil do
|
||
|
it 'should to utf8 by setting from latin1' do
|
||
10 years ago
|
with_settings repositories_encodings: 'UTF-8,ISO-8859-1' do
|
||
14 years ago
|
s1 = "Texte encod\xc3\xa9"
|
||
|
s2 = "Texte encod\xe9"
|
||
14 years ago
|
s3 = s2.dup
|
||
14 years ago
|
if s1.respond_to?(:force_encoding)
|
||
10 years ago
|
s1.force_encoding('UTF-8')
|
||
|
s2.force_encoding('ASCII-8BIT')
|
||
|
s3.force_encoding('UTF-8')
|
||
14 years ago
|
end
|
||
13 years ago
|
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
|
||
|
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should to utf8 by setting from euc jp' do
|
||
10 years ago
|
with_settings repositories_encodings: 'UTF-8,EUC-JP' do
|
||
14 years ago
|
s1 = "\xe3\x83\xac\xe3\x83\x83\xe3\x83\x89\xe3\x83\x9e\xe3\x82\xa4\xe3\x83\xb3"
|
||
|
s2 = "\xa5\xec\xa5\xc3\xa5\xc9\xa5\xde\xa5\xa4\xa5\xf3"
|
||
14 years ago
|
s3 = s2.dup
|
||
14 years ago
|
if s1.respond_to?(:force_encoding)
|
||
10 years ago
|
s1.force_encoding('UTF-8')
|
||
|
s2.force_encoding('ASCII-8BIT')
|
||
|
s3.force_encoding('UTF-8')
|
||
14 years ago
|
end
|
||
13 years ago
|
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
|
||
|
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should to utf8 by setting should be converted all latin1' do
|
||
10 years ago
|
with_settings repositories_encodings: 'ISO-8859-1' do
|
||
14 years ago
|
s1 = "\xc3\x82\xc2\x80"
|
||
|
s2 = "\xC2\x80"
|
||
14 years ago
|
s3 = s2.dup
|
||
14 years ago
|
if s1.respond_to?(:force_encoding)
|
||
10 years ago
|
s1.force_encoding('UTF-8')
|
||
|
s2.force_encoding('ASCII-8BIT')
|
||
|
s3.force_encoding('UTF-8')
|
||
14 years ago
|
end
|
||
13 years ago
|
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s2)
|
||
|
assert_equal s1, Redmine::CodesetUtil.to_utf8_by_setting(s3)
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should to utf8 by setting blank string' do
|
||
10 years ago
|
assert_equal '', Redmine::CodesetUtil.to_utf8_by_setting('')
|
||
13 years ago
|
assert_equal nil, Redmine::CodesetUtil.to_utf8_by_setting(nil)
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should to utf8 by setting returns ascii as utf8' do
|
||
10 years ago
|
s1 = 'ASCII'
|
||
14 years ago
|
s2 = s1.dup
|
||
|
if s1.respond_to?(:force_encoding)
|
||
10 years ago
|
s1.force_encoding('UTF-8')
|
||
|
s2.force_encoding('ISO-8859-1')
|
||
14 years ago
|
end
|
||
13 years ago
|
str1 = Redmine::CodesetUtil.to_utf8_by_setting(s1)
|
||
|
str2 = Redmine::CodesetUtil.to_utf8_by_setting(s2)
|
||
14 years ago
|
assert_equal s1, str1
|
||
|
assert_equal s1, str2
|
||
|
if s1.respond_to?(:force_encoding)
|
||
10 years ago
|
assert_equal 'UTF-8', str1.encoding.to_s
|
||
|
assert_equal 'UTF-8', str2.encoding.to_s
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should to utf8 by setting invalid utf8 sequences should be stripped' do
|
||
10 years ago
|
with_settings repositories_encodings: '' do
|
||
13 years ago
|
s1 = "Texte encod\xe9 en ISO-8859-1."
|
||
10 years ago
|
s1.force_encoding('ASCII-8BIT') if s1.respond_to?(:force_encoding)
|
||
13 years ago
|
str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
|
||
|
if str.respond_to?(:force_encoding)
|
||
|
assert str.valid_encoding?
|
||
10 years ago
|
assert_equal 'UTF-8', str.encoding.to_s
|
||
13 years ago
|
end
|
||
10 years ago
|
assert_equal 'Texte encod? en ISO-8859-1.', str
|
||
13 years ago
|
end
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should to utf8 by setting invalid utf8 sequences should be stripped ja jis' do
|
||
10 years ago
|
with_settings repositories_encodings: 'ISO-2022-JP' do
|
||
13 years ago
|
s1 = "test\xb5\xfetest\xb5\xfe"
|
||
10 years ago
|
s1.force_encoding('ASCII-8BIT') if s1.respond_to?(:force_encoding)
|
||
13 years ago
|
str = Redmine::CodesetUtil.to_utf8_by_setting(s1)
|
||
14 years ago
|
if str.respond_to?(:force_encoding)
|
||
|
assert str.valid_encoding?
|
||
10 years ago
|
assert_equal 'UTF-8', str.encoding.to_s
|
||
14 years ago
|
end
|
||
10 years ago
|
assert_equal 'test??test??', str
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
end
|