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

ruby-changes:14543

From: mame <ko1@a...>
Date: Sat, 23 Jan 2010 00:03:54 +0900 (JST)
Subject: [ruby-changes:14543] Ruby:r26379 (trunk): * test/ruby/test_array.rb: add a test for Array#rotate, rotate!.

mame	2010-01-23 00:03:32 +0900 (Sat, 23 Jan 2010)

  New Revision: 26379

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26379

  Log:
    * test/ruby/test_array.rb: add a test for Array#rotate, rotate!.
    
    * test/ruby/test_dir.rb, test/ruby/test_fnmatch.rb: add some tests
      (for coverage of dir.c).
    
    * test/ruby/test_enum.rb: add a test for Enumerable#minmax.
    
    * test/ruby/test_enumerator.rb: add some tests for Enumerator#inspect,
      Enumerator::Generator and Yielder.
    
    * test/ruby/test_env.rb: add a test for ENV#index.
    
    * test/ruby/test_exception.rb: add some tests (for coverage of
      error.c).
    
    * test/ruby/test_hash.rb: add a test for recursive check.
    
    * test/ruby/test_integer.rb: add a test for number of argument of
      Integer.
    
    * test/ruby/test_method.rb: add a test for define_method.
    
    * test/ruby/test_module.rb: add a test for constant of included
      module.
    
    * test/ruby/test_proc.rb: add a test for parameters with cfunc.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_array.rb
    trunk/test/ruby/test_dir.rb
    trunk/test/ruby/test_enum.rb
    trunk/test/ruby/test_enumerator.rb
    trunk/test/ruby/test_env.rb
    trunk/test/ruby/test_exception.rb
    trunk/test/ruby/test_fnmatch.rb
    trunk/test/ruby/test_hash.rb
    trunk/test/ruby/test_integer.rb
    trunk/test/ruby/test_method.rb
    trunk/test/ruby/test_module.rb
    trunk/test/ruby/test_proc.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26378)
+++ ChangeLog	(revision 26379)
@@ -1,3 +1,32 @@
+Fri Jan 22 23:54:04 2010  Yusuke Endoh  <mame@t...>
+
+	* test/ruby/test_array.rb: add a test for Array#rotate, rotate!.
+	
+	* test/ruby/test_dir.rb, test/ruby/test_fnmatch.rb: add some tests
+	  (for coverage of dir.c).
+
+	* test/ruby/test_enum.rb: add a test for Enumerable#minmax.
+
+	* test/ruby/test_enumerator.rb: add some tests for Enumerator#inspect,
+	  Enumerator::Generator and Yielder.
+	
+	* test/ruby/test_env.rb: add a test for ENV#index.
+
+	* test/ruby/test_exception.rb: add some tests (for coverage of
+	  error.c).
+
+	* test/ruby/test_hash.rb: add a test for recursive check.
+
+	* test/ruby/test_integer.rb: add a test for number of argument of
+	  Integer.
+
+	* test/ruby/test_method.rb: add a test for define_method.
+
+	* test/ruby/test_module.rb: add a test for constant of included
+	  module.
+
+	* test/ruby/test_proc.rb: add a test for parameters with cfunc.
+
 Fri Jan 22 23:50:03 2010  Yusuke Endoh  <mame@t...>
 
 	* test/ruby/test_regexp.rb, test/ruby/test_symbol.rb,
Index: test/ruby/test_fnmatch.rb
===================================================================
--- test/ruby/test_fnmatch.rb	(revision 26378)
+++ test/ruby/test_fnmatch.rb	(revision 26379)
@@ -79,6 +79,8 @@
     assert(File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD))
     assert(!File.fnmatch('[a-z]', 'D'))
     assert(File.fnmatch('[a-z]', 'D', File::FNM_CASEFOLD))
+    assert(!File.fnmatch('[abc]', 'B'))
+    assert(File.fnmatch('[abc]', 'B', File::FNM_CASEFOLD))
     # wildcard doesn't match '/' if FNM_PATHNAME is set
     assert(File.fnmatch('foo?boo', 'foo/boo'))
     assert(File.fnmatch('foo*', 'foo/boo'))
Index: test/ruby/test_enumerator.rb
===================================================================
--- test/ruby/test_enumerator.rb	(revision 26378)
+++ test/ruby/test_enumerator.rb	(revision 26379)
@@ -332,6 +332,46 @@
     assert_equal(10, exc.result)
   end
 
+  def test_inspect
+    e = (0..10).each_cons(2)
+    assert_equal("#<Enumerator: 0..10:each_cons(2)>", e.inspect)
 
