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

ruby-changes:3046

From: ko1@a...
Date: 24 Dec 2007 02:05:51 +0900
Subject: [ruby-changes:3046] akr - Ruby:r14538 (trunk): add test for IO.pipe.

akr	2007-12-24 02:05:40 +0900 (Mon, 24 Dec 2007)

  New Revision: 14538

  Modified files:
    trunk/test/ruby/test_io_m17n.rb

  Log:
    add test for IO.pipe.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_io_m17n.rb?r1=14538&r2=14537

Index: test/ruby/test_io_m17n.rb
===================================================================
--- test/ruby/test_io_m17n.rb	(revision 14537)
+++ test/ruby/test_io_m17n.rb	(revision 14538)
@@ -2,13 +2,31 @@
 require 'tmpdir'
 
 class TestIO_M17N < Test::Unit::TestCase
+  ENCS = [
+    Encoding::ASCII_8BIT,
+    Encoding::EUC_JP,
+    Encoding::Shift_JIS,
+    Encoding::UTF_8
+  ]
+
   def with_tmpdir
     Dir.mktmpdir {|dir|
-      Dir.chdir dir
-      yield dir
+      Dir.chdir(dir) {
+        yield dir
+      }
     }
   end
 
+  def with_pipe(enc=nil)
+    r, w = IO.pipe(enc)
+    begin
+      yield r, w
+    ensure
+      r.close if !r.closed?
+      w.close if !w.closed?
+    end
+  end
+
   def generate_file(path, content)
     open(path, "wb") {|f| f.write content }
   end
@@ -39,12 +57,7 @@
     with_tmpdir {
       src = "abc\n"
       generate_file('tmp', "abc\n")
-      [
-        Encoding::ASCII_8BIT,
-        Encoding::EUC_JP,
-        Encoding::Shift_JIS,
-        Encoding::UTF_8
-      ].each {|enc|
+      ENCS.each {|enc|
         s = open('tmp', "r:#{enc}") {|f| f.gets }
         assert_equal(enc, s.encoding)
         assert_str_equal(src, s)
@@ -56,12 +69,7 @@
     with_tmpdir {
       src = "\xc2\xa1\n"
       generate_file('tmp', src)
-      [
-        Encoding::ASCII_8BIT,
-        Encoding::EUC_JP,
-        Encoding::Shift_JIS,
-        Encoding::UTF_8
-      ].each {|enc|
+      ENCS.each {|enc|
         content = src.dup.force_encoding(enc)
         s = open('tmp', "r:#{enc}") {|f| f.gets }
         assert_equal(enc, s.encoding)
@@ -74,12 +82,7 @@
     with_tmpdir {
       src = "\xc2\xa1\n".force_encoding("ASCII-8BIT")
       generate_file('tmp', "\xc2\xa1\n")
-      [
-        Encoding::ASCII_8BIT,
-        Encoding::EUC_JP,
-        Encoding::Shift_JIS,
-        Encoding::UTF_8
-      ].each {|enc|
+      ENCS.each {|enc|
         content = src.dup.force_encoding(enc)
         open('tmp', "r:#{enc}") {|f|
           s = f.getc
@@ -140,25 +143,19 @@
 
   def test_write_noenc
     src = "\xc2\xa1\n"
-    encs = [
-      Encoding::ASCII_8BIT,
-      Encoding::EUC_JP,
-      Encoding::Shift_JIS,
-      Encoding::UTF_8
-    ]
     with_tmpdir {
       open('tmp', "w") {|f|
-        encs.each {|enc|
+        ENCS.each {|enc|
           f.write src.dup.force_encoding(enc)
         }
       }
       open('tmp', 'rb') {|f|
-        assert_equal(src*encs.length, f.read)
+        assert_equal(src*ENCS.length, f.read)
       }
     }
   end
 
-  def test_write_enc
+  def test_write_conversion
     utf8 = "\u6666"
     eucjp = "\xb3\xa2".force_encoding("EUC-JP")
     with_tmpdir {
@@ -174,5 +171,16 @@
     }
   end
 
+  def test_pipe
+    ENCS.each {|enc|
+      with_pipe(enc) {|r, w|
+        w << "\xc2\xa1"
+        w.close
+        s = r.getc 
+        assert_equal(enc, s.encoding)
+      }
+    }
+  end
+
 end
 

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

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