##// END OF EJS Templates
PDF: add test of ensuring 'ASCII-8BIT' encoding in Ruby 1.9 (#61)....
Toshi MARUYAMA -
r5446:02c5577a26b1
parent child
Show More
@@ -1,52 +1,55
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../../../../test_helper', __FILE__)
19 19
20 20 class PdfTest < ActiveSupport::TestCase
21 21 include Redmine::I18n
22 22
23 23 def test_fix_text_encoding_nil
24 24 set_language_if_valid 'ja'
25 25 pdf = Redmine::Export::PDF::IFPDF.new('ja')
26 26 assert pdf
27 27 assert_equal '', pdf.fix_text_encoding(nil)
28 28 end
29 29
30 30 def test_fix_text_encoding_cannot_convert_ja_cp932
31 31 pdf = Redmine::Export::PDF::IFPDF.new('ja')
32 32 assert pdf
33 33 utf8_txt_1 = "\xe7\x8b\x80\xe6\x85\x8b"
34 34 utf8_txt_2 = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
35 35 utf8_txt_3 = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
36 36 if utf8_txt_1.respond_to?(:force_encoding)
37 assert_equal "?\x91\xd4",
38 pdf.fix_text_encoding(utf8_txt_1)
39 assert_equal "?\x91\xd4?",
40 pdf.fix_text_encoding(utf8_txt_2)
41 assert_equal "??\x91\xd4?",
42 pdf.fix_text_encoding(utf8_txt_3)
37 txt_1 = pdf.fix_text_encoding(utf8_txt_1)
38 txt_2 = pdf.fix_text_encoding(utf8_txt_2)
39 txt_3 = pdf.fix_text_encoding(utf8_txt_3)
40 assert_equal "?\x91\xd4", txt_1
41 assert_equal "?\x91\xd4?", txt_2
42 assert_equal "??\x91\xd4?", txt_3
43 assert_equal "ASCII-8BIT", txt_1.encoding.to_s
44 assert_equal "ASCII-8BIT", txt_2.encoding.to_s
45 assert_equal "ASCII-8BIT", txt_3.encoding.to_s
43 46 else
44 47 assert_equal "???\x91\xd4",
45 48 pdf.fix_text_encoding(utf8_txt_1)
46 49 assert_equal "???\x91\xd4???",
47 50 pdf.fix_text_encoding(utf8_txt_2)
48 51 assert_equal "??????\x91\xd4???",
49 52 pdf.fix_text_encoding(utf8_txt_3)
50 53 end
51 54 end
52 55 end
General Comments 0
You need to be logged in to leave comments. Login now