+    e = Enumerator.new {|y| x = y.yield; 10 }
+    assert_match(/\A#<Enumerator: .*:each>/, e.inspect)
+
+    a = []
+    e = a.each_with_object(a)
+    a << e
+    assert_equal("#<Enumerator: [#<Enumerator: ...>]:each_with_object([#<Enumerator: ...>])>",
+		e.inspect)
+  end
+
+  def test_generator
+    # note: Enumerator::Generator is a class just for internal
+    g = Enumerator::Generator.new {|y| y << 1 << 2 << 3; :foo }
+    g2 = g.dup
+    a = []
+    assert_equal(:foo, g.each {|x| a << x })
+    assert_equal([1, 2, 3], a)
+    a = []
+    assert_equal(:foo, g2.each {|x| a << x })
+    assert_equal([1, 2, 3], a)
+  end
+
+  def test_yielder
+    # note: Enumerator::Yielder is a class just for internal
+    a = []
+    y = Enumerator::Yielder.new {|x| a << x }
+    assert_equal(y, y << 1 << 2 << 3)
+    assert_equal([1, 2, 3], a)
+
+    a = []
+    y = Enumerator::Yielder.new {|x| a << x }
+    assert_equal([1], y.yield(1))
+    assert_equal([1, 2], y.yield(2))
+    assert_equal([1, 2, 3], y.yield(3))
+
+    assert_raise(LocalJumpError) { Enumerator::Yielder.new }
+  end
 end
 
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 26378)
+++ test/ruby/test_module.rb	(revision 26379)
@@ -380,6 +380,25 @@
     Object.module_eval "WALTER = 99"
     c2 = Module.constants
     assert_equal([:WALTER], c2 - c1)
+
+    assert_equal([], Module.constants(true))
+    assert_equal([], Module.constants(false))
+
+    src = <<-INPUT
+      module M
+        WALTER = 99
+      end
+      class Module
+        include M
+      end
+      p Module.constants, Module.constants(true), Module.constants(false)
+    INPUT
+    assert_in_out_err([], src) do |out, err|
+      assert_equal([:BasicObject, :M], eval(out[0]).sort - Module.constants)
+      assert_equal("[:WALTER]", out[1])
+      assert_equal("[]", out[2])
+      assert_equal([], err)
+    end
   end
 
   module M1
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 26378)
+++ test/ruby/test_array.rb	(revision 26379)
@@ -1788,6 +1788,8 @@
     assert_equal([], a.rotate(-4))
     assert_equal([], a.rotate(13))
     assert_equal([], a.rotate(-13))
+    a = [1,2,3]
+    assert_raise(ArgumentError) { a.rotate(1, 1) }
   end
 
   def test_rotate!
@@ -1813,5 +1815,7 @@
     a = [].freeze
     e = assert_raise(RuntimeError) {a.rotate!}
     assert_match(/can't modify frozen array/, e.message)
+    a = [1,2,3]
+    assert_raise(ArgumentError) { a.rotate!(1, 1) }
   end
 end
Index: test/ruby/test_integer.rb
===================================================================
--- test/ruby/test_integer.rb	(revision 26378)
+++ test/ruby/test_integer.rb	(revision 26379)
@@ -84,6 +84,12 @@
     assert_raise(ArgumentError) { Integer("0x123", 10) }
     assert_raise(ArgumentError) { Integer(1234, 10) }
     assert_raise(ArgumentError) { Integer(12.34, 10) }
+    assert_raise(ArgumentError) { Integer(Object.new, 1) }
+
+    assert_raise(ArgumentError) { Integer(1, 1, 1) }
+
+    assert_equal(2 ** 50, Integer(2.0 ** 50))
+    assert_raise(TypeError) { Integer(nil) }
   end
 
   def test_int_p
@@ -192,9 +198,4 @@
     assert_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1))
     assert_equal(Bignum, (-1111_1111_1111_1111_1111_1111_1111_1111).round(-1).class)
   end
-
-  def test_Integer2
-    assert_equal(2 ** 50, Integer(2.0 ** 50))
-    assert_raise(TypeError) { Integer(nil) }
-  end
 end
Index: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 26378)
+++ test/ruby/test_proc.rb	(revision 26379)
@@ -735,6 +735,10 @@
     assert_equal([[:req, :a], [:rest, :b], [:req, :c], [:block, :d]], method(:pmo6).to_proc.parameters)
     assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]], method(:pmo7).to_proc.parameters)
     assert_equal([[:req], [:block, :b]], method(:pma1).to_proc.parameters)
+
+    assert_equal([], "".method(:upcase).to_proc.parameters)
+    assert_equal([[:rest]], "".method(:gsub).to_proc.parameters)
+    assert_equal([[:rest]], proc {}.curry.parameters)
   end
 
   def test_to_s
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 26378)
+++ test/ruby/test_enum.rb	(revision 26379)
@@ -166,6 +166,7 @@
     assert_equal(["dog", "albatross"], a.minmax {|a,b| a.length <=> b.length })
     assert_equal([1, 3], [2,3,1].minmax)
     assert_equal([3, 1], [2,3,1].minmax {|a,b| b <=> a })
