diff test/unit/helpers/.svn/text-base/repository_helper_test.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children
line wrap: on
line diff
--- a/test/unit/helpers/.svn/text-base/repository_helper_test.rb.svn-base	Thu Mar 03 11:42:28 2011 +0000
+++ b/test/unit/helpers/.svn/text-base/repository_helper_test.rb.svn-base	Mon Jun 06 14:24:13 2011 +0100
@@ -24,7 +24,7 @@
     with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
       s1 = "Texte encod\xc3\xa9"
       s2 = "Texte encod\xe9"
-      s3 = s2
+      s3 = s2.dup
       if s1.respond_to?(:force_encoding)
         s1.force_encoding("UTF-8")
         s2.force_encoding("ASCII-8BIT")
@@ -39,7 +39,7 @@
     with_settings :repositories_encodings => 'UTF-8,EUC-JP' do
       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"
-      s3 = s2
+      s3 = s2.dup
       if s1.respond_to?(:force_encoding)
         s1.force_encoding("UTF-8")
         s2.force_encoding("ASCII-8BIT")
@@ -54,7 +54,7 @@
     with_settings :repositories_encodings => 'ISO-8859-1' do
       s1 = "\xc3\x82\xc2\x80"
       s2 = "\xC2\x80"
-      s3 = s2
+      s3 = s2.dup
       if s1.respond_to?(:force_encoding)
         s1.force_encoding("UTF-8")
         s2.force_encoding("ASCII-8BIT")
@@ -64,5 +64,53 @@
       assert_equal s1, to_utf8(s3)
     end
   end
+
+  def test_to_utf8_blank_string
+    assert_equal "",  to_utf8("")
+    assert_equal nil, to_utf8(nil)
+  end
+
+  def test_to_utf8_returns_ascii_as_utf8
+    s1 = "ASCII"
+    s2 = s1.dup
+    if s1.respond_to?(:force_encoding)
+      s1.force_encoding("UTF-8")
+      s2.force_encoding("ISO-8859-1")
+    end
+    str1 = to_utf8(s1)
+    str2 = to_utf8(s2)
+    assert_equal s1, str1
+    assert_equal s1, str2
+    if s1.respond_to?(:force_encoding)
+      assert_equal "UTF-8", str1.encoding.to_s
+      assert_equal "UTF-8", str2.encoding.to_s
+    end
+  end
+
+  def test_to_utf8_invalid_utf8_sequences_should_be_stripped
+    with_settings :repositories_encodings => '' do
+      # s1 = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
+      s1 = "Texte encod\xe9 en ISO-8859-1."
+      s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
+      str = to_utf8(s1)
+      if str.respond_to?(:force_encoding)
+        assert str.valid_encoding?
+        assert_equal "UTF-8", str.encoding.to_s
+      end
+      assert_equal "Texte encod? en ISO-8859-1.", str
+    end
+  end
+
+  def test_to_utf8_invalid_utf8_sequences_should_be_stripped_ja_jis
+    with_settings :repositories_encodings => 'ISO-2022-JP' do
+      s1 = "test\xb5\xfetest\xb5\xfe"
+      s1.force_encoding("ASCII-8BIT") if s1.respond_to?(:force_encoding)
+      str = to_utf8(s1)
+      if str.respond_to?(:force_encoding)
+        assert str.valid_encoding?
+        assert_equal "UTF-8", str.encoding.to_s
+      end
+      assert_equal "test??test??", str
+    end
+  end
 end
-