[前][次][番号順一覧][スレッド一覧]

ruby-changes:5332

From: nobu <ko1@a...>
Date: Thu, 5 Jun 2008 13:58:57 +0900 (JST)
Subject: [ruby-changes:5332] Ruby:r16833 (ruby_1_8, trunk): * test/iconv/test_{basic,option}.rb, test/iconv/utils.rb: added.

nobu	2008-06-05 13:58:41 +0900 (Thu, 05 Jun 2008)

  New Revision: 16833

  Added files:
    branches/ruby_1_8/test/iconv/test_basic.rb
    branches/ruby_1_8/test/iconv/test_option.rb
    branches/ruby_1_8/test/iconv/test_partial.rb
    branches/ruby_1_8/test/iconv/utils.rb
    trunk/test/iconv/test_basic.rb
    trunk/test/iconv/test_option.rb
    trunk/test/iconv/test_partial.rb
    trunk/test/iconv/utils.rb
  Removed files:
    branches/ruby_1_8/test/iconv/test_simple.rb
    trunk/test/iconv/test_simple.rb

  Log:
    * test/iconv/test_{basic,option}.rb, test/iconv/utils.rb: added.
    
    * test/iconv/test_partial.rb: renamed from test_simple.rb.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/iconv/test_partial.rb
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/iconv/test_option.rb?revision=16833&view=markup
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/iconv/test_option.rb?r1=16833&r2=16832&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/iconv/utils.rb?revision=16833&view=markup
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/iconv/utils.rb?r1=16833&r2=16832&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/iconv/test_simple.rb
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/iconv/test_basic.rb?revision=16833&view=markup
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/iconv/test_basic.rb?r1=16833&r2=16832&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/iconv/test_simple.rb
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/iconv/test_basic.rb?revision=16833&view=markup
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/iconv/test_basic.rb?r1=16833&r2=16832&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/iconv/test_partial.rb
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/iconv/test_option.rb?revision=16833&view=markup
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/iconv/test_option.rb?r1=16833&r2=16832&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/iconv/utils.rb?revision=16833&view=markup
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/test/iconv/utils.rb?r1=16833&r2=16832&diff_format=u

Index: test/iconv/test_simple.rb
===================================================================
--- test/iconv/test_simple.rb	(revision 16832)
+++ test/iconv/test_simple.rb	(revision 16833)
@@ -1,27 +0,0 @@
-require 'test/unit'
-begin
-  require 'iconv'
-rescue LoadError
-end
-
-class TestIConv < Test::Unit::TestCase
-  ASCII = "ascii"
-  def test_simple
-    c = Iconv.open(ASCII, ASCII)
-    ref = '[ruby-core:17092]'
-  rescue
-    return
-  else
-    assert_equal("abc", c.iconv("abc"))
-    assert_equal("c",   c.iconv("abc", 2),     "#{ref}: with start")
-    assert_equal("c",   c.iconv("abc", 2, 1),  "#{ref}: with start, length")
-    assert_equal("c",   c.iconv("abc", 2, 5),  "#{ref}: with start, longer length")
-    assert_equal("bc",  c.iconv("abc", -2),    "#{ref}: with nagative start")
-    assert_equal("b",   c.iconv("abc", -2, 1), "#{ref}: with nagative start, length")
-    assert_equal("bc",  c.iconv("abc", -2, 5), "#{ref}: with nagative start, longer length")
-    assert_equal("",    c.iconv("abc", 5),     "#{ref}: with OOB")
-    assert_equal("",    c.iconv("abc", 5, 2),  "#{ref}: with OOB, length")
-  ensure
-    c.close if c
-  end
-end if defined?(::Iconv)
Index: test/iconv/test_basic.rb
===================================================================
--- test/iconv/test_basic.rb	(revision 0)
+++ test/iconv/test_basic.rb	(revision 16833)
@@ -0,0 +1,49 @@
+require File.join(File.dirname(__FILE__), "utils.rb")
+
+class TestIconv
+  def test_euc2sjis
+    iconv = Iconv.open('SHIFT_JIS', 'EUC-JP')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+  end
+
+  def test_close
+    iconv = Iconv.new('Shift_JIS', 'EUC-JP')
+    output = ""
+    begin
+      output += iconv.iconv(EUCJ_STR)
+      output += iconv.iconv(nil)
+    ensure
+      assert_respond_to(iconv, :close)
+      assert_equal("", iconv.close)
+      assert_equal(SJIS_STR, output)
+    end
+  end
+
+  def test_open_without_block
+    assert_respond_to(Iconv, :open)
+    iconv = Iconv.open('SHIFT_JIS', 'EUC-JP')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str )
+    iconv.close
+  end
+
+  def test_open_with_block
+    input = "#{EUCJ_STR}\n"*2
+    output = ""
+    Iconv.open("Shift_JIS", "EUC-JP") do |cd|
+      input.each_line do |s|
+        output << cd.iconv(s)
+      end
+      output << cd.iconv(nil)
+    end
+    assert_equal("#{SJIS_STR}\n"*2, output)
+  end
+
+  def test_unknown_encoding
+    assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") }
+  end
+end