+    assert_equal([1, 3], [2,2,3,3,1,1].minmax)
   end
 
   def test_min_by
Index: test/ruby/test_dir.rb
===================================================================
--- test/ruby/test_dir.rb	(revision 26378)
+++ test/ruby/test_dir.rb	(revision 26379)
@@ -162,6 +162,9 @@
     assert_equal([], Dir.glob(File.join(@root, '[')))
     assert_equal([], Dir.glob(File.join(@root, '[a-\\')))
 
+    assert_equal([File.join(@root, "a")], Dir.glob(File.join(@root, 'a\\')))
+    assert_equal((?a..?f).map {|f| File.join(@root, f) }.sort, Dir.glob(File.join(@root, '[abc/def]')).sort)
+
     d = "\u{3042}\u{3044}".encode("utf-16le")
     assert_raise(Encoding::CompatibilityError) {Dir.glob(d)}
     m = Class.new {define_method(:to_path) {d}}
@@ -172,4 +175,42 @@
     assert_equal(Dir.foreach(@root).to_a.sort, %w(. ..) + (?a..?z).to_a)
   end
 
+  def test_dir_enc
+    dir = Dir.open(@root, encoding: "UTF-8")
+    begin
+      while name = dir.read
+	assert_equal(Encoding.find("UTF-8"), name.encoding)
+      end
+    ensure
+      dir.close
+    end
+
+    dir = Dir.open(@root, encoding: "ASCII-8BIT")
+    begin
+      while name = dir.read
+	assert_equal(Encoding.find("ASCII-8BIT"), name.encoding)
+      end
+    ensure
+      dir.close
+    end
+  end
+
+  def test_symlink
+    begin
+      [:dummy, *?a..?z].each do |f|
+	File.symlink(File.join(@root, f),
+		     File.join(@root, "symlink-#{ f }"))
+      end
+    rescue NotImplementedError
+      return
+    end
+
+    assert_equal([*?a..?z, *"symlink-a".."symlink-z"].each_slice(2).map {|f, _| File.join(@root, f + "/") }.sort,
+		 Dir.glob(File.join(@root, "*/")).sort)
+
+    puts("1");
+    Dir.glob(File.join(@root, "**/"))
+    puts("2");
+  end
+
 end
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 26378)
+++ test/ruby/test_method.rb	(revision 26379)
@@ -179,6 +179,10 @@
     o = Object.new
     o.instance_eval { define_singleton_method(:foo) { :foo } }
     assert_equal(:foo, o.foo)
+
+    assert_raise(TypeError) do
+      Class.new.class_eval { define_method(:foo, Object.new) }
+    end
   end
 
   def test_clone
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 26378)
+++ test/ruby/test_hash.rb	(revision 26379)
@@ -875,4 +875,9 @@
   def test_hash_poped
     assert_nothing_raised { eval("a = 1; {a => a}; a") }
   end
+
+  def test_recursive_check
+    h = {}
+    assert_raise(ArgumentError) { h[h] = :foo }
+  end
 end
Index: test/ruby/test_env.rb
===================================================================
--- test/ruby/test_env.rb	(revision 26378)
+++ test/ruby/test_env.rb	(revision 26379)
@@ -68,6 +68,7 @@
     ENV['test'] = val[0...-1]
 
     assert_nil(ENV.key(val))
+    assert_nil(ENV.index(val))
     assert_nil(ENV.key(val.upcase))
     ENV['test'] = val
     if IGNORE_CASE
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 26378)
+++ test/ruby/test_exception.rb	(revision 26379)
@@ -255,4 +255,53 @@
     RUBY
     assert_not_match(/:0/, stderr, "[ruby-dev:39116]")
   end
+
+  def test_errinfo
+    begin
+      raise "foo"
+      assert(false)
+    rescue => e
+      assert_equal(e, $!)
+      1.times { assert_equal(e, $!) }
+    end
+
+    assert_equal(nil, $!)
+  end
+
+  def test_inspect
+    assert_equal("#<Exception: Exception>", Exception.new.inspect)
+
+    e = Class.new(Exception)
+    e.class_eval do
+      def to_s; ""; end
+    end
+    assert_equal(e.inspect, e.new.inspect)
+  end
+
+  def test_set_backtrace
+    e = Exception.new
+
+    e.set_backtrace("foo")
+    assert_equal(["foo"], e.backtrace)
+
+    e.set_backtrace(%w(foo bar baz))
+    assert_equal(%w(foo bar baz), e.backtrace)
+
+    assert_raise(TypeError) { e.set_backtrace(1) }
+    assert_raise(TypeError) { e.set_backtrace([1]) }
+  end
+
+  def test_exit_success_p
+    begin
+      exit
+    rescue SystemExit => e
+    end
+    assert(e.success?)
+
+    begin
+      abort
+    rescue SystemExit => e
+    end
+    assert(!e.success?)
+  end
 end

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

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