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

ruby-changes:4179

From: ko1@a...
Date: Sun, 2 Mar 2008 01:17:15 +0900 (JST)
Subject: [ruby-changes:4179] akr - Ruby:r15669 (trunk): add tests.

akr	2008-03-02 01:16:46 +0900 (Sun, 02 Mar 2008)

  New Revision: 15669

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

  Log:
    add tests.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/ruby/test_literal.rb?r1=15669&r2=15668&diff_format=u

Index: test/ruby/test_literal.rb
===================================================================
--- test/ruby/test_literal.rb	(revision 15668)
+++ test/ruby/test_literal.rb	(revision 15669)
@@ -184,4 +184,58 @@
     assert_equal __LINE__, __LINE__
   end
 
+  def test_integer
+    head = ['', '0x', '0o', '0b', '0d', '-', '+']
+    chars = ['0', '1', '_', '9', 'f']
+    head.each {|h|
+      4.times {|len|
+        a = [h]
+        len.times { a = a.product(chars).map {|x| x.join('') } }
+        a.each {|s|
+          next if s.empty?
+          begin
+            r1 = Integer(s)
+          rescue ArgumentError
+            r1 = :err
+          end
+          begin
+            r2 = eval(s)
+          rescue NameError, SyntaxError
+            r2 = :err
+          end
+          assert_equal(r1, r2, "Integer(#{s.inspect}) != eval(#{s.inspect})")
+        }
+      }
+    }
+  end
+
+  def test_float
+    head = ['', '-', '+']
+    chars = ['0', '1', '_', '9', 'f', '.']
+    head.each {|h|
+      6.times {|len|
+        a = [h]
+        len.times { a = a.product(chars).map {|x| x.join('') } }
+        a.each {|s|
+          next if s.empty?
+          next if /\.\z/ =~ s
+          next if /\A[-+]?\./ =~ s
+          next if /\A[-+]?0/ =~ s
+          begin
+            r1 = Float(s)
+          rescue ArgumentError
+            r1 = :err
+          end
+          begin
+            r2 = eval(s)
+          rescue NameError, SyntaxError
+            r2 = :err
+          end
+          r2 = :err if Range === r2
+          assert_equal(r1, r2, "Float(#{s.inspect}) != eval(#{s.inspect})")
+        }
+      }
+    }
+  end
+
 end

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

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