Property changes on: test/iconv/test_basic.rb
___________________________________________________________________
Name: svn:eol-style
   + LF

Index: test/iconv/utils.rb
===================================================================
--- test/iconv/utils.rb	(revision 0)
+++ test/iconv/utils.rb	(revision 16833)
@@ -0,0 +1,22 @@
+begin
+  require 'iconv'
+rescue LoadError
+else
+  require 'test/unit'
+end
+
+class TestIconv < Test::Unit::TestCase
+  if defined?(::Encoding) and String.method_defined?(:force_encoding)
+    def self.encode(str, enc)
+      str.force_encoding(enc)
+    end
+  else
+    def self.encode(str, enc)
+      str
+    end
+  end
+
+  ASCII = "ascii"
+  EUCJ_STR = encode("\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa", "EUC-JP").freeze
+  SJIS_STR = encode("\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8", "Shift_JIS").freeze
+end if defined?(::Iconv)

Property changes on: test/iconv/utils.rb
___________________________________________________________________
Name: svn:eol-style
   + LF

Index: test/iconv/test_option.rb
===================================================================
--- test/iconv/test_option.rb	(revision 0)
+++ test/iconv/test_option.rb	(revision 16833)
@@ -0,0 +1,31 @@
+require File.join(File.dirname(__FILE__), "utils.rb")
+
+class TestIconv
+  def test_ignore_option
+    iconv = Iconv.new('SHIFT_JIS', 'EUC-JP//ignore')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+
+    iconv = Iconv.new('SHIFT_JIS//IGNORE', 'EUC-JP//ignore')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+  end
+
+  def test_translit_option
+    iconv = Iconv.new('SHIFT_JIS', 'EUC-JP//ignore')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+
+    iconv = Iconv.new('SHIFT_JIS//TRANSLIT', 'EUC-JP//translit//ignore')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+  end
+end if defined?(::Iconv)

Property changes on: test/iconv/test_option.rb
___________________________________________________________________
Name: svn:eol-style
   + LF

Index: test/iconv/test_partial.rb
===================================================================
--- test/iconv/test_partial.rb	(revision 0)
+++ test/iconv/test_partial.rb	(revision 16833)
@@ -0,0 +1,41 @@
+require File.join(File.dirname(__FILE__), "utils.rb")
+
+class TestIconv
+  def test_partial_ascii
+    c = Iconv.open(ASCII, ASCII)
+    ref = '[ruby-core:17092]'
+  rescue
+    return
+  else
+    assert_equal("abc", c.iconv("abc"))
+    assert_equal("c",   c.iconv("abc", 2),     "#{ref}: with start")
+    assert_equal("c",   c.iconv("abc", 2, 1),  "#{ref}: with start, length")
+    assert_equal("c",   c.iconv("abc", 2, 5),  "#{ref}: with start, longer length")
+    assert_equal("bc",  c.iconv("abc", -2),    "#{ref}: with nagative start")
+    assert_equal("b",   c.iconv("abc", -2, 1), "#{ref}: with nagative start, length")
+    assert_equal("bc",  c.iconv("abc", -2, 5), "#{ref}: with nagative start, longer length")
+    assert_equal("",    c.iconv("abc", 5),     "#{ref}: with OOB")
+    assert_equal("",    c.iconv("abc", 5, 2),  "#{ref}: with OOB, length")
+  ensure
+    c.close if c
+  end
+
+  def test_partial_euc2sjis
+    c = Iconv.open('SHIFT_JIS', 'EUC-JP')
+  rescue
+    return
+  else
+    assert_equal(SJIS_STR[0, 2],   c.iconv(EUCJ_STR, 0, 2))
+    assert_equal(SJIS_STR,         c.iconv(EUCJ_STR, 0, 20))
+    assert_equal(SJIS_STR[2..-1],  c.iconv(EUCJ_STR, 2))
+    assert_equal(SJIS_STR[2, 2],   c.iconv(EUCJ_STR, 2, 2))
+    assert_equal(SJIS_STR[2..-1],  c.iconv(EUCJ_STR, 2, 20))
+    assert_equal(SJIS_STR[-4..-1], c.iconv(EUCJ_STR, -4))
+    assert_equal(SJIS_STR[-4, 2],  c.iconv(EUCJ_STR, -4, 2))
+    assert_equal(SJIS_STR[-4..-1], c.iconv(EUCJ_STR, -4, 20))
+    assert_equal("",               c.iconv(EUCJ_STR, 20))
+    assert_equal("",               c.iconv(EUCJ_STR, 20, 2))
+  ensure
+    c.close
+  end
+end if defined?(::Iconv)

Property changes on: test/iconv/test_partial.rb
___________________________________________________________________
Name: svn:eol-style
   + LF

Index: ruby_1_8/test/iconv/test_simple.rb
===================================================================
--- ruby_1_8/test/iconv/test_simple.rb	(revision 16832)
+++ ruby_1_8/test/iconv/test_simple.rb	(revision 16833)
@@ -1,27 +0,0 @@
-require 'test/unit'
-begin
-  require 'iconv'
-rescue LoadError
-end
-
-class TestIConv < Test::Unit::TestCase
-  ASCII = "ascii"
-  def test_simple
-    c = Iconv.open(ASCII, ASCII)
-    ref = '[ruby-core:17092]'
-  rescue
-    return
-  else
-    assert_equal("abc", c.iconv("abc"))
-    assert_equal("c",   c.iconv("abc", 2),     "#{ref}: with start")
-    assert_equal("c",   c.iconv("abc", 2, 1),  "#{ref}: with start, length")
-    assert_equal("c",   c.iconv("abc", 2, 5),  "#{ref}: with start, longer length")
-    assert_equal("bc",  c.iconv("abc", -2),    "#{ref}: with nagative start")
-    assert_equal("b",   c.iconv("abc", -2, 1), "#{ref}: with nagative start, length")
-    assert_equal("bc",  c.iconv("abc", -2, 5), "#{ref}: with nagative start, longer length")
-    assert_equal("",    c.iconv("abc", 5),     "#{ref}: with OOB")
-    assert_equal("",    c.iconv("abc", 5, 2),  "#{ref}: with OOB, length")
-  ensure
-    c.close if c
-  end
-end if defined?(::Iconv)
Index: ruby_1_8/test/iconv/test_basic.rb
===================================================================
--- ruby_1_8/test/iconv/test_basic.rb	(revision 0)
+++ ruby_1_8/test/iconv/test_basic.rb	(revision 16833)
@@ -0,0 +1,49 @@
+require File.join(File.dirname(__FILE__), "utils.rb")
+
+class TestIconv
+  def test_euc2sjis
+    iconv = Iconv.open('SHIFT_JIS', 'EUC-JP')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+  end
+
+  def test_close
+    iconv = Iconv.new('Shift_JIS', 'EUC-JP')
+    output = ""
+    begin
+      output += iconv.iconv(EUCJ_STR)
+      output += iconv.iconv(nil)
+    ensure
+      assert_respond_to(iconv, :close)
+      assert_equal("", iconv.close)
+      assert_equal(SJIS_STR, output)
+    end
+  end
+
+  def test_open_without_block
+    assert_respond_to(Iconv, :open)
+    iconv = Iconv.open('SHIFT_JIS', 'EUC-JP')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str )
+    iconv.close
+  end
+
+  def test_open_with_block
+    input = "#{EUCJ_STR}\n"*2
+    output = ""
+    Iconv.open("Shift_JIS", "EUC-JP") do |cd|
+      input.each_line do |s|
+        output << cd.iconv(s)
+      end
+      output << cd.iconv(nil)
+    end
+    assert_equal("#{SJIS_STR}\n"*2, output)
+  end
+
+  def test_unknown_encoding
+    assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") }
+  end
+end

Property changes on: ruby_1_8/test/iconv/test_basic.rb
___________________________________________________________________
Name: svn:eol-style
   + LF

Index: ruby_1_8/test/iconv/utils.rb
===================================================================
--- ruby_1_8/test/iconv/utils.rb	(revision 0)
+++ ruby_1_8/test/iconv/utils.rb	(revision 16833)
@@ -0,0 +1,22 @@
+begin
+  require 'iconv'
+rescue LoadError
+else
+  require 'test/unit'
+end
+
+class TestIconv < Test::Unit::TestCase
+  if defined?(::Encoding) and String.method_defined?(:force_encoding)
+    def self.encode(str, enc)
+      str.force_encoding(enc)
+    end
+  else
+    def self.encode(str, enc)
+      str
+    end
+  end
+
+  ASCII = "ascii"
+  EUCJ_STR = encode("\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa", "EUC-JP").freeze
+  SJIS_STR = encode("\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8", "Shift_JIS").freeze
+end if defined?(::Iconv)

Property changes on: ruby_1_8/test/iconv/utils.rb
___________________________________________________________________
Name: svn:eol-style
   + LF

Index: ruby_1_8/test/iconv/test_option.rb
===================================================================
--- ruby_1_8/test/iconv/test_option.rb	(revision 0)
+++ ruby_1_8/test/iconv/test_option.rb	(revision 16833)
@@ -0,0 +1,31 @@
+require File.join(File.dirname(__FILE__), "utils.rb")
+
+class TestIconv
+  def test_ignore_option
+    iconv = Iconv.new('SHIFT_JIS', 'EUC-JP//ignore')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+
+    iconv = Iconv.new('SHIFT_JIS//IGNORE', 'EUC-JP//ignore')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+  end
+
+  def test_translit_option
+    iconv = Iconv.new('SHIFT_JIS', 'EUC-JP//ignore')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+
+    iconv = Iconv.new('SHIFT_JIS//TRANSLIT', 'EUC-JP//translit//ignore')
+    str = iconv.iconv(EUCJ_STR)
+    str << iconv.iconv(nil)
+    assert_equal(SJIS_STR, str)
+    iconv.close
+  end
+end if defined?(::Iconv)

Property changes on: ruby_1_8/test/iconv/test_option.rb
___________________________________________________________________
Name: svn:eol-style
   + LF

Index: ruby_1_8/test/iconv/test_partial.rb
===================================================================
--- ruby_1_8/test/iconv/test_partial.rb	(revision 0)
+++ ruby_1_8/test/iconv/test_partial.rb	(revision 16833)
@@ -0,0 +1,41 @@
+require File.join(File.dirname(__FILE__), "utils.rb")
+
+class TestIconv
+  def test_partial_ascii
+    c = Iconv.open(ASCII, ASCII)
+    ref = '[ruby-core:17092]'
+  rescue
+    return
+  else
+    assert_equal("abc", c.iconv("abc"))
+    assert_equal("c",   c.iconv("abc", 2),     "#{ref}: with start")
+    assert_equal("c",   c.iconv("abc", 2, 1),  "#{ref}: with start, length")
+    assert_equal("c",   c.iconv("abc", 2, 5),  "#{ref}: with start, longer length")
+    assert_equal("bc",  c.iconv("abc", -2),    "#{ref}: with nagative start")
+    assert_equal("b",   c.iconv("abc", -2, 1), "#{ref}: with nagative start, length")
+    assert_equal("bc",  c.iconv("abc", -2, 5), "#{ref}: with nagative start, longer length")
+    assert_equal("",    c.iconv("abc", 5),     "#{ref}: with OOB")
+    assert_equal("",    c.iconv("abc", 5, 2),  "#{ref}: with OOB, length")
+  ensure
+    c.close if c
+  end
+
+  def test_partial_euc2sjis
+    c = Iconv.open('SHIFT_JIS', 'EUC-JP')
+  rescue
+    return
+  else
+    assert_equal(SJIS_STR[0, 2],   c.iconv(EUCJ_STR, 0, 2))
+    assert_equal(SJIS_STR,         c.iconv(EUCJ_STR, 0, 20))
+    assert_equal(SJIS_STR[2..-1],  c.iconv(EUCJ_STR, 2))
+    assert_equal(SJIS_STR[2, 2],   c.iconv(EUCJ_STR, 2, 2))
+    assert_equal(SJIS_STR[2..-1],  c.iconv(EUCJ_STR, 2, 20))
+    assert_equal(SJIS_STR[-4..-1], c.iconv(EUCJ_STR, -4))
+    assert_equal(SJIS_STR[-4, 2],  c.iconv(EUCJ_STR, -4, 2))
+    assert_equal(SJIS_STR[-4..-1], c.iconv(EUCJ_STR, -4, 20))
+    assert_equal("",               c.iconv(EUCJ_STR, 20))
+    assert_equal("",               c.iconv(EUCJ_STR, 20, 2))
+  ensure
+    c.close
+  end
+end if defined?(::Iconv)

Property changes on: ruby_1_8/test/iconv/test_partial.rb
___________________________________________________________________
Name: svn:eol-style
   + LF


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]