mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Avoid defining the same test class in multiple files
Should fix issues with parallel testing sometimes not running all tests. This should be viewed skipping whitespace changes. Fixes [Bug #18731]
This commit is contained in:
		
							parent
							
								
									c2d38a0d2d
								
							
						
					
					
						commit
						ab3cb29bd9
					
				
				
				Notes:
				
					git
				
				2022-04-23 07:00:43 +09:00 
				
			
			
			
		
		
					 47 changed files with 1282 additions and 1358 deletions
				
			
		| 
						 | 
				
			
			@ -2,29 +2,27 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require "-test-/bignum"
 | 
			
		||||
 | 
			
		||||
class Test_Bignum < Test::Unit::TestCase
 | 
			
		||||
  class TestBig2str < Test::Unit::TestCase
 | 
			
		||||
class TestBignum_Big2str < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
    SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
 | 
			
		||||
    BITSPERDIG = Bug::Bignum::BITSPERDIG
 | 
			
		||||
    BDIGMAX = (1 << BITSPERDIG) - 1
 | 
			
		||||
 | 
			
		||||
    def test_big2str_generic
 | 
			
		||||
      x = 10**1000
 | 
			
		||||
      assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_generic(x, 10))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_big2str_poweroftwo
 | 
			
		||||
      e = BITSPERDIG*2
 | 
			
		||||
      x = 0b10**e
 | 
			
		||||
      assert_equal("1" + "0" * e, Bug::Bignum.big2str_poweroftwo(x, 2))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_big2str_gmp
 | 
			
		||||
      x = 10**1000
 | 
			
		||||
      assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_gmp(x, 10))
 | 
			
		||||
    rescue NotImplementedError
 | 
			
		||||
    end
 | 
			
		||||
  SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
 | 
			
		||||
  BITSPERDIG = Bug::Bignum::BITSPERDIG
 | 
			
		||||
  BDIGMAX = (1 << BITSPERDIG) - 1
 | 
			
		||||
 | 
			
		||||
  def test_big2str_generic
 | 
			
		||||
    x = 10**1000
 | 
			
		||||
    assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_generic(x, 10))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_big2str_poweroftwo
 | 
			
		||||
    e = BITSPERDIG*2
 | 
			
		||||
    x = 0b10**e
 | 
			
		||||
    assert_equal("1" + "0" * e, Bug::Bignum.big2str_poweroftwo(x, 2))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_big2str_gmp
 | 
			
		||||
    x = 10**1000
 | 
			
		||||
    assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_gmp(x, 10))
 | 
			
		||||
  rescue NotImplementedError
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,19 +2,17 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require "-test-/bignum"
 | 
			
		||||
 | 
			
		||||
class Test_Bignum < Test::Unit::TestCase
 | 
			
		||||
  class TestBigZero < Test::Unit::TestCase
 | 
			
		||||
    def test_equal_0
 | 
			
		||||
      bug8204 = '[ruby-core:53893] [Bug #8204]'
 | 
			
		||||
      (0..10).each do |i|
 | 
			
		||||
        assert_equal(0, Bug::Bignum.zero(i), "#{bug8204} Bignum.zero(#{i})")
 | 
			
		||||
      end
 | 
			
		||||
class TestBignum_BigZero < Test::Unit::TestCase
 | 
			
		||||
  def test_equal_0
 | 
			
		||||
    bug8204 = '[ruby-core:53893] [Bug #8204]'
 | 
			
		||||
    (0..10).each do |i|
 | 
			
		||||
      assert_equal(0, Bug::Bignum.zero(i), "#{bug8204} Bignum.zero(#{i})")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_zero?
 | 
			
		||||
      (0..10).each do |i|
 | 
			
		||||
        assert_equal(true, Bug::Bignum.zero(i).zero?)
 | 
			
		||||
      end
 | 
			
		||||
  def test_zero?
 | 
			
		||||
    (0..10).each do |i|
 | 
			
		||||
      assert_equal(true, Bug::Bignum.zero(i).zero?)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,28 +2,26 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require "-test-/bignum"
 | 
			
		||||
 | 
			
		||||
class Test_Bignum < Test::Unit::TestCase
 | 
			
		||||
  class TestDiv < Test::Unit::TestCase
 | 
			
		||||
class TestBignum_Div < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
    SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
 | 
			
		||||
    BITSPERDIG = Bug::Bignum::BITSPERDIG
 | 
			
		||||
    BDIGMAX = (1 << BITSPERDIG) - 1
 | 
			
		||||
  SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
 | 
			
		||||
  BITSPERDIG = Bug::Bignum::BITSPERDIG
 | 
			
		||||
  BDIGMAX = (1 << BITSPERDIG) - 1
 | 
			
		||||
 | 
			
		||||
    def test_divrem_normal
 | 
			
		||||
      x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
 | 
			
		||||
      y = (1 << BITSPERDIG) | 1
 | 
			
		||||
      q = (1 << BITSPERDIG) | 1
 | 
			
		||||
      r = 2
 | 
			
		||||
      assert_equal([q, r], Bug::Bignum.big_divrem_normal(x, y))
 | 
			
		||||
    end
 | 
			
		||||
  def test_divrem_normal
 | 
			
		||||
    x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
 | 
			
		||||
    y = (1 << BITSPERDIG) | 1
 | 
			
		||||
    q = (1 << BITSPERDIG) | 1
 | 
			
		||||
    r = 2
 | 
			
		||||
    assert_equal([q, r], Bug::Bignum.big_divrem_normal(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_divrem_gmp
 | 
			
		||||
      x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
 | 
			
		||||
      y = (1 << BITSPERDIG) | 1
 | 
			
		||||
      q = (1 << BITSPERDIG) | 1
 | 
			
		||||
      r = 2
 | 
			
		||||
      assert_equal([q, r], Bug::Bignum.big_divrem_gmp(x, y))
 | 
			
		||||
    rescue NotImplementedError
 | 
			
		||||
    end
 | 
			
		||||
  def test_divrem_gmp
 | 
			
		||||
    x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
 | 
			
		||||
    y = (1 << BITSPERDIG) | 1
 | 
			
		||||
    q = (1 << BITSPERDIG) | 1
 | 
			
		||||
    r = 2
 | 
			
		||||
    assert_equal([q, r], Bug::Bignum.big_divrem_gmp(x, y))
 | 
			
		||||
  rescue NotImplementedError
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,137 +2,135 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require "-test-/bignum"
 | 
			
		||||
 | 
			
		||||
class Test_Bignum < Test::Unit::TestCase
 | 
			
		||||
  class TestMul < Test::Unit::TestCase
 | 
			
		||||
class TestBignum_Mul < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
    SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
 | 
			
		||||
    BITSPERDIG = Bug::Bignum::BITSPERDIG
 | 
			
		||||
    BDIGMAX = (1 << BITSPERDIG) - 1
 | 
			
		||||
 | 
			
		||||
    def test_mul_normal
 | 
			
		||||
      x = (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << BITSPERDIG) | 1
 | 
			
		||||
      z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_normal_zero_in_x
 | 
			
		||||
      x = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
      y = (1 << BITSPERDIG) | 1
 | 
			
		||||
      z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_normal_zero_in_y
 | 
			
		||||
      x = (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
      z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_normal_max_max
 | 
			
		||||
      x = (1 << (2*BITSPERDIG)) - 1
 | 
			
		||||
      y = (1 << (2*BITSPERDIG)) - 1
 | 
			
		||||
      z = (1 << (4*BITSPERDIG)) - (1 << (2*BITSPERDIG+1)) + 1
 | 
			
		||||
      assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_sq_fast
 | 
			
		||||
      x = (1 << BITSPERDIG) | 1
 | 
			
		||||
      z = (1 << 2*BITSPERDIG) | (2 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(z, Bug::Bignum.big_sq_fast(x))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_sq_fast_max2
 | 
			
		||||
      x = (BDIGMAX << BITSPERDIG) | BDIGMAX
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_sq_fast_zero_in_middle
 | 
			
		||||
      x = (BDIGMAX << 2*BITSPERDIG) | BDIGMAX
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_balance
 | 
			
		||||
      x = (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << BITSPERDIG) | 1
 | 
			
		||||
      z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(z, Bug::Bignum.big_mul_balance(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_balance_2x16
 | 
			
		||||
      x = (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << BITSPERDIG*16) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_balance_2x17
 | 
			
		||||
      x = (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << BITSPERDIG*17) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_karatsuba
 | 
			
		||||
      x = (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << BITSPERDIG) | 1
 | 
			
		||||
      z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(z, Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_karatsuba_odd_y
 | 
			
		||||
      x = (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_karatsuba_odd_xy
 | 
			
		||||
      x = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
      y = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_karatsuba_x1_gt_x0
 | 
			
		||||
      x = (2 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << BITSPERDIG) | 2
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_karatsuba_y1_gt_y0
 | 
			
		||||
      x = (1 << BITSPERDIG) | 2
 | 
			
		||||
      y = (2 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_karatsuba_x1_gt_x0_and_y1_gt_y0
 | 
			
		||||
      x = (2 << BITSPERDIG) | 1
 | 
			
		||||
      y = (2 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_karatsuba_carry2
 | 
			
		||||
      x = (1 << BITSPERDIG) | BDIGMAX
 | 
			
		||||
      y = (1 << BITSPERDIG) | BDIGMAX
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_karatsuba_borrow
 | 
			
		||||
      x = (BDIGMAX << BITSPERDIG) | 1
 | 
			
		||||
      y = (BDIGMAX << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_toom3
 | 
			
		||||
      x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_toom3(x, y))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_mul_gmp
 | 
			
		||||
      x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
 | 
			
		||||
      y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
 | 
			
		||||
      assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_gmp(x, y))
 | 
			
		||||
    rescue NotImplementedError
 | 
			
		||||
    end
 | 
			
		||||
  SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
 | 
			
		||||
  BITSPERDIG = Bug::Bignum::BITSPERDIG
 | 
			
		||||
  BDIGMAX = (1 << BITSPERDIG) - 1
 | 
			
		||||
 | 
			
		||||
  def test_mul_normal
 | 
			
		||||
    x = (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << BITSPERDIG) | 1
 | 
			
		||||
    z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_normal_zero_in_x
 | 
			
		||||
    x = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
    y = (1 << BITSPERDIG) | 1
 | 
			
		||||
    z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_normal_zero_in_y
 | 
			
		||||
    x = (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
    z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_normal_max_max
 | 
			
		||||
    x = (1 << (2*BITSPERDIG)) - 1
 | 
			
		||||
    y = (1 << (2*BITSPERDIG)) - 1
 | 
			
		||||
    z = (1 << (4*BITSPERDIG)) - (1 << (2*BITSPERDIG+1)) + 1
 | 
			
		||||
    assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_sq_fast
 | 
			
		||||
    x = (1 << BITSPERDIG) | 1
 | 
			
		||||
    z = (1 << 2*BITSPERDIG) | (2 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(z, Bug::Bignum.big_sq_fast(x))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_sq_fast_max2
 | 
			
		||||
    x = (BDIGMAX << BITSPERDIG) | BDIGMAX
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_sq_fast_zero_in_middle
 | 
			
		||||
    x = (BDIGMAX << 2*BITSPERDIG) | BDIGMAX
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_balance
 | 
			
		||||
    x = (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << BITSPERDIG) | 1
 | 
			
		||||
    z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(z, Bug::Bignum.big_mul_balance(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_balance_2x16
 | 
			
		||||
    x = (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << BITSPERDIG*16) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_balance_2x17
 | 
			
		||||
    x = (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << BITSPERDIG*17) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_karatsuba
 | 
			
		||||
    x = (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << BITSPERDIG) | 1
 | 
			
		||||
    z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(z, Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_karatsuba_odd_y
 | 
			
		||||
    x = (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_karatsuba_odd_xy
 | 
			
		||||
    x = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
    y = (1 << (2*BITSPERDIG)) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_karatsuba_x1_gt_x0
 | 
			
		||||
    x = (2 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << BITSPERDIG) | 2
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_karatsuba_y1_gt_y0
 | 
			
		||||
    x = (1 << BITSPERDIG) | 2
 | 
			
		||||
    y = (2 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_karatsuba_x1_gt_x0_and_y1_gt_y0
 | 
			
		||||
    x = (2 << BITSPERDIG) | 1
 | 
			
		||||
    y = (2 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_karatsuba_carry2
 | 
			
		||||
    x = (1 << BITSPERDIG) | BDIGMAX
 | 
			
		||||
    y = (1 << BITSPERDIG) | BDIGMAX
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_karatsuba_borrow
 | 
			
		||||
    x = (BDIGMAX << BITSPERDIG) | 1
 | 
			
		||||
    y = (BDIGMAX << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_toom3
 | 
			
		||||
    x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_toom3(x, y))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_mul_gmp
 | 
			
		||||
    x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
 | 
			
		||||
    y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
 | 
			
		||||
    assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_gmp(x, y))
 | 
			
		||||
  rescue NotImplementedError
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,348 +4,346 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require "-test-/bignum"
 | 
			
		||||
 | 
			
		||||
class Test_Bignum < Test::Unit::TestCase
 | 
			
		||||
  class TestPack < Test::Unit::TestCase
 | 
			
		||||
class TestBignum_Pack < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
    MSWORD_FIRST = Bug::Bignum::INTEGER_PACK_MSWORD_FIRST
 | 
			
		||||
    LSWORD_FIRST = Bug::Bignum::INTEGER_PACK_LSWORD_FIRST
 | 
			
		||||
    MSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_MSBYTE_FIRST
 | 
			
		||||
    LSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_LSBYTE_FIRST
 | 
			
		||||
    NATIVE_BYTE_ORDER = Bug::Bignum::INTEGER_PACK_NATIVE_BYTE_ORDER
 | 
			
		||||
    TWOCOMP = Bug::Bignum::INTEGER_PACK_2COMP
 | 
			
		||||
    LITTLE_ENDIAN = Bug::Bignum::INTEGER_PACK_LITTLE_ENDIAN
 | 
			
		||||
    BIG_ENDIAN = Bug::Bignum::INTEGER_PACK_BIG_ENDIAN
 | 
			
		||||
    NEGATIVE = Bug::Bignum::INTEGER_PACK_NEGATIVE
 | 
			
		||||
    GENERIC = Bug::Bignum::INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION
 | 
			
		||||
  MSWORD_FIRST = Bug::Bignum::INTEGER_PACK_MSWORD_FIRST
 | 
			
		||||
  LSWORD_FIRST = Bug::Bignum::INTEGER_PACK_LSWORD_FIRST
 | 
			
		||||
  MSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_MSBYTE_FIRST
 | 
			
		||||
  LSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_LSBYTE_FIRST
 | 
			
		||||
  NATIVE_BYTE_ORDER = Bug::Bignum::INTEGER_PACK_NATIVE_BYTE_ORDER
 | 
			
		||||
  TWOCOMP = Bug::Bignum::INTEGER_PACK_2COMP
 | 
			
		||||
  LITTLE_ENDIAN = Bug::Bignum::INTEGER_PACK_LITTLE_ENDIAN
 | 
			
		||||
  BIG_ENDIAN = Bug::Bignum::INTEGER_PACK_BIG_ENDIAN
 | 
			
		||||
  NEGATIVE = Bug::Bignum::INTEGER_PACK_NEGATIVE
 | 
			
		||||
  GENERIC = Bug::Bignum::INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION
 | 
			
		||||
 | 
			
		||||
    def test_pack_zero
 | 
			
		||||
      assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack_zero
 | 
			
		||||
    assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_argument_check
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 2, 1, 0, MSBYTE_FIRST) }
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 0, MSWORD_FIRST) }
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 0, 0, BIG_ENDIAN) }
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 8, BIG_ENDIAN) }
 | 
			
		||||
  def test_pack_argument_check
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 2, 1, 0, MSBYTE_FIRST) }
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 0, MSWORD_FIRST) }
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 0, 0, BIG_ENDIAN) }
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 8, BIG_ENDIAN) }
 | 
			
		||||
 | 
			
		||||
      # assume sizeof(ssize_t) == sizeof(intptr_t)
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
 | 
			
		||||
    end
 | 
			
		||||
    # assume sizeof(ssize_t) == sizeof(intptr_t)
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_wordsize
 | 
			
		||||
      assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(1, 1, 2, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x00\x00\x01"], Bug::Bignum.test_pack(1, 1, 3, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(1, 1, 2, 0, LITTLE_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x01\x00\x00"], Bug::Bignum.test_pack(1, 1, 3, 0, LITTLE_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack_wordsize
 | 
			
		||||
    assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(1, 1, 2, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x00\x00\x01"], Bug::Bignum.test_pack(1, 1, 3, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(1, 1, 2, 0, LITTLE_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x01\x00\x00"], Bug::Bignum.test_pack(1, 1, 3, 0, LITTLE_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_fixed_buffer
 | 
			
		||||
      assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(0x01, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x02\x01"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(0x01, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x01\x02"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
      assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
      assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack_fixed_buffer
 | 
			
		||||
    assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(0x01, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x02\x01"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(0x01, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x01\x02"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
    assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
    assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_wordorder_and_endian
 | 
			
		||||
      assert_equal([1, "\x12\x34\x56\x78"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal([1, "\x34\x12\x78\x56"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
 | 
			
		||||
      assert_equal([1, "\x56\x78\x12\x34"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal([1, "\x78\x56\x34\x12"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack_wordorder_and_endian
 | 
			
		||||
    assert_equal([1, "\x12\x34\x56\x78"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
 | 
			
		||||
    assert_equal([1, "\x34\x12\x78\x56"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
 | 
			
		||||
    assert_equal([1, "\x56\x78\x12\x34"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
 | 
			
		||||
    assert_equal([1, "\x78\x56\x34\x12"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_native_endian
 | 
			
		||||
      assert_equal([1, [0x1234].pack("S!")], Bug::Bignum.test_pack(0x1234, 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack_native_endian
 | 
			
		||||
    assert_equal([1, [0x1234].pack("S!")], Bug::Bignum.test_pack(0x1234, 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_nail
 | 
			
		||||
      assert_equal([1, "\x01\x00\x00\x00\x01\x01"], Bug::Bignum.test_pack(0b100011, 6, 1, 7, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08"], Bug::Bignum.test_pack(0x12345678, 8, 1, 4, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78"], Bug::Bignum.test_pack(0x12345678, 4, 2, 8, BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack_nail
 | 
			
		||||
    assert_equal([1, "\x01\x00\x00\x00\x01\x01"], Bug::Bignum.test_pack(0b100011, 6, 1, 7, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08"], Bug::Bignum.test_pack(0x12345678, 8, 1, 4, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78"], Bug::Bignum.test_pack(0x12345678, 4, 2, 8, BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_overflow
 | 
			
		||||
      assert_equal([-2, "\x1"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-2, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\xF"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
  def test_pack_overflow
 | 
			
		||||
    assert_equal([-2, "\x1"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-2, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\xF"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, BIG_ENDIAN))
 | 
			
		||||
 | 
			
		||||
      assert_equal([-2, "\x01"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-2, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-2, "\x01"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-2, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
 | 
			
		||||
      assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
 | 
			
		||||
 | 
			
		||||
      1.upto(16) {|wordsize|
 | 
			
		||||
        1.upto(20) {|numwords|
 | 
			
		||||
          w = numwords*wordsize
 | 
			
		||||
          n = 256**w
 | 
			
		||||
          assert_equal([-2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
          assert_equal([-2, "\x00"*w],            Bug::Bignum.test_pack((-n  ), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
          assert_equal([-1, "\xFF"*w],            Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
          assert_equal([+1, "\xFF"*w],            Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
          assert_equal([+2, "\x00"*w],            Bug::Bignum.test_pack((+n  ), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
          assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
        }
 | 
			
		||||
    1.upto(16) {|wordsize|
 | 
			
		||||
      1.upto(20) {|numwords|
 | 
			
		||||
        w = numwords*wordsize
 | 
			
		||||
        n = 256**w
 | 
			
		||||
        assert_equal([-2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
        assert_equal([-2, "\x00"*w],            Bug::Bignum.test_pack((-n  ), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
        assert_equal([-1, "\xFF"*w],            Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
        assert_equal([+1, "\xFF"*w],            Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
        assert_equal([+2, "\x00"*w],            Bug::Bignum.test_pack((+n  ), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
        assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, BIG_ENDIAN))
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
      1.upto(16) {|wordsize|
 | 
			
		||||
        1.upto(20) {|numwords|
 | 
			
		||||
          w = numwords*wordsize
 | 
			
		||||
          n = 256**w
 | 
			
		||||
          assert_equal([-2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([-2, "\x00"*w],            Bug::Bignum.test_pack((-n  ), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([-1, "\xFF"*w],            Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([+1, "\xFF"*w],            Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([+2, "\x00"*w],            Bug::Bignum.test_pack((+n  ), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
        }
 | 
			
		||||
    1.upto(16) {|wordsize|
 | 
			
		||||
      1.upto(20) {|numwords|
 | 
			
		||||
        w = numwords*wordsize
 | 
			
		||||
        n = 256**w
 | 
			
		||||
        assert_equal([-2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([-2, "\x00"*w],            Bug::Bignum.test_pack((-n  ), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([-1, "\xFF"*w],            Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([+1, "\xFF"*w],            Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([+2, "\x00"*w],            Bug::Bignum.test_pack((+n  ), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_sign
 | 
			
		||||
      assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-1), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10"], Bug::Bignum.test_pack((-0x8070605040302010), 8, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack_sign
 | 
			
		||||
    assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-1), 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10"], Bug::Bignum.test_pack((-0x8070605040302010), 8, 1, 0, BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack_orders
 | 
			
		||||
      [MSWORD_FIRST, LSWORD_FIRST].each {|word_order|
 | 
			
		||||
        [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order|
 | 
			
		||||
          1.upto(16) {|wordsize|
 | 
			
		||||
            1.upto(20) {|numwords|
 | 
			
		||||
              w = numwords*wordsize
 | 
			
		||||
              n = 0;
 | 
			
		||||
              0.upto(w) {|i|
 | 
			
		||||
                n |= ((i+1) % 256) << (i*8)
 | 
			
		||||
              }
 | 
			
		||||
              assert_equal(Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order|GENERIC),
 | 
			
		||||
                           Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order),
 | 
			
		||||
                          "#{'%#x' % n}.test_pack(#{numwords}, #{wordsize}, 0, #{'%#x' % (word_order|byte_order)})")
 | 
			
		||||
  def test_pack_orders
 | 
			
		||||
    [MSWORD_FIRST, LSWORD_FIRST].each {|word_order|
 | 
			
		||||
      [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order|
 | 
			
		||||
        1.upto(16) {|wordsize|
 | 
			
		||||
          1.upto(20) {|numwords|
 | 
			
		||||
            w = numwords*wordsize
 | 
			
		||||
            n = 0;
 | 
			
		||||
            0.upto(w) {|i|
 | 
			
		||||
              n |= ((i+1) % 256) << (i*8)
 | 
			
		||||
            }
 | 
			
		||||
            assert_equal(Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order|GENERIC),
 | 
			
		||||
                         Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order),
 | 
			
		||||
                        "#{'%#x' % n}.test_pack(#{numwords}, #{wordsize}, 0, #{'%#x' % (word_order|byte_order)})")
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack2comp_zero
 | 
			
		||||
      assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack2comp_zero
 | 
			
		||||
    assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack2comp_emptybuf
 | 
			
		||||
      assert_equal([-2, ""], Bug::Bignum.test_pack((-3), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-2, ""], Bug::Bignum.test_pack((-2), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, ""], Bug::Bignum.test_pack((-1), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([ 0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, ""], Bug::Bignum.test_pack(1, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, ""], Bug::Bignum.test_pack(2, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack2comp_emptybuf
 | 
			
		||||
    assert_equal([-2, ""], Bug::Bignum.test_pack((-3), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-2, ""], Bug::Bignum.test_pack((-2), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, ""], Bug::Bignum.test_pack((-1), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([ 0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, ""], Bug::Bignum.test_pack(1, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, ""], Bug::Bignum.test_pack(2, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack2comp_nearly_zero
 | 
			
		||||
      assert_equal([-1, "\xFE"], Bug::Bignum.test_pack((-2), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-1), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([ 0, "\x00"], Bug::Bignum.test_pack(0, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+1, "\x02"], Bug::Bignum.test_pack(2, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_pack2comp_nearly_zero
 | 
			
		||||
    assert_equal([-1, "\xFE"], Bug::Bignum.test_pack((-2), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-1), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([ 0, "\x00"], Bug::Bignum.test_pack(0, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+1, "\x02"], Bug::Bignum.test_pack(2, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_pack2comp_overflow
 | 
			
		||||
      assert_equal([-2, "\xF"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\x1"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
  def test_pack2comp_overflow
 | 
			
		||||
    assert_equal([-2, "\xF"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\x1"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
 | 
			
		||||
      assert_equal([-2, "\xFF"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-2, "\xFF"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
 | 
			
		||||
      assert_equal([-2, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-2, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
 | 
			
		||||
      1.upto(16) {|wordsize|
 | 
			
		||||
        1.upto(20) {|numwords|
 | 
			
		||||
          w = numwords*wordsize
 | 
			
		||||
          n = 256**w
 | 
			
		||||
          assert_equal([-2, "\xFF"*w           ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
          assert_equal([-1, "\x00"*w],            Bug::Bignum.test_pack((-n  ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
          assert_equal([-1, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
          assert_equal([+1, "\xFF"*w],            Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
          assert_equal([+2, "\x00"*w],            Bug::Bignum.test_pack((+n  ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
          assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
        }
 | 
			
		||||
    1.upto(16) {|wordsize|
 | 
			
		||||
      1.upto(20) {|numwords|
 | 
			
		||||
        w = numwords*wordsize
 | 
			
		||||
        n = 256**w
 | 
			
		||||
        assert_equal([-2, "\xFF"*w           ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
        assert_equal([-1, "\x00"*w],            Bug::Bignum.test_pack((-n  ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
        assert_equal([-1, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
        assert_equal([+1, "\xFF"*w],            Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
        assert_equal([+2, "\x00"*w],            Bug::Bignum.test_pack((+n  ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
        assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
      1.upto(16) {|wordsize|
 | 
			
		||||
        1.upto(20) {|numwords|
 | 
			
		||||
          w = numwords*wordsize
 | 
			
		||||
          n = 256**w
 | 
			
		||||
          assert_equal([-2, "\xFF"*w           ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([-1, "\x00"*w],            Bug::Bignum.test_pack((-n  ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([-1, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([+1, "\xFF"*w],            Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([+2, "\x00"*w],            Bug::Bignum.test_pack((+n  ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
          assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
        }
 | 
			
		||||
    1.upto(16) {|wordsize|
 | 
			
		||||
      1.upto(20) {|numwords|
 | 
			
		||||
        w = numwords*wordsize
 | 
			
		||||
        n = 256**w
 | 
			
		||||
        assert_equal([-2, "\xFF"*w           ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([-1, "\x00"*w],            Bug::Bignum.test_pack((-n  ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([-1, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([+1, "\xFF"*w],            Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([+2, "\x00"*w],            Bug::Bignum.test_pack((+n  ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
        assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
      2.upto(16) {|wordsize|
 | 
			
		||||
        w = wordsize
 | 
			
		||||
        b = 8*wordsize-1
 | 
			
		||||
        n = 2**b
 | 
			
		||||
        assert_equal([-2, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
        assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n  ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
        assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
        assert_equal([+1, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
        assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n  ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
        assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
      }
 | 
			
		||||
    2.upto(16) {|wordsize|
 | 
			
		||||
      w = wordsize
 | 
			
		||||
      b = 8*wordsize-1
 | 
			
		||||
      n = 2**b
 | 
			
		||||
      assert_equal([-2, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n  ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal([+1, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n  ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
      2.upto(16) {|wordsize|
 | 
			
		||||
        w = wordsize
 | 
			
		||||
        b = 8*wordsize-1
 | 
			
		||||
        n = 2**b
 | 
			
		||||
        assert_equal([-2, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
        assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n  ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
        assert_equal([-1, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
        assert_equal([+1, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
        assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n  ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
        assert_equal([+2, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
      }
 | 
			
		||||
    2.upto(16) {|wordsize|
 | 
			
		||||
      w = wordsize
 | 
			
		||||
      b = 8*wordsize-1
 | 
			
		||||
      n = 2**b
 | 
			
		||||
      assert_equal([-2, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
      assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n  ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
      assert_equal([-1, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
      assert_equal([+1, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
      assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n  ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
      assert_equal([+2, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack_zero
 | 
			
		||||
      assert_equal(0, Bug::Bignum.test_unpack("", 0, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack_zero
 | 
			
		||||
    assert_equal(0, Bug::Bignum.test_unpack("", 0, 1, 0, BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack_argument_check
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 2, 1, 0, MSBYTE_FIRST) }
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 0, MSWORD_FIRST) }
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 0, 0, BIG_ENDIAN) }
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 8, BIG_ENDIAN) }
 | 
			
		||||
  def test_unpack_argument_check
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 2, 1, 0, MSBYTE_FIRST) }
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 0, MSWORD_FIRST) }
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 0, 0, BIG_ENDIAN) }
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 8, BIG_ENDIAN) }
 | 
			
		||||
 | 
			
		||||
      # assume sizeof(ssize_t) == sizeof(intptr_t)
 | 
			
		||||
      assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
 | 
			
		||||
    end
 | 
			
		||||
    # assume sizeof(ssize_t) == sizeof(intptr_t)
 | 
			
		||||
    assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack_wordsize
 | 
			
		||||
      assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal(1, Bug::Bignum.test_unpack("\x00\x01", 1, 2, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal(1, Bug::Bignum.test_unpack("\x00\x00\x01", 1, 3, 0, BIG_ENDIAN))
 | 
			
		||||
      assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
      assert_equal(1, Bug::Bignum.test_unpack("\x01\x00", 1, 2, 0, LITTLE_ENDIAN))
 | 
			
		||||
      assert_equal(1, Bug::Bignum.test_unpack("\x01\x00\x00", 1, 3, 0, LITTLE_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack_wordsize
 | 
			
		||||
    assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal(1, Bug::Bignum.test_unpack("\x00\x01", 1, 2, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal(1, Bug::Bignum.test_unpack("\x00\x00\x01", 1, 3, 0, BIG_ENDIAN))
 | 
			
		||||
    assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, LITTLE_ENDIAN))
 | 
			
		||||
    assert_equal(1, Bug::Bignum.test_unpack("\x01\x00", 1, 2, 0, LITTLE_ENDIAN))
 | 
			
		||||
    assert_equal(1, Bug::Bignum.test_unpack("\x01\x00\x00", 1, 3, 0, LITTLE_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack_wordorder_and_endian
 | 
			
		||||
      assert_equal(0x01020304, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal(0x02010403, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
 | 
			
		||||
      assert_equal(0x03040102, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
 | 
			
		||||
      assert_equal(0x04030201, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack_wordorder_and_endian
 | 
			
		||||
    assert_equal(0x01020304, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
 | 
			
		||||
    assert_equal(0x02010403, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
 | 
			
		||||
    assert_equal(0x03040102, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
 | 
			
		||||
    assert_equal(0x04030201, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack_native_endian
 | 
			
		||||
      assert_equal("\x12\x34".unpack("S!")[0], Bug::Bignum.test_unpack("\x12\x34", 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack_native_endian
 | 
			
		||||
    assert_equal("\x12\x34".unpack("S!")[0], Bug::Bignum.test_unpack("\x12\x34", 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack_nail
 | 
			
		||||
      assert_equal(0b100011, Bug::Bignum.test_unpack("\x01\x00\x00\x00\x01\x01", 6, 1, 7, BIG_ENDIAN))
 | 
			
		||||
      assert_equal(0x12345678, Bug::Bignum.test_unpack("\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 4, BIG_ENDIAN))
 | 
			
		||||
      assert_equal(0x12345678, Bug::Bignum.test_unpack("\x00\x12\x00\x34\x00\x56\x00\x78", 4, 2, 8, BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack_nail
 | 
			
		||||
    assert_equal(0b100011, Bug::Bignum.test_unpack("\x01\x00\x00\x00\x01\x01", 6, 1, 7, BIG_ENDIAN))
 | 
			
		||||
    assert_equal(0x12345678, Bug::Bignum.test_unpack("\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 4, BIG_ENDIAN))
 | 
			
		||||
    assert_equal(0x12345678, Bug::Bignum.test_unpack("\x00\x12\x00\x34\x00\x56\x00\x78", 4, 2, 8, BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack_sign
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
      assert_equal(-0x8070605040302010, Bug::Bignum.test_unpack("\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 0, BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack_sign
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    assert_equal(-0x8070605040302010, Bug::Bignum.test_unpack("\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 0, BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack_orders
 | 
			
		||||
      [MSWORD_FIRST, LSWORD_FIRST].each {|word_order|
 | 
			
		||||
        [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order|
 | 
			
		||||
          1.upto(16) {|wordsize|
 | 
			
		||||
            1.upto(20) {|numwords|
 | 
			
		||||
              w = numwords*wordsize
 | 
			
		||||
              ary = []
 | 
			
		||||
              0.upto(w) {|i|
 | 
			
		||||
                ary << ((i+1) % 256);
 | 
			
		||||
              }
 | 
			
		||||
              str = ary.pack("C*")
 | 
			
		||||
              flags = word_order|byte_order
 | 
			
		||||
              assert_equal(Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags|GENERIC),
 | 
			
		||||
                           Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags),
 | 
			
		||||
                          "Bug::Bignum.test_unpack(#{str.dump}, #{numwords}, #{wordsize}, 0, #{'%#x' % flags})")
 | 
			
		||||
  def test_unpack_orders
 | 
			
		||||
    [MSWORD_FIRST, LSWORD_FIRST].each {|word_order|
 | 
			
		||||
      [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order|
 | 
			
		||||
        1.upto(16) {|wordsize|
 | 
			
		||||
          1.upto(20) {|numwords|
 | 
			
		||||
            w = numwords*wordsize
 | 
			
		||||
            ary = []
 | 
			
		||||
            0.upto(w) {|i|
 | 
			
		||||
              ary << ((i+1) % 256);
 | 
			
		||||
            }
 | 
			
		||||
            str = ary.pack("C*")
 | 
			
		||||
            flags = word_order|byte_order
 | 
			
		||||
            assert_equal(Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags|GENERIC),
 | 
			
		||||
                         Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags),
 | 
			
		||||
                        "Bug::Bignum.test_unpack(#{str.dump}, #{numwords}, #{wordsize}, 0, #{'%#x' % flags})")
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack2comp_single_byte
 | 
			
		||||
      assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(  -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(  -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(   0, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(   1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(   2, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal( 127, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack2comp_single_byte
 | 
			
		||||
    assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(  -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(  -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(   0, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(   1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(   2, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal( 127, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack2comp_sequence_of_ff
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*2, 2, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*3, 3, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*4, 4, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*5, 5, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*6, 6, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*7, 7, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*8, 8, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
      assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*9, 9, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack2comp_sequence_of_ff
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*2, 2, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*3, 3, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*4, 4, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*5, 5, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*6, 6, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*7, 7, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*8, 8, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
    assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*9, 9, 1, 0, TWOCOMP|BIG_ENDIAN))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack2comp_negative_single_byte
 | 
			
		||||
      assert_equal(-256, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
      assert_equal(-255, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
      assert_equal(-254, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
      assert_equal(-129, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
      assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
      assert_equal(  -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
      assert_equal(  -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack2comp_negative_single_byte
 | 
			
		||||
    assert_equal(-256, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    assert_equal(-255, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    assert_equal(-254, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    assert_equal(-129, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    assert_equal(  -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
    assert_equal(  -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_unpack2comp_negative_zero
 | 
			
		||||
      0.upto(100) {|n|
 | 
			
		||||
        str = "\x00"*n
 | 
			
		||||
        flags = TWOCOMP|BIG_ENDIAN|NEGATIVE
 | 
			
		||||
        assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags))
 | 
			
		||||
        flags = TWOCOMP|LITTLE_ENDIAN|NEGATIVE
 | 
			
		||||
        assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags),
 | 
			
		||||
                    "Bug::Bignum.test_unpack(#{str.dump}, #{n}, 1, 0, #{'%#x' % flags})")
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
  def test_unpack2comp_negative_zero
 | 
			
		||||
    0.upto(100) {|n|
 | 
			
		||||
      str = "\x00"*n
 | 
			
		||||
      flags = TWOCOMP|BIG_ENDIAN|NEGATIVE
 | 
			
		||||
      assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags))
 | 
			
		||||
      flags = TWOCOMP|LITTLE_ENDIAN|NEGATIVE
 | 
			
		||||
      assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags),
 | 
			
		||||
                  "Bug::Bignum.test_unpack(#{str.dump}, #{n}, 1, 0, #{'%#x' % flags})")
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_numbits_2comp
 | 
			
		||||
| 
						 | 
				
			
			@ -395,5 +393,4 @@ class Test_Bignum < Test::Unit::TestCase
 | 
			
		|||
    assert_equal(5, Bug::Bignum.test_numbytes_2comp_with_sign(0x7fffffffff))
 | 
			
		||||
    assert_equal(6, Bug::Bignum.test_numbytes_2comp_with_sign(0x8000000000))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,37 +2,35 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require "-test-/bignum"
 | 
			
		||||
 | 
			
		||||
class Test_Bignum < Test::Unit::TestCase
 | 
			
		||||
  class TestStr2big < Test::Unit::TestCase
 | 
			
		||||
class TestBignum_Str2big < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
    SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
 | 
			
		||||
    BITSPERDIG = Bug::Bignum::BITSPERDIG
 | 
			
		||||
    BDIGMAX = (1 << BITSPERDIG) - 1
 | 
			
		||||
 | 
			
		||||
    def test_str2big_poweroftwo
 | 
			
		||||
      s = "1" + "0" * 1000
 | 
			
		||||
      n = 16 ** 1000
 | 
			
		||||
      assert_equal(n, Bug::Bignum.str2big_poweroftwo(s, 16, true))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_str2big_normal
 | 
			
		||||
      s = "1" + "0" * 1000
 | 
			
		||||
      n = 10 ** 1000
 | 
			
		||||
      assert_equal(n, Bug::Bignum.str2big_normal(s, 10, true))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_str2big_karatsuba
 | 
			
		||||
      s = "1" + "0" * 1000
 | 
			
		||||
      n = 10 ** 1000
 | 
			
		||||
      assert_equal(n, Bug::Bignum.str2big_karatsuba(s, 10, true))
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_str2big_gmp
 | 
			
		||||
      s = "1" + "0" * 1000
 | 
			
		||||
      n = 10 ** 1000
 | 
			
		||||
      assert_equal(n, Bug::Bignum.str2big_gmp(s, 10, true))
 | 
			
		||||
    rescue NotImplementedError
 | 
			
		||||
    end
 | 
			
		||||
  SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
 | 
			
		||||
  BITSPERDIG = Bug::Bignum::BITSPERDIG
 | 
			
		||||
  BDIGMAX = (1 << BITSPERDIG) - 1
 | 
			
		||||
 | 
			
		||||
  def test_str2big_poweroftwo
 | 
			
		||||
    s = "1" + "0" * 1000
 | 
			
		||||
    n = 16 ** 1000
 | 
			
		||||
    assert_equal(n, Bug::Bignum.str2big_poweroftwo(s, 16, true))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_str2big_normal
 | 
			
		||||
    s = "1" + "0" * 1000
 | 
			
		||||
    n = 10 ** 1000
 | 
			
		||||
    assert_equal(n, Bug::Bignum.str2big_normal(s, 10, true))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_str2big_karatsuba
 | 
			
		||||
    s = "1" + "0" * 1000
 | 
			
		||||
    n = 10 ** 1000
 | 
			
		||||
    assert_equal(n, Bug::Bignum.str2big_karatsuba(s, 10, true))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_str2big_gmp
 | 
			
		||||
    s = "1" + "0" * 1000
 | 
			
		||||
    n = 10 ** 1000
 | 
			
		||||
    assert_equal(n, Bug::Bignum.str2big_gmp(s, 10, true))
 | 
			
		||||
  rescue NotImplementedError
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +0,0 @@
 | 
			
		|||
# frozen_string_literal: true
 | 
			
		||||
require 'test/unit'
 | 
			
		||||
 | 
			
		||||
class TestFuncall < Test::Unit::TestCase
 | 
			
		||||
  require '-test-/funcall'
 | 
			
		||||
 | 
			
		||||
  def test_funcall_extra_args
 | 
			
		||||
    assert_equal 'TestFuncall', TestFuncall.extra_args_name,
 | 
			
		||||
	 '[ruby-core:85266] [Bug #14425]'
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -9,6 +9,11 @@ class TestFuncall < Test::Unit::TestCase
 | 
			
		|||
  end
 | 
			
		||||
  require '-test-/funcall'
 | 
			
		||||
 | 
			
		||||
  def test_funcall_extra_args
 | 
			
		||||
    assert_equal 'TestFuncall', TestFuncall.extra_args_name,
 | 
			
		||||
	 '[ruby-core:85266] [Bug #14425]'
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_with_funcall2
 | 
			
		||||
    ok = nil
 | 
			
		||||
    Relay.with_funcall2("feature#4504") {|arg| ok = arg || true}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require 'date'
 | 
			
		||||
 | 
			
		||||
class TestDateParse < Test::Unit::TestCase
 | 
			
		||||
class TestDateParseRactor < Test::Unit::TestCase
 | 
			
		||||
  def code(klass = Date, share: false)
 | 
			
		||||
    <<~RUBY.gsub('Date', klass.name)
 | 
			
		||||
      share = #{share}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,10 +4,7 @@ require 'test/unit'
 | 
			
		|||
require 'tmpdir'
 | 
			
		||||
require_relative 'fileasserts'
 | 
			
		||||
 | 
			
		||||
class TestFileUtils < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
module TestFileUtils::Clobber
 | 
			
		||||
module TestFileUtilsClobber
 | 
			
		||||
  include Test::Unit::FileAssertions
 | 
			
		||||
 | 
			
		||||
  def my_rm_rf(path)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ require_relative 'visibility_tests'
 | 
			
		|||
class TestFileUtilsDryRun < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
  include FileUtils::DryRun
 | 
			
		||||
  include TestFileUtilsInc::Visibility
 | 
			
		||||
  include TestFileUtilsIncVisibility
 | 
			
		||||
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ require_relative 'visibility_tests'
 | 
			
		|||
class TestFileUtilsNoWrite < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
  include FileUtils::NoWrite
 | 
			
		||||
  include TestFileUtilsInc::Visibility
 | 
			
		||||
  include TestFileUtilsIncVisibility
 | 
			
		||||
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@ require_relative 'visibility_tests'
 | 
			
		|||
class TestFileUtilsVerbose < Test::Unit::TestCase
 | 
			
		||||
 | 
			
		||||
  include FileUtils::Verbose
 | 
			
		||||
  include TestFileUtilsInc::Visibility
 | 
			
		||||
  include TestFileUtilsIncVisibility
 | 
			
		||||
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,14 +2,11 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require 'fileutils'
 | 
			
		||||
 | 
			
		||||
class TestFileUtilsInc < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
##
 | 
			
		||||
# These tests are reused in the FileUtils::Verbose, FileUtils::NoWrite and
 | 
			
		||||
# FileUtils::DryRun tests
 | 
			
		||||
 | 
			
		||||
module TestFileUtilsInc::Visibility
 | 
			
		||||
module TestFileUtilsIncVisibility
 | 
			
		||||
 | 
			
		||||
  FileUtils::METHODS.each do |m|
 | 
			
		||||
    define_method "test_singleton_visibility_#{m}" do
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,134 +20,131 @@ $INCFLAGS << " -I."
 | 
			
		|||
$extout_prefix = "$(extout)$(target_prefix)/"
 | 
			
		||||
 | 
			
		||||
class TestMkmf < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
  module Base
 | 
			
		||||
    MKMFLOG = proc {File.read("mkmf.log") rescue ""}
 | 
			
		||||
 | 
			
		||||
module TestMkmf::Base
 | 
			
		||||
  MKMFLOG = proc {File.read("mkmf.log") rescue ""}
 | 
			
		||||
 | 
			
		||||
  class Capture
 | 
			
		||||
    attr_accessor :origin
 | 
			
		||||
    def initialize
 | 
			
		||||
      @buffer = ""
 | 
			
		||||
      @filter = nil
 | 
			
		||||
      @out = true
 | 
			
		||||
      @origin = nil
 | 
			
		||||
    end
 | 
			
		||||
    def clear
 | 
			
		||||
      @buffer.clear
 | 
			
		||||
    end
 | 
			
		||||
    def flush
 | 
			
		||||
      STDOUT.print @filter ? @filter.call(@buffer) : @buffer
 | 
			
		||||
      clear
 | 
			
		||||
    end
 | 
			
		||||
    def reopen(io)
 | 
			
		||||
      case io
 | 
			
		||||
      when Capture
 | 
			
		||||
        initialize_copy(io)
 | 
			
		||||
      when File
 | 
			
		||||
        @out = false
 | 
			
		||||
        @origin.reopen(io) if @origin
 | 
			
		||||
      when IO
 | 
			
		||||
    class Capture
 | 
			
		||||
      attr_accessor :origin
 | 
			
		||||
      def initialize
 | 
			
		||||
        @buffer = ""
 | 
			
		||||
        @filter = nil
 | 
			
		||||
        @out = true
 | 
			
		||||
        @origin.reopen(io) if @origin
 | 
			
		||||
      else
 | 
			
		||||
        @out = false
 | 
			
		||||
        @origin = nil
 | 
			
		||||
      end
 | 
			
		||||
      def clear
 | 
			
		||||
        @buffer.clear
 | 
			
		||||
      end
 | 
			
		||||
      def flush
 | 
			
		||||
        STDOUT.print @filter ? @filter.call(@buffer) : @buffer
 | 
			
		||||
        clear
 | 
			
		||||
      end
 | 
			
		||||
      def reopen(io)
 | 
			
		||||
        case io
 | 
			
		||||
        when Capture
 | 
			
		||||
          initialize_copy(io)
 | 
			
		||||
        when File
 | 
			
		||||
          @out = false
 | 
			
		||||
          @origin.reopen(io) if @origin
 | 
			
		||||
        when IO
 | 
			
		||||
          @out = true
 | 
			
		||||
          @origin.reopen(io) if @origin
 | 
			
		||||
        else
 | 
			
		||||
          @out = false
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
      def filter(&block)
 | 
			
		||||
        @filter = block
 | 
			
		||||
      end
 | 
			
		||||
      def write(*s)
 | 
			
		||||
        if @out
 | 
			
		||||
          @buffer.concat(*s)
 | 
			
		||||
        elsif @origin
 | 
			
		||||
          @origin.write(*s)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
    def filter(&block)
 | 
			
		||||
      @filter = block
 | 
			
		||||
 | 
			
		||||
    attr_reader :stdout
 | 
			
		||||
 | 
			
		||||
    def mkmflog(msg)
 | 
			
		||||
      proc {MKMFLOG[] << msg}
 | 
			
		||||
    end
 | 
			
		||||
    def write(*s)
 | 
			
		||||
      if @out
 | 
			
		||||
        @buffer.concat(*s)
 | 
			
		||||
      elsif @origin
 | 
			
		||||
        @origin.write(*s)
 | 
			
		||||
 | 
			
		||||
    def setup
 | 
			
		||||
      @rbconfig = rbconfig0 = RbConfig::CONFIG
 | 
			
		||||
      @mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG
 | 
			
		||||
      rbconfig = {
 | 
			
		||||
        "hdrdir" => $hdrdir,
 | 
			
		||||
        "srcdir" => $srcdir,
 | 
			
		||||
        "topdir" => $topdir,
 | 
			
		||||
      }
 | 
			
		||||
      mkconfig = {
 | 
			
		||||
        "hdrdir" => "$(top_srcdir)/include",
 | 
			
		||||
        "srcdir" => "$(top_srcdir)",
 | 
			
		||||
        "topdir" => $topdir,
 | 
			
		||||
      }
 | 
			
		||||
      rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup}
 | 
			
		||||
      mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup}
 | 
			
		||||
      RbConfig.module_eval {
 | 
			
		||||
        remove_const(:CONFIG)
 | 
			
		||||
        const_set(:CONFIG, rbconfig)
 | 
			
		||||
        remove_const(:MAKEFILE_CONFIG)
 | 
			
		||||
        const_set(:MAKEFILE_CONFIG, mkconfig)
 | 
			
		||||
      }
 | 
			
		||||
      MakeMakefile.class_eval {
 | 
			
		||||
        remove_const(:CONFIG)
 | 
			
		||||
        const_set(:CONFIG, mkconfig)
 | 
			
		||||
      }
 | 
			
		||||
      @tmpdir = Dir.mktmpdir
 | 
			
		||||
      @curdir = Dir.pwd
 | 
			
		||||
      @mkmfobj = Object.new
 | 
			
		||||
      @stdout = Capture.new
 | 
			
		||||
      Dir.chdir(@tmpdir)
 | 
			
		||||
      @quiet, Logging.quiet = Logging.quiet, true
 | 
			
		||||
      init_mkmf
 | 
			
		||||
      $INCFLAGS[0, 0] = "-I. "
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def teardown
 | 
			
		||||
      rbconfig0 = @rbconfig
 | 
			
		||||
      mkconfig0 = @mkconfig
 | 
			
		||||
      RbConfig.module_eval {
 | 
			
		||||
        remove_const(:CONFIG)
 | 
			
		||||
        const_set(:CONFIG, rbconfig0)
 | 
			
		||||
        remove_const(:MAKEFILE_CONFIG)
 | 
			
		||||
        const_set(:MAKEFILE_CONFIG, mkconfig0)
 | 
			
		||||
      }
 | 
			
		||||
      MakeMakefile.class_eval {
 | 
			
		||||
        remove_const(:CONFIG)
 | 
			
		||||
        const_set(:CONFIG, mkconfig0)
 | 
			
		||||
      }
 | 
			
		||||
      Logging.quiet = @quiet
 | 
			
		||||
      Logging.log_close
 | 
			
		||||
      FileUtils.rm_f("mkmf.log")
 | 
			
		||||
      Dir.chdir(@curdir)
 | 
			
		||||
      FileUtils.rm_rf(@tmpdir)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def mkmf(*args, &block)
 | 
			
		||||
      @stdout.clear
 | 
			
		||||
      stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout
 | 
			
		||||
      verbose, $VERBOSE = $VERBOSE, false
 | 
			
		||||
      @mkmfobj.instance_eval(*args, &block)
 | 
			
		||||
    ensure
 | 
			
		||||
      $VERBOSE = verbose
 | 
			
		||||
      $stdout, @stdout.origin = @stdout.origin, stdout
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def config_value(name)
 | 
			
		||||
      create_tmpsrc("---config-value=#{name}")
 | 
			
		||||
      xpopen(cpp_command('')) do |f|
 | 
			
		||||
        f.grep(/^---config-value=(.*)/) {return $1}
 | 
			
		||||
      end
 | 
			
		||||
      nil
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  attr_reader :stdout
 | 
			
		||||
 | 
			
		||||
  def mkmflog(msg)
 | 
			
		||||
    proc {MKMFLOG[] << msg}
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def setup
 | 
			
		||||
    @rbconfig = rbconfig0 = RbConfig::CONFIG
 | 
			
		||||
    @mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG
 | 
			
		||||
    rbconfig = {
 | 
			
		||||
      "hdrdir" => $hdrdir,
 | 
			
		||||
      "srcdir" => $srcdir,
 | 
			
		||||
      "topdir" => $topdir,
 | 
			
		||||
    }
 | 
			
		||||
    mkconfig = {
 | 
			
		||||
      "hdrdir" => "$(top_srcdir)/include",
 | 
			
		||||
      "srcdir" => "$(top_srcdir)",
 | 
			
		||||
      "topdir" => $topdir,
 | 
			
		||||
    }
 | 
			
		||||
    rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup}
 | 
			
		||||
    mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup}
 | 
			
		||||
    RbConfig.module_eval {
 | 
			
		||||
      remove_const(:CONFIG)
 | 
			
		||||
      const_set(:CONFIG, rbconfig)
 | 
			
		||||
      remove_const(:MAKEFILE_CONFIG)
 | 
			
		||||
      const_set(:MAKEFILE_CONFIG, mkconfig)
 | 
			
		||||
    }
 | 
			
		||||
    MakeMakefile.class_eval {
 | 
			
		||||
      remove_const(:CONFIG)
 | 
			
		||||
      const_set(:CONFIG, mkconfig)
 | 
			
		||||
    }
 | 
			
		||||
    @tmpdir = Dir.mktmpdir
 | 
			
		||||
    @curdir = Dir.pwd
 | 
			
		||||
    @mkmfobj = Object.new
 | 
			
		||||
    @stdout = Capture.new
 | 
			
		||||
    Dir.chdir(@tmpdir)
 | 
			
		||||
    @quiet, Logging.quiet = Logging.quiet, true
 | 
			
		||||
    init_mkmf
 | 
			
		||||
    $INCFLAGS[0, 0] = "-I. "
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def teardown
 | 
			
		||||
    rbconfig0 = @rbconfig
 | 
			
		||||
    mkconfig0 = @mkconfig
 | 
			
		||||
    RbConfig.module_eval {
 | 
			
		||||
      remove_const(:CONFIG)
 | 
			
		||||
      const_set(:CONFIG, rbconfig0)
 | 
			
		||||
      remove_const(:MAKEFILE_CONFIG)
 | 
			
		||||
      const_set(:MAKEFILE_CONFIG, mkconfig0)
 | 
			
		||||
    }
 | 
			
		||||
    MakeMakefile.class_eval {
 | 
			
		||||
      remove_const(:CONFIG)
 | 
			
		||||
      const_set(:CONFIG, mkconfig0)
 | 
			
		||||
    }
 | 
			
		||||
    Logging.quiet = @quiet
 | 
			
		||||
    Logging.log_close
 | 
			
		||||
    FileUtils.rm_f("mkmf.log")
 | 
			
		||||
    Dir.chdir(@curdir)
 | 
			
		||||
    FileUtils.rm_rf(@tmpdir)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def mkmf(*args, &block)
 | 
			
		||||
    @stdout.clear
 | 
			
		||||
    stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout
 | 
			
		||||
    verbose, $VERBOSE = $VERBOSE, false
 | 
			
		||||
    @mkmfobj.instance_eval(*args, &block)
 | 
			
		||||
  ensure
 | 
			
		||||
    $VERBOSE = verbose
 | 
			
		||||
    $stdout, @stdout.origin = @stdout.origin, stdout
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def config_value(name)
 | 
			
		||||
    create_tmpsrc("---config-value=#{name}")
 | 
			
		||||
    xpopen(cpp_command('')) do |f|
 | 
			
		||||
      f.grep(/^---config-value=(.*)/) {return $1}
 | 
			
		||||
    end
 | 
			
		||||
    nil
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  include TestMkmf::Base
 | 
			
		||||
  include Base
 | 
			
		||||
 | 
			
		||||
  def assert_separately(args, src, *rest, **options)
 | 
			
		||||
    super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\nEND{teardown}\n#{src}", *rest, **options)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,14 +4,12 @@ $extmk = true
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require 'mkmf'
 | 
			
		||||
 | 
			
		||||
class TestMkmf < Test::Unit::TestCase
 | 
			
		||||
  class TestConfig < Test::Unit::TestCase
 | 
			
		||||
    def test_dir_config
 | 
			
		||||
      bug8074 = '[Bug #8074]'
 | 
			
		||||
      lib = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["libdir"], "exec_prefix"=>"")
 | 
			
		||||
      assert_separately %w[-rmkmf - -- --with-foo-dir=/test/foo], %{
 | 
			
		||||
        assert_equal(%w[/test/foo/include /test/foo#{lib}], dir_config("foo"), #{bug8074.dump})
 | 
			
		||||
      }
 | 
			
		||||
    end
 | 
			
		||||
class TestMkmfConfig < Test::Unit::TestCase
 | 
			
		||||
  def test_dir_config
 | 
			
		||||
    bug8074 = '[Bug #8074]'
 | 
			
		||||
    lib = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["libdir"], "exec_prefix"=>"")
 | 
			
		||||
    assert_separately %w[-rmkmf - -- --with-foo-dir=/test/foo], %{
 | 
			
		||||
      assert_equal(%w[/test/foo/include /test/foo#{lib}], dir_config("foo"), #{bug8074.dump})
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,38 +1,36 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestTryConstant < TestMkmf
 | 
			
		||||
    def test_simple
 | 
			
		||||
      assert_equal( 0, mkmf {try_constant("0")}, MKMFLOG)
 | 
			
		||||
      assert_equal( 1, mkmf {try_constant("1")}, MKMFLOG)
 | 
			
		||||
      assert_equal(-1, mkmf {try_constant("-1")}, MKMFLOG)
 | 
			
		||||
class TestMkmfTryConstant < TestMkmf
 | 
			
		||||
  def test_simple
 | 
			
		||||
    assert_equal( 0, mkmf {try_constant("0")}, MKMFLOG)
 | 
			
		||||
    assert_equal( 1, mkmf {try_constant("1")}, MKMFLOG)
 | 
			
		||||
    assert_equal(-1, mkmf {try_constant("-1")}, MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_sizeof
 | 
			
		||||
    assert_equal(config_value("SIZEOF_INT").to_i, mkmf {try_constant("sizeof(int)")}, MKMFLOG)
 | 
			
		||||
    assert_equal(config_value("SIZEOF_LONG").to_i, mkmf {try_constant("sizeof(long)")}, MKMFLOG)
 | 
			
		||||
    assert_equal(config_value("SIZEOF_VOIDP").to_i, mkmf {try_constant("sizeof(void*)")}, MKMFLOG)
 | 
			
		||||
    assert_equal(config_value("SIZEOF_VALUE").to_i, mkmf {try_constant("sizeof(Qnil)")}, MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_long
 | 
			
		||||
    sizeof_int = config_value("SIZEOF_INT").to_i
 | 
			
		||||
    sizeof_long = config_value("SIZEOF_LONG").to_i
 | 
			
		||||
    if sizeof_long > sizeof_int
 | 
			
		||||
      type = 'long'
 | 
			
		||||
    else
 | 
			
		||||
      sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i
 | 
			
		||||
      return if !sizeof_long_long or sizeof_long_long <= sizeof_int
 | 
			
		||||
      type = 'LONG_LONG'
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_sizeof
 | 
			
		||||
      assert_equal(config_value("SIZEOF_INT").to_i, mkmf {try_constant("sizeof(int)")}, MKMFLOG)
 | 
			
		||||
      assert_equal(config_value("SIZEOF_LONG").to_i, mkmf {try_constant("sizeof(long)")}, MKMFLOG)
 | 
			
		||||
      assert_equal(config_value("SIZEOF_VOIDP").to_i, mkmf {try_constant("sizeof(void*)")}, MKMFLOG)
 | 
			
		||||
      assert_equal(config_value("SIZEOF_VALUE").to_i, mkmf {try_constant("sizeof(Qnil)")}, MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
    decl = "#define CONFTEST_VALUE (unsigned #{type})(((unsigned #{type})1)<<(CHAR_BIT*sizeof(int)))"
 | 
			
		||||
    assert_operator(mkmf {try_constant("CONFTEST_VALUE", [[decl]])}, :>, 0, MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_long
 | 
			
		||||
      sizeof_int = config_value("SIZEOF_INT").to_i
 | 
			
		||||
      sizeof_long = config_value("SIZEOF_LONG").to_i
 | 
			
		||||
      if sizeof_long > sizeof_int
 | 
			
		||||
        type = 'long'
 | 
			
		||||
      else
 | 
			
		||||
        sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i
 | 
			
		||||
        return if !sizeof_long_long or sizeof_long_long <= sizeof_int
 | 
			
		||||
        type = 'LONG_LONG'
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      decl = "#define CONFTEST_VALUE (unsigned #{type})(((unsigned #{type})1)<<(CHAR_BIT*sizeof(int)))"
 | 
			
		||||
      assert_operator(mkmf {try_constant("CONFTEST_VALUE", [[decl]])}, :>, 0, MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_large_unsigned
 | 
			
		||||
      assert_operator(mkmf {try_constant("1U<<(CHAR_BIT*sizeof(int)-1)")}, :>, 0, MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
  def test_large_unsigned
 | 
			
		||||
    assert_operator(mkmf {try_constant("1U<<(CHAR_BIT*sizeof(int)-1)")}, :>, 0, MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,35 +1,33 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestConvertible < TestMkmf
 | 
			
		||||
    def test_typeof_builtin
 | 
			
		||||
      ["", ["signed ", ""], "unsigned "].each do |signed, prefix|
 | 
			
		||||
        %w[short int long].each do |type|
 | 
			
		||||
          assert_equal((prefix || signed)+type,
 | 
			
		||||
                       mkmf {convertible_int(signed+type)}, MKMFLOG)
 | 
			
		||||
        end
 | 
			
		||||
class TestMkmfConvertible < TestMkmf
 | 
			
		||||
  def test_typeof_builtin
 | 
			
		||||
    ["", ["signed ", ""], "unsigned "].each do |signed, prefix|
 | 
			
		||||
      %w[short int long].each do |type|
 | 
			
		||||
        assert_equal((prefix || signed)+type,
 | 
			
		||||
                     mkmf {convertible_int(signed+type)}, MKMFLOG)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_typeof_typedef
 | 
			
		||||
      ["", ["signed ", ""], "unsigned "].each do |signed, prefix|
 | 
			
		||||
        %w[short int long].each do |type|
 | 
			
		||||
          open("confdefs.h", "w") {|f|
 | 
			
		||||
            f.puts "typedef #{signed}#{type} test1_t;"
 | 
			
		||||
          }
 | 
			
		||||
          $defs.clear
 | 
			
		||||
          assert_equal((prefix || signed)+type,
 | 
			
		||||
                       mkmf {convertible_int("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
          (u = signed[/^u/]) and u.upcase!
 | 
			
		||||
          assert_include($defs, "-DTYPEOF_TEST1_T="+"#{prefix||signed}#{type}".quote)
 | 
			
		||||
          assert_include($defs, "-DPRI_TEST1T_PREFIX=PRI_#{type.upcase}_PREFIX")
 | 
			
		||||
          assert_include($defs, "-DTEST1T2NUM=#{u}#{type.upcase}2NUM")
 | 
			
		||||
          assert_include($defs, "-DNUM2TEST1T=NUM2#{u}#{type.upcase}")
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    ensure
 | 
			
		||||
      File.unlink("confdefs.h")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_typeof_typedef
 | 
			
		||||
    ["", ["signed ", ""], "unsigned "].each do |signed, prefix|
 | 
			
		||||
      %w[short int long].each do |type|
 | 
			
		||||
        open("confdefs.h", "w") {|f|
 | 
			
		||||
          f.puts "typedef #{signed}#{type} test1_t;"
 | 
			
		||||
        }
 | 
			
		||||
        $defs.clear
 | 
			
		||||
        assert_equal((prefix || signed)+type,
 | 
			
		||||
                     mkmf {convertible_int("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
        (u = signed[/^u/]) and u.upcase!
 | 
			
		||||
        assert_include($defs, "-DTYPEOF_TEST1_T="+"#{prefix||signed}#{type}".quote)
 | 
			
		||||
        assert_include($defs, "-DPRI_TEST1T_PREFIX=PRI_#{type.upcase}_PREFIX")
 | 
			
		||||
        assert_include($defs, "-DTEST1T2NUM=#{u}#{type.upcase}2NUM")
 | 
			
		||||
        assert_include($defs, "-DNUM2TEST1T=NUM2#{u}#{type.upcase}")
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  ensure
 | 
			
		||||
    File.unlink("confdefs.h")
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,14 +2,12 @@
 | 
			
		|||
require_relative 'base'
 | 
			
		||||
require 'tempfile'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestEgrepCpp < TestMkmf
 | 
			
		||||
    def test_egrep_cpp
 | 
			
		||||
      assert_equal(true, egrep_cpp(/ruby_init/, ""), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
class TestMkmfEgrepCpp < TestMkmf
 | 
			
		||||
  def test_egrep_cpp
 | 
			
		||||
    assert_equal(true, egrep_cpp(/ruby_init/, ""), MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_not_have_func
 | 
			
		||||
      assert_equal(false, egrep_cpp(/never match/, ""), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
  def test_not_have_func
 | 
			
		||||
    assert_equal(false, egrep_cpp(/never match/, ""), MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,58 +1,56 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestFindExecutable < TestMkmf
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
      @path, ENV["PATH"] = ENV["PATH"], @tmpdir
 | 
			
		||||
    end
 | 
			
		||||
class TestMkmfFindExecutable < TestMkmf
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @path, ENV["PATH"] = ENV["PATH"], @tmpdir
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def each_exts(&block)
 | 
			
		||||
      name = "foobar#{$$}#{rand(1000)}"
 | 
			
		||||
      stdout.filter {|s| s.sub(name, "<executable>")}
 | 
			
		||||
      exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
 | 
			
		||||
      exts[0] ||= ""
 | 
			
		||||
      exts.each do |ext|
 | 
			
		||||
        yield name+ext, name
 | 
			
		||||
  def each_exts(&block)
 | 
			
		||||
    name = "foobar#{$$}#{rand(1000)}"
 | 
			
		||||
    stdout.filter {|s| s.sub(name, "<executable>")}
 | 
			
		||||
    exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
 | 
			
		||||
    exts[0] ||= ""
 | 
			
		||||
    exts.each do |ext|
 | 
			
		||||
      yield name+ext, name
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def teardown
 | 
			
		||||
    ENV["PATH"] = @path
 | 
			
		||||
    super
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_find_executable
 | 
			
		||||
    bug2669 = '[ruby-core:27912]'
 | 
			
		||||
    each_exts do |full, name|
 | 
			
		||||
      begin
 | 
			
		||||
        open(full, "w") {|ff| ff.chmod(0755)}
 | 
			
		||||
        result = mkmf {find_executable(name)}
 | 
			
		||||
      ensure
 | 
			
		||||
        File.unlink(full)
 | 
			
		||||
      end
 | 
			
		||||
      assert_equal("#{@tmpdir}/#{full}", result, bug2669)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def teardown
 | 
			
		||||
      ENV["PATH"] = @path
 | 
			
		||||
      super
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_find_executable
 | 
			
		||||
      bug2669 = '[ruby-core:27912]'
 | 
			
		||||
      each_exts do |full, name|
 | 
			
		||||
        begin
 | 
			
		||||
          open(full, "w") {|ff| ff.chmod(0755)}
 | 
			
		||||
          result = mkmf {find_executable(name)}
 | 
			
		||||
        ensure
 | 
			
		||||
          File.unlink(full)
 | 
			
		||||
        end
 | 
			
		||||
        assert_equal("#{@tmpdir}/#{full}", result, bug2669)
 | 
			
		||||
  def test_find_executable_dir
 | 
			
		||||
    each_exts do |full, name|
 | 
			
		||||
      begin
 | 
			
		||||
        Dir.mkdir(full)
 | 
			
		||||
        result = mkmf {find_executable(name)}
 | 
			
		||||
      ensure
 | 
			
		||||
        Dir.rmdir(full)
 | 
			
		||||
      end
 | 
			
		||||
      assert_nil(result)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_find_executable_dir
 | 
			
		||||
      each_exts do |full, name|
 | 
			
		||||
        begin
 | 
			
		||||
          Dir.mkdir(full)
 | 
			
		||||
          result = mkmf {find_executable(name)}
 | 
			
		||||
        ensure
 | 
			
		||||
          Dir.rmdir(full)
 | 
			
		||||
        end
 | 
			
		||||
        assert_nil(result)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    if /mingw|mswin/ =~ RUBY_PLATFORM
 | 
			
		||||
      def test_quoted_path_on_windows
 | 
			
		||||
        ENV["PATH"] = %["#{@tmpdir}"]
 | 
			
		||||
        test_find_executable
 | 
			
		||||
      end
 | 
			
		||||
  if /mingw|mswin/ =~ RUBY_PLATFORM
 | 
			
		||||
    def test_quoted_path_on_windows
 | 
			
		||||
      ENV["PATH"] = %["#{@tmpdir}"]
 | 
			
		||||
      test_find_executable
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,57 +1,55 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestFlags < TestMkmf
 | 
			
		||||
    def test_valid_warnflags
 | 
			
		||||
      val = $extmk
 | 
			
		||||
      warnflags = $warnflags
 | 
			
		||||
      makefile = mkmf do
 | 
			
		||||
        $extmk = false
 | 
			
		||||
        self.class::CONFIG['warnflags'] = %w"-Wextra
 | 
			
		||||
        -Wno-unused-parameter -Wno-parentheses -Wno-long-long
 | 
			
		||||
        -Wno-missing-field-initializers -Werror=pointer-arith
 | 
			
		||||
        -Werror=write-strings -Werror=declaration-after-statement
 | 
			
		||||
        -Werror=shorten-64-to-32
 | 
			
		||||
        -Werror-implicit-function-declaration
 | 
			
		||||
        ".join(' ')
 | 
			
		||||
        self.class::CONFIG['GCC'] = 'yes'
 | 
			
		||||
        init_mkmf(self.class::CONFIG)
 | 
			
		||||
        configuration '.'
 | 
			
		||||
      end
 | 
			
		||||
      generated_flags = makefile.grep(/warnflags/).first[/^warnflags = (.*)$/, 1].split
 | 
			
		||||
 | 
			
		||||
      assert_equal %w"
 | 
			
		||||
      -Wextra -Wno-unused-parameter -Wno-parentheses
 | 
			
		||||
      -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith
 | 
			
		||||
      -Wwrite-strings -Wdeclaration-after-statement
 | 
			
		||||
      -Wshorten-64-to-32 -Werror-implicit-function-declaration
 | 
			
		||||
      ", generated_flags
 | 
			
		||||
 | 
			
		||||
    ensure
 | 
			
		||||
      $warnflags = warnflags
 | 
			
		||||
      $extmk = val
 | 
			
		||||
class TestMkmfFlags < TestMkmf
 | 
			
		||||
  def test_valid_warnflags
 | 
			
		||||
    val = $extmk
 | 
			
		||||
    warnflags = $warnflags
 | 
			
		||||
    makefile = mkmf do
 | 
			
		||||
      $extmk = false
 | 
			
		||||
      self.class::CONFIG['warnflags'] = %w"-Wextra
 | 
			
		||||
      -Wno-unused-parameter -Wno-parentheses -Wno-long-long
 | 
			
		||||
      -Wno-missing-field-initializers -Werror=pointer-arith
 | 
			
		||||
      -Werror=write-strings -Werror=declaration-after-statement
 | 
			
		||||
      -Werror=shorten-64-to-32
 | 
			
		||||
      -Werror-implicit-function-declaration
 | 
			
		||||
      ".join(' ')
 | 
			
		||||
      self.class::CONFIG['GCC'] = 'yes'
 | 
			
		||||
      init_mkmf(self.class::CONFIG)
 | 
			
		||||
      configuration '.'
 | 
			
		||||
    end
 | 
			
		||||
    generated_flags = makefile.grep(/warnflags/).first[/^warnflags = (.*)$/, 1].split
 | 
			
		||||
 | 
			
		||||
    def test_try_ldflag_invalid_opt
 | 
			
		||||
      assert_separately([], <<-'end;') #do
 | 
			
		||||
        assert(!try_ldflags("nosuch.c"), TestMkmf::MKMFLOG)
 | 
			
		||||
        assert(have_devel?, TestMkmf::MKMFLOG)
 | 
			
		||||
      end;
 | 
			
		||||
    end
 | 
			
		||||
    assert_equal %w"
 | 
			
		||||
    -Wextra -Wno-unused-parameter -Wno-parentheses
 | 
			
		||||
    -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith
 | 
			
		||||
    -Wwrite-strings -Wdeclaration-after-statement
 | 
			
		||||
    -Wshorten-64-to-32 -Werror-implicit-function-declaration
 | 
			
		||||
    ", generated_flags
 | 
			
		||||
 | 
			
		||||
    def test_try_cflag_invalid_opt
 | 
			
		||||
      assert_separately([], <<-'end;', timeout: 30) #do
 | 
			
		||||
        assert(!try_cflags("nosuch.c"), TestMkmf::MKMFLOG)
 | 
			
		||||
        assert(have_devel?, TestMkmf::MKMFLOG)
 | 
			
		||||
      end;
 | 
			
		||||
    end
 | 
			
		||||
  ensure
 | 
			
		||||
    $warnflags = warnflags
 | 
			
		||||
    $extmk = val
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_try_cppflag_invalid_opt
 | 
			
		||||
      assert_separately([], <<-'end;') #do
 | 
			
		||||
        assert(!try_cppflags("nosuch.c"), TestMkmf::MKMFLOG)
 | 
			
		||||
        assert(have_devel?, TestMkmf::MKMFLOG)
 | 
			
		||||
      end;
 | 
			
		||||
    end
 | 
			
		||||
  def test_try_ldflag_invalid_opt
 | 
			
		||||
    assert_separately([], <<-'end;') #do
 | 
			
		||||
      assert(!try_ldflags("nosuch.c"), TestMkmf::MKMFLOG)
 | 
			
		||||
      assert(have_devel?, TestMkmf::MKMFLOG)
 | 
			
		||||
    end;
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_try_cflag_invalid_opt
 | 
			
		||||
    assert_separately([], <<-'end;', timeout: 30) #do
 | 
			
		||||
      assert(!try_cflags("nosuch.c"), TestMkmf::MKMFLOG)
 | 
			
		||||
      assert(have_devel?, TestMkmf::MKMFLOG)
 | 
			
		||||
    end;
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_try_cppflag_invalid_opt
 | 
			
		||||
    assert_separately([], <<-'end;') #do
 | 
			
		||||
      assert(!try_cppflags("nosuch.c"), TestMkmf::MKMFLOG)
 | 
			
		||||
      assert(have_devel?, TestMkmf::MKMFLOG)
 | 
			
		||||
    end;
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,49 +1,47 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestHaveFramework < TestMkmf
 | 
			
		||||
    def create_framework(fw, hdrname = "#{fw}.h")
 | 
			
		||||
      Dir.mktmpdir("frameworks") do |dir|
 | 
			
		||||
        fwdir = "#{dir}/#{fw}.framework"
 | 
			
		||||
        hdrdir = "#{fwdir}/Headers"
 | 
			
		||||
        FileUtils.mkdir_p(hdrdir)
 | 
			
		||||
        File.write("#{hdrdir}/#{hdrname}", "")
 | 
			
		||||
        src = "#{fwdir}/main.c"
 | 
			
		||||
        File.write(src, "void #{fw}(void) {}\n")
 | 
			
		||||
        cmd = LINK_SO.dup
 | 
			
		||||
        RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src))
 | 
			
		||||
        cmd.gsub!("$@", "#{fwdir}/#{fw}")
 | 
			
		||||
        cmd.gsub!(/ -bundle /, ' -dynamiclib ')
 | 
			
		||||
        assert(xsystem(cmd), MKMFLOG)
 | 
			
		||||
        $INCFLAGS << " " << "-F#{dir}".quote
 | 
			
		||||
        yield fw, hdrname
 | 
			
		||||
      end
 | 
			
		||||
class TestMkmfHaveFramework < TestMkmf
 | 
			
		||||
  def create_framework(fw, hdrname = "#{fw}.h")
 | 
			
		||||
    Dir.mktmpdir("frameworks") do |dir|
 | 
			
		||||
      fwdir = "#{dir}/#{fw}.framework"
 | 
			
		||||
      hdrdir = "#{fwdir}/Headers"
 | 
			
		||||
      FileUtils.mkdir_p(hdrdir)
 | 
			
		||||
      File.write("#{hdrdir}/#{hdrname}", "")
 | 
			
		||||
      src = "#{fwdir}/main.c"
 | 
			
		||||
      File.write(src, "void #{fw}(void) {}\n")
 | 
			
		||||
      cmd = LINK_SO.dup
 | 
			
		||||
      RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src))
 | 
			
		||||
      cmd.gsub!("$@", "#{fwdir}/#{fw}")
 | 
			
		||||
      cmd.gsub!(/ -bundle /, ' -dynamiclib ')
 | 
			
		||||
      assert(xsystem(cmd), MKMFLOG)
 | 
			
		||||
      $INCFLAGS << " " << "-F#{dir}".quote
 | 
			
		||||
      yield fw, hdrname
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_single_framework
 | 
			
		||||
      assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C"))
 | 
			
		||||
  def test_single_framework
 | 
			
		||||
    assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C"))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_multi_frameworks
 | 
			
		||||
    assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C"))
 | 
			
		||||
    create_framework("MkmfTest") do |fw|
 | 
			
		||||
      assert(have_framework(fw), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_multi_frameworks
 | 
			
		||||
      assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C"))
 | 
			
		||||
      create_framework("MkmfTest") do |fw|
 | 
			
		||||
        assert(have_framework(fw), MKMFLOG)
 | 
			
		||||
      end
 | 
			
		||||
  def test_empty_framework
 | 
			
		||||
    create_framework("MkmfTest") do |fw|
 | 
			
		||||
      assert(have_framework(fw), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_empty_framework
 | 
			
		||||
      create_framework("MkmfTest") do |fw|
 | 
			
		||||
        assert(have_framework(fw), MKMFLOG)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_different_name_header
 | 
			
		||||
      _bug8593 = '[ruby-core:55745] [Bug #8593]'
 | 
			
		||||
      create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname|
 | 
			
		||||
        assert(!have_framework(fw), MKMFLOG)
 | 
			
		||||
        assert(have_framework([fw, hdrname]), MKMFLOG)
 | 
			
		||||
      end
 | 
			
		||||
  def test_different_name_header
 | 
			
		||||
    _bug8593 = '[ruby-core:55745] [Bug #8593]'
 | 
			
		||||
    create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname|
 | 
			
		||||
      assert(!have_framework(fw), MKMFLOG)
 | 
			
		||||
      assert(have_framework([fw, hdrname]), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end if /darwin/ =~ RUBY_PLATFORM
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,16 +2,14 @@
 | 
			
		|||
require_relative 'base'
 | 
			
		||||
require 'tempfile'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestHaveFunc < TestMkmf
 | 
			
		||||
    def test_have_func
 | 
			
		||||
      assert_equal(true, have_func("ruby_init"), MKMFLOG)
 | 
			
		||||
      assert_include($defs, '-DHAVE_RUBY_INIT')
 | 
			
		||||
    end
 | 
			
		||||
class TestMkmfHaveFunc < TestMkmf
 | 
			
		||||
  def test_have_func
 | 
			
		||||
    assert_equal(true, have_func("ruby_init"), MKMFLOG)
 | 
			
		||||
    assert_include($defs, '-DHAVE_RUBY_INIT')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_not_have_func
 | 
			
		||||
      assert_equal(false, have_func("no_ruby_init"), MKMFLOG)
 | 
			
		||||
      assert_not_include($defs, '-DHAVE_RUBY_INIT')
 | 
			
		||||
    end
 | 
			
		||||
  def test_not_have_func
 | 
			
		||||
    assert_equal(false, have_func("no_ruby_init"), MKMFLOG)
 | 
			
		||||
    assert_not_include($defs, '-DHAVE_RUBY_INIT')
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,55 +2,53 @@
 | 
			
		|||
require_relative 'base'
 | 
			
		||||
require 'tempfile'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestHaveLibrary < TestMkmf
 | 
			
		||||
    LIBRARY_NAME = 'mkmftest'
 | 
			
		||||
    HEADER_NAME = "#{LIBRARY_NAME}.h"
 | 
			
		||||
    FUNC_NAME = 'ruby_mkmftest_foo'
 | 
			
		||||
    ARPREFIX = config_string('LIBRUBY_A') {|lib| lib[/\A\w+/]}
 | 
			
		||||
class TestMkmfHaveLibrary < TestMkmf
 | 
			
		||||
  LIBRARY_NAME = 'mkmftest'
 | 
			
		||||
  HEADER_NAME = "#{LIBRARY_NAME}.h"
 | 
			
		||||
  FUNC_NAME = 'ruby_mkmftest_foo'
 | 
			
		||||
  ARPREFIX = config_string('LIBRUBY_A') {|lib| lib[/\A\w+/]}
 | 
			
		||||
 | 
			
		||||
    def create_library(libname = LIBRARY_NAME)
 | 
			
		||||
      lib = "#{ARPREFIX}#{libname}.#{$LIBEXT}"
 | 
			
		||||
      open(HEADER_NAME, "w") do |hdr|
 | 
			
		||||
        hdr.puts "void #{FUNC_NAME}(void);"
 | 
			
		||||
        hdr.puts "void #{FUNC_NAME}_fake(void);"
 | 
			
		||||
      end
 | 
			
		||||
      create_tmpsrc("#include \"#{HEADER_NAME}\"\n""void #{FUNC_NAME}(void) {}")
 | 
			
		||||
      assert(xsystem(cc_command), "compile failed: #{cc_command}")
 | 
			
		||||
      command = "#{CONFIG['AR']} #{config_string('ARFLAGS') || 'cru '}#{lib} #{CONFTEST}.#{$OBJEXT}"
 | 
			
		||||
      assert(xsystem(command), "making library failed: #{command}")
 | 
			
		||||
      File.unlink("#{CONFTEST}.#{$OBJEXT}")
 | 
			
		||||
      config_string('RANLIB') do |ranlib|
 | 
			
		||||
        command = "#{ranlib} #{lib}"
 | 
			
		||||
        assert(xsystem(command), "ranlib failed: #{command}")
 | 
			
		||||
      end
 | 
			
		||||
  def create_library(libname = LIBRARY_NAME)
 | 
			
		||||
    lib = "#{ARPREFIX}#{libname}.#{$LIBEXT}"
 | 
			
		||||
    open(HEADER_NAME, "w") do |hdr|
 | 
			
		||||
      hdr.puts "void #{FUNC_NAME}(void);"
 | 
			
		||||
      hdr.puts "void #{FUNC_NAME}_fake(void);"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def assert_have_library(*args)
 | 
			
		||||
      assert_equal(true, have_library(LIBRARY_NAME, *args), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def assert_not_have_library(*args)
 | 
			
		||||
      assert_equal(false, have_library(LIBRARY_NAME, *args), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_have_library
 | 
			
		||||
      create_library
 | 
			
		||||
      assert_have_library
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_have_library_with_name
 | 
			
		||||
      create_library
 | 
			
		||||
      assert_have_library(FUNC_NAME, HEADER_NAME)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_not_have_library
 | 
			
		||||
      assert_not_have_library
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_not_have_library_with_name
 | 
			
		||||
      create_library
 | 
			
		||||
      assert_not_have_library("#{FUNC_NAME}_fake", HEADER_NAME)
 | 
			
		||||
    create_tmpsrc("#include \"#{HEADER_NAME}\"\n""void #{FUNC_NAME}(void) {}")
 | 
			
		||||
    assert(xsystem(cc_command), "compile failed: #{cc_command}")
 | 
			
		||||
    command = "#{CONFIG['AR']} #{config_string('ARFLAGS') || 'cru '}#{lib} #{CONFTEST}.#{$OBJEXT}"
 | 
			
		||||
    assert(xsystem(command), "making library failed: #{command}")
 | 
			
		||||
    File.unlink("#{CONFTEST}.#{$OBJEXT}")
 | 
			
		||||
    config_string('RANLIB') do |ranlib|
 | 
			
		||||
      command = "#{ranlib} #{lib}"
 | 
			
		||||
      assert(xsystem(command), "ranlib failed: #{command}")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def assert_have_library(*args)
 | 
			
		||||
    assert_equal(true, have_library(LIBRARY_NAME, *args), MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def assert_not_have_library(*args)
 | 
			
		||||
    assert_equal(false, have_library(LIBRARY_NAME, *args), MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_have_library
 | 
			
		||||
    create_library
 | 
			
		||||
    assert_have_library
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_have_library_with_name
 | 
			
		||||
    create_library
 | 
			
		||||
    assert_have_library(FUNC_NAME, HEADER_NAME)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_not_have_library
 | 
			
		||||
    assert_not_have_library
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_not_have_library_with_name
 | 
			
		||||
    create_library
 | 
			
		||||
    assert_not_have_library("#{FUNC_NAME}_fake", HEADER_NAME)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,35 +2,33 @@
 | 
			
		|||
require_relative 'base'
 | 
			
		||||
require 'tempfile'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestHaveMacro < TestMkmf
 | 
			
		||||
    MACRO_NAME = "RUBY_MKMFTEST_FOOBAR"
 | 
			
		||||
class TestMkmfHaveMacro < TestMkmf
 | 
			
		||||
  MACRO_NAME = "RUBY_MKMFTEST_FOOBAR"
 | 
			
		||||
 | 
			
		||||
    def test_have_macro_opt
 | 
			
		||||
      assert_equal(true, have_macro(MACRO_NAME, nil, "-D#{MACRO_NAME}"), MKMFLOG)
 | 
			
		||||
  def test_have_macro_opt
 | 
			
		||||
    assert_equal(true, have_macro(MACRO_NAME, nil, "-D#{MACRO_NAME}"), MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_have_macro_header
 | 
			
		||||
    Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
 | 
			
		||||
      tmp.puts("#undef #{MACRO_NAME}")
 | 
			
		||||
      tmp.puts("#define #{MACRO_NAME} 1")
 | 
			
		||||
      tmp.close
 | 
			
		||||
      base = File.basename(tmp.path)
 | 
			
		||||
      assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_have_macro_header
 | 
			
		||||
      Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
 | 
			
		||||
        tmp.puts("#undef #{MACRO_NAME}")
 | 
			
		||||
        tmp.puts("#define #{MACRO_NAME} 1")
 | 
			
		||||
        tmp.close
 | 
			
		||||
        base = File.basename(tmp.path)
 | 
			
		||||
        assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  def test_not_have_macro_opt
 | 
			
		||||
    assert_equal(false, have_macro(MACRO_NAME, nil, "-U#{MACRO_NAME}"), MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_not_have_macro_opt
 | 
			
		||||
      assert_equal(false, have_macro(MACRO_NAME, nil, "-U#{MACRO_NAME}"), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_not_have_macro_header
 | 
			
		||||
      Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
 | 
			
		||||
        tmp.puts("#undef #{MACRO_NAME}")
 | 
			
		||||
        tmp.close
 | 
			
		||||
        base = File.basename(tmp.path)
 | 
			
		||||
        assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
 | 
			
		||||
      end
 | 
			
		||||
  def test_not_have_macro_header
 | 
			
		||||
    Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
 | 
			
		||||
      tmp.puts("#undef #{MACRO_NAME}")
 | 
			
		||||
      tmp.close
 | 
			
		||||
      base = File.basename(tmp.path)
 | 
			
		||||
      assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,27 +1,25 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestInstall < TestMkmf
 | 
			
		||||
    def test_install_dirs
 | 
			
		||||
      Dir.mktmpdir do |dir|
 | 
			
		||||
        File.write(dir+"/extconf.rb", "require 'mkmf'; create_makefile('test')")
 | 
			
		||||
        all_assertions do |a|
 | 
			
		||||
class TestMkmfInstall < TestMkmf
 | 
			
		||||
  def test_install_dirs
 | 
			
		||||
    Dir.mktmpdir do |dir|
 | 
			
		||||
      File.write(dir+"/extconf.rb", "require 'mkmf'; create_makefile('test')")
 | 
			
		||||
      all_assertions do |a|
 | 
			
		||||
        a.foreach(
 | 
			
		||||
          ["site"],
 | 
			
		||||
          ["vendor", "--vendor"],
 | 
			
		||||
        ) do |dest, *options|
 | 
			
		||||
          assert_ruby_status(["-C", dir, "extconf.rb", *options])
 | 
			
		||||
          mf = File.read(dir+"/Makefile")
 | 
			
		||||
          a.foreach(
 | 
			
		||||
            ["site"],
 | 
			
		||||
            ["vendor", "--vendor"],
 | 
			
		||||
          ) do |dest, *options|
 | 
			
		||||
            assert_ruby_status(["-C", dir, "extconf.rb", *options])
 | 
			
		||||
            mf = File.read(dir+"/Makefile")
 | 
			
		||||
            a.foreach(
 | 
			
		||||
              ["RUBYCOMMONDIR", "$(#{dest}dir)$(target_prefix)"],
 | 
			
		||||
              ["RUBYLIBDIR",    "$(#{dest}libdir)$(target_prefix)"],
 | 
			
		||||
              ["RUBYARCHDIR",   "$(#{dest}archdir)$(target_prefix)"],
 | 
			
		||||
              ["HDRDIR",        "$(#{dest}hdrdir)$(target_prefix)"],
 | 
			
		||||
              ["ARCHHDRDIR",    "$(#{dest}archhdrdir)$(target_prefix)"],
 | 
			
		||||
            ) do |(var, path)|
 | 
			
		||||
              assert_equal path, mf[/^#{var}\s*=\s*(.*)$/, 1]
 | 
			
		||||
            end
 | 
			
		||||
            ["RUBYCOMMONDIR", "$(#{dest}dir)$(target_prefix)"],
 | 
			
		||||
            ["RUBYLIBDIR",    "$(#{dest}libdir)$(target_prefix)"],
 | 
			
		||||
            ["RUBYARCHDIR",   "$(#{dest}archdir)$(target_prefix)"],
 | 
			
		||||
            ["HDRDIR",        "$(#{dest}hdrdir)$(target_prefix)"],
 | 
			
		||||
            ["ARCHHDRDIR",    "$(#{dest}archhdrdir)$(target_prefix)"],
 | 
			
		||||
          ) do |(var, path)|
 | 
			
		||||
            assert_equal path, mf[/^#{var}\s*=\s*(.*)$/, 1]
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,94 +1,92 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestLibs < TestMkmf
 | 
			
		||||
    def test_split_libs
 | 
			
		||||
      assert_equal(%w[-lfoo -lbar], split_libs("-lfoo -lbar"))
 | 
			
		||||
    end
 | 
			
		||||
class TestMkmfLibs < TestMkmf
 | 
			
		||||
  def test_split_libs
 | 
			
		||||
    assert_equal(%w[-lfoo -lbar], split_libs("-lfoo -lbar"))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_split_libs_macos
 | 
			
		||||
      assert_equal(%w[-ObjC -framework\ Ruby], split_libs("-ObjC -framework Ruby"), 'Bug #6987')
 | 
			
		||||
    end if /darwin/ =~ RUBY_PLATFORM
 | 
			
		||||
  def test_split_libs_macos
 | 
			
		||||
    assert_equal(%w[-ObjC -framework\ Ruby], split_libs("-ObjC -framework Ruby"), 'Bug #6987')
 | 
			
		||||
  end if /darwin/ =~ RUBY_PLATFORM
 | 
			
		||||
 | 
			
		||||
    def test_split_libs_windows
 | 
			
		||||
      assert_equal(%w[zdll.lib libffi.lib], split_libs("zdll.lib libffi.lib"))
 | 
			
		||||
    end if /mswin/ =~ RUBY_PLATFORM
 | 
			
		||||
  def test_split_libs_windows
 | 
			
		||||
    assert_equal(%w[zdll.lib libffi.lib], split_libs("zdll.lib libffi.lib"))
 | 
			
		||||
  end if /mswin/ =~ RUBY_PLATFORM
 | 
			
		||||
 | 
			
		||||
    def assert_in_order(array, x, y, mesg = nil)
 | 
			
		||||
      mesg = "#{x} must proceed to #{y}#{': ' if mesg}#{mesg}"
 | 
			
		||||
      assert_operator(array.index(x), :<, array.rindex(y), mesg)
 | 
			
		||||
    end
 | 
			
		||||
  def assert_in_order(array, x, y, mesg = nil)
 | 
			
		||||
    mesg = "#{x} must proceed to #{y}#{': ' if mesg}#{mesg}"
 | 
			
		||||
    assert_operator(array.index(x), :<, array.rindex(y), mesg)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_merge_simple
 | 
			
		||||
      bug = '[ruby-dev:21765]'
 | 
			
		||||
      assert_equal([], merge_libs(%w[]))
 | 
			
		||||
      assert_equal(%w[a b], merge_libs(%w[a], %w[b]))
 | 
			
		||||
      array = merge_libs(%w[a c], %w[b])
 | 
			
		||||
      assert_in_order(array, "a", "c", bug)
 | 
			
		||||
    end
 | 
			
		||||
  def test_merge_simple
 | 
			
		||||
    bug = '[ruby-dev:21765]'
 | 
			
		||||
    assert_equal([], merge_libs(%w[]))
 | 
			
		||||
    assert_equal(%w[a b], merge_libs(%w[a], %w[b]))
 | 
			
		||||
    array = merge_libs(%w[a c], %w[b])
 | 
			
		||||
    assert_in_order(array, "a", "c", bug)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_merge_seq
 | 
			
		||||
      bug = '[ruby-dev:21765]'
 | 
			
		||||
      array = merge_libs(%w[a c d], %w[c b e])
 | 
			
		||||
      assert_in_order(array, "a", "c", bug)
 | 
			
		||||
      assert_in_order(array, "c", "d", bug)
 | 
			
		||||
      assert_in_order(array, "c", "b", bug)
 | 
			
		||||
      assert_in_order(array, "b", "e", bug)
 | 
			
		||||
    end
 | 
			
		||||
  def test_merge_seq
 | 
			
		||||
    bug = '[ruby-dev:21765]'
 | 
			
		||||
    array = merge_libs(%w[a c d], %w[c b e])
 | 
			
		||||
    assert_in_order(array, "a", "c", bug)
 | 
			
		||||
    assert_in_order(array, "c", "d", bug)
 | 
			
		||||
    assert_in_order(array, "c", "b", bug)
 | 
			
		||||
    assert_in_order(array, "b", "e", bug)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_merge_seq_pre
 | 
			
		||||
      bug = '[ruby-dev:21765]'
 | 
			
		||||
      array = merge_libs(%w[a c d], %w[b c d e])
 | 
			
		||||
      assert_in_order(array, "a", "c", bug)
 | 
			
		||||
      assert_in_order(array, "c", "d", bug)
 | 
			
		||||
      assert_in_order(array, "b", "c", bug)
 | 
			
		||||
      assert_in_order(array, "d", "e", bug)
 | 
			
		||||
    end
 | 
			
		||||
  def test_merge_seq_pre
 | 
			
		||||
    bug = '[ruby-dev:21765]'
 | 
			
		||||
    array = merge_libs(%w[a c d], %w[b c d e])
 | 
			
		||||
    assert_in_order(array, "a", "c", bug)
 | 
			
		||||
    assert_in_order(array, "c", "d", bug)
 | 
			
		||||
    assert_in_order(array, "b", "c", bug)
 | 
			
		||||
    assert_in_order(array, "d", "e", bug)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_merge_cyclic
 | 
			
		||||
      bug = '[ruby-dev:21765]'
 | 
			
		||||
      array = merge_libs(%w[a c d], %w[b c b])
 | 
			
		||||
      assert_in_order(array, "a", "c", bug)
 | 
			
		||||
      assert_in_order(array, "c", "d", bug)
 | 
			
		||||
      assert_in_order(array, "b", "c", bug)
 | 
			
		||||
      assert_in_order(array, "c", "b", bug)
 | 
			
		||||
    end
 | 
			
		||||
  def test_merge_cyclic
 | 
			
		||||
    bug = '[ruby-dev:21765]'
 | 
			
		||||
    array = merge_libs(%w[a c d], %w[b c b])
 | 
			
		||||
    assert_in_order(array, "a", "c", bug)
 | 
			
		||||
    assert_in_order(array, "c", "d", bug)
 | 
			
		||||
    assert_in_order(array, "b", "c", bug)
 | 
			
		||||
    assert_in_order(array, "c", "b", bug)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_merge_cyclic_2
 | 
			
		||||
      bug = '[ruby-dev:21765]'
 | 
			
		||||
      array = merge_libs(%w[a c a d], %w[b c b])
 | 
			
		||||
      assert_in_order(array, "a", "c", bug)
 | 
			
		||||
      assert_in_order(array, "c", "a", bug)
 | 
			
		||||
      assert_in_order(array, "c", "d", bug)
 | 
			
		||||
      assert_in_order(array, "a", "d", bug)
 | 
			
		||||
      assert_in_order(array, "b", "c", bug)
 | 
			
		||||
      assert_in_order(array, "c", "b", bug)
 | 
			
		||||
    end
 | 
			
		||||
  def test_merge_cyclic_2
 | 
			
		||||
    bug = '[ruby-dev:21765]'
 | 
			
		||||
    array = merge_libs(%w[a c a d], %w[b c b])
 | 
			
		||||
    assert_in_order(array, "a", "c", bug)
 | 
			
		||||
    assert_in_order(array, "c", "a", bug)
 | 
			
		||||
    assert_in_order(array, "c", "d", bug)
 | 
			
		||||
    assert_in_order(array, "a", "d", bug)
 | 
			
		||||
    assert_in_order(array, "b", "c", bug)
 | 
			
		||||
    assert_in_order(array, "c", "b", bug)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_merge_reversal
 | 
			
		||||
      bug = '[ruby-dev:22440]'
 | 
			
		||||
      array = merge_libs(%w[a b c], %w[c d a])
 | 
			
		||||
      assert_in_order(array, "a", "b" , bug)
 | 
			
		||||
      assert_in_order(array, "c", "d" , bug)
 | 
			
		||||
      ## assume that a and c have no dependency
 | 
			
		||||
    end
 | 
			
		||||
  def test_merge_reversal
 | 
			
		||||
    bug = '[ruby-dev:22440]'
 | 
			
		||||
    array = merge_libs(%w[a b c], %w[c d a])
 | 
			
		||||
    assert_in_order(array, "a", "b" , bug)
 | 
			
		||||
    assert_in_order(array, "c", "d" , bug)
 | 
			
		||||
    ## assume that a and c have no dependency
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_merge_reversal_followed
 | 
			
		||||
      bug7467 = '[ruby-core:50314] [Bug #7467]'
 | 
			
		||||
      array = nil
 | 
			
		||||
      assert_nothing_raised(bug7467) {
 | 
			
		||||
        array = merge_libs(%w[a b c d e f g h], %w[d c d e], [])
 | 
			
		||||
      }
 | 
			
		||||
      assert_in_order(array, "a", "b", bug7467)
 | 
			
		||||
      assert_in_order(array, "b", "c", bug7467)
 | 
			
		||||
      assert_in_order(array, "c", "d", bug7467)
 | 
			
		||||
      assert_in_order(array, "d", "e", bug7467)
 | 
			
		||||
      assert_in_order(array, "e", "f", bug7467)
 | 
			
		||||
      assert_in_order(array, "f", "g", bug7467)
 | 
			
		||||
      assert_in_order(array, "g", "h", bug7467)
 | 
			
		||||
      assert_in_order(array, "d", "c", bug7467)
 | 
			
		||||
      assert_in_order(array, "c", "e", bug7467)
 | 
			
		||||
    end
 | 
			
		||||
  def test_merge_reversal_followed
 | 
			
		||||
    bug7467 = '[ruby-core:50314] [Bug #7467]'
 | 
			
		||||
    array = nil
 | 
			
		||||
    assert_nothing_raised(bug7467) {
 | 
			
		||||
      array = merge_libs(%w[a b c d e f g h], %w[d c d e], [])
 | 
			
		||||
    }
 | 
			
		||||
    assert_in_order(array, "a", "b", bug7467)
 | 
			
		||||
    assert_in_order(array, "b", "c", bug7467)
 | 
			
		||||
    assert_in_order(array, "c", "d", bug7467)
 | 
			
		||||
    assert_in_order(array, "d", "e", bug7467)
 | 
			
		||||
    assert_in_order(array, "e", "f", bug7467)
 | 
			
		||||
    assert_in_order(array, "f", "g", bug7467)
 | 
			
		||||
    assert_in_order(array, "g", "h", bug7467)
 | 
			
		||||
    assert_in_order(array, "d", "c", bug7467)
 | 
			
		||||
    assert_in_order(array, "c", "e", bug7467)
 | 
			
		||||
  end
 | 
			
		||||
end if RUBY_ENGINE == "ruby"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,14 +2,12 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require 'mkmf'
 | 
			
		||||
 | 
			
		||||
class TestMkmf < Test::Unit::TestCase
 | 
			
		||||
  class TestGlobal < TestMkmf
 | 
			
		||||
    main = TOPLEVEL_BINDING.receiver
 | 
			
		||||
    MakeMakefile.public_instance_methods(false).each do |m|
 | 
			
		||||
      define_method(:"test_global_#{m}") do
 | 
			
		||||
        assert_respond_to(main, [m, true])
 | 
			
		||||
        assert_not_respond_to(main, [m, false])
 | 
			
		||||
      end
 | 
			
		||||
class TestMkmfGlobal < Test::Unit::TestCase
 | 
			
		||||
  main = TOPLEVEL_BINDING.receiver
 | 
			
		||||
  MakeMakefile.public_instance_methods(false).each do |m|
 | 
			
		||||
    define_method(:"test_global_#{m}") do
 | 
			
		||||
      assert_respond_to(main, [m, true])
 | 
			
		||||
      assert_not_respond_to(main, [m, false])
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,67 +2,65 @@
 | 
			
		|||
require_relative 'base'
 | 
			
		||||
require 'shellwords'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestPkgConfig < TestMkmf
 | 
			
		||||
    PKG_CONFIG = find_executable0("pkg-config")
 | 
			
		||||
class TestMkmfPkgConfig < TestMkmf
 | 
			
		||||
  PKG_CONFIG = find_executable0("pkg-config")
 | 
			
		||||
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
 | 
			
		||||
      if PKG_CONFIG
 | 
			
		||||
        @fixtures_dir = File.join(Dir.pwd, "fixtures")
 | 
			
		||||
        @fixtures_lib_dir = File.join(@fixtures_dir, "lib")
 | 
			
		||||
        @fixtures_inc_dir = File.join(@fixtures_dir, "include")
 | 
			
		||||
    if PKG_CONFIG
 | 
			
		||||
      @fixtures_dir = File.join(Dir.pwd, "fixtures")
 | 
			
		||||
      @fixtures_lib_dir = File.join(@fixtures_dir, "lib")
 | 
			
		||||
      @fixtures_inc_dir = File.join(@fixtures_dir, "include")
 | 
			
		||||
 | 
			
		||||
        FileUtils.mkdir(@fixtures_dir)
 | 
			
		||||
        File.write("fixtures/test1.pc", <<~EOF)
 | 
			
		||||
          libdir=#{@fixtures_lib_dir}
 | 
			
		||||
          includedir=#{@fixtures_inc_dir}
 | 
			
		||||
      FileUtils.mkdir(@fixtures_dir)
 | 
			
		||||
      File.write("fixtures/test1.pc", <<~EOF)
 | 
			
		||||
        libdir=#{@fixtures_lib_dir}
 | 
			
		||||
        includedir=#{@fixtures_inc_dir}
 | 
			
		||||
 | 
			
		||||
          Name: test1
 | 
			
		||||
          Description: Test for mkmf pkg-config method
 | 
			
		||||
          Version: 1.2.3
 | 
			
		||||
          Libs: -L${libdir} -ltest1-public
 | 
			
		||||
          Libs.private: -ltest1-private
 | 
			
		||||
          Cflags: -I${includedir}/cflags-I --cflags-other
 | 
			
		||||
        EOF
 | 
			
		||||
        Name: test1
 | 
			
		||||
        Description: Test for mkmf pkg-config method
 | 
			
		||||
        Version: 1.2.3
 | 
			
		||||
        Libs: -L${libdir} -ltest1-public
 | 
			
		||||
        Libs.private: -ltest1-private
 | 
			
		||||
        Cflags: -I${includedir}/cflags-I --cflags-other
 | 
			
		||||
      EOF
 | 
			
		||||
 | 
			
		||||
        @pkg_config_path, ENV["PKG_CONFIG_PATH"] = ENV["PKG_CONFIG_PATH"], File.join(Dir.pwd, "fixtures")
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def teardown
 | 
			
		||||
      if PKG_CONFIG
 | 
			
		||||
        ENV["PKG_CONFIG_PATH"] = @pkg_config_path
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      super
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_pkgconfig_with_option_returns_nil_on_error
 | 
			
		||||
      pend("skipping because pkg-config is not installed") unless PKG_CONFIG
 | 
			
		||||
      assert_nil(pkg_config("package-does-not-exist", "exists"), MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_pkgconfig_with_libs_option_returns_output
 | 
			
		||||
      pend("skipping because pkg-config is not installed") unless PKG_CONFIG
 | 
			
		||||
      expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public"].sort
 | 
			
		||||
      actual = pkg_config("test1", "libs").shellsplit.sort
 | 
			
		||||
      assert_equal(expected, actual, MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_pkgconfig_with_cflags_option_returns_output
 | 
			
		||||
      pend("skipping because pkg-config is not installed") unless PKG_CONFIG
 | 
			
		||||
      expected = ["--cflags-other", "-I#{@fixtures_inc_dir}/cflags-I"].sort
 | 
			
		||||
      actual = pkg_config("test1", "cflags").shellsplit.sort
 | 
			
		||||
      assert_equal(expected, actual, MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_pkgconfig_with_multiple_options
 | 
			
		||||
      pend("skipping because pkg-config is not installed") unless PKG_CONFIG
 | 
			
		||||
      expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public", "-ltest1-private"].sort
 | 
			
		||||
      actual = pkg_config("test1", "libs", "static").shellsplit.sort
 | 
			
		||||
      assert_equal(expected, actual, MKMFLOG)
 | 
			
		||||
      @pkg_config_path, ENV["PKG_CONFIG_PATH"] = ENV["PKG_CONFIG_PATH"], File.join(Dir.pwd, "fixtures")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def teardown
 | 
			
		||||
    if PKG_CONFIG
 | 
			
		||||
      ENV["PKG_CONFIG_PATH"] = @pkg_config_path
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    super
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_pkgconfig_with_option_returns_nil_on_error
 | 
			
		||||
    pend("skipping because pkg-config is not installed") unless PKG_CONFIG
 | 
			
		||||
    assert_nil(pkg_config("package-does-not-exist", "exists"), MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_pkgconfig_with_libs_option_returns_output
 | 
			
		||||
    pend("skipping because pkg-config is not installed") unless PKG_CONFIG
 | 
			
		||||
    expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public"].sort
 | 
			
		||||
    actual = pkg_config("test1", "libs").shellsplit.sort
 | 
			
		||||
    assert_equal(expected, actual, MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_pkgconfig_with_cflags_option_returns_output
 | 
			
		||||
    pend("skipping because pkg-config is not installed") unless PKG_CONFIG
 | 
			
		||||
    expected = ["--cflags-other", "-I#{@fixtures_inc_dir}/cflags-I"].sort
 | 
			
		||||
    actual = pkg_config("test1", "cflags").shellsplit.sort
 | 
			
		||||
    assert_equal(expected, actual, MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_pkgconfig_with_multiple_options
 | 
			
		||||
    pend("skipping because pkg-config is not installed") unless PKG_CONFIG
 | 
			
		||||
    expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public", "-ltest1-private"].sort
 | 
			
		||||
    actual = pkg_config("test1", "libs", "static").shellsplit.sort
 | 
			
		||||
    assert_equal(expected, actual, MKMFLOG)
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,30 +1,28 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestSignedness < TestMkmf
 | 
			
		||||
    def test_typeof_builtin
 | 
			
		||||
      bug4144 = '[ruby-dev:42731]'
 | 
			
		||||
      [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
 | 
			
		||||
        %w[short int long].each do |type|
 | 
			
		||||
          assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144))
 | 
			
		||||
        end
 | 
			
		||||
class TestMkmfSignedness < TestMkmf
 | 
			
		||||
  def test_typeof_builtin
 | 
			
		||||
    bug4144 = '[ruby-dev:42731]'
 | 
			
		||||
    [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
 | 
			
		||||
      %w[short int long].each do |type|
 | 
			
		||||
        assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144))
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_typeof_typedef
 | 
			
		||||
      [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
 | 
			
		||||
        %w[short int long].each do |type|
 | 
			
		||||
          open("confdefs.h", "w") {|f|
 | 
			
		||||
            f.puts "typedef #{signed}#{type} test1_t;"
 | 
			
		||||
          }
 | 
			
		||||
          $defs.clear
 | 
			
		||||
          assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
          assert_include($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}")
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    ensure
 | 
			
		||||
      File.unlink("confdefs.h")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_typeof_typedef
 | 
			
		||||
    [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
 | 
			
		||||
      %w[short int long].each do |type|
 | 
			
		||||
        open("confdefs.h", "w") {|f|
 | 
			
		||||
          f.puts "typedef #{signed}#{type} test1_t;"
 | 
			
		||||
        }
 | 
			
		||||
        $defs.clear
 | 
			
		||||
        assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
        assert_include($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}")
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  ensure
 | 
			
		||||
    File.unlink("confdefs.h")
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,48 +1,46 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'base'
 | 
			
		||||
 | 
			
		||||
class TestMkmf
 | 
			
		||||
  class TestSizeof < TestMkmf
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
      @sizeof_short = config_value("SIZEOF_SHORT").to_i
 | 
			
		||||
      @sizeof_int = config_value("SIZEOF_INT").to_i
 | 
			
		||||
      @sizeof_long = config_value("SIZEOF_LONG").to_i
 | 
			
		||||
      @sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i
 | 
			
		||||
      @sizeof___int64 = config_value("SIZEOF___INT64").to_i
 | 
			
		||||
class TestMkmfSizeof < TestMkmf
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @sizeof_short = config_value("SIZEOF_SHORT").to_i
 | 
			
		||||
    @sizeof_int = config_value("SIZEOF_INT").to_i
 | 
			
		||||
    @sizeof_long = config_value("SIZEOF_LONG").to_i
 | 
			
		||||
    @sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i
 | 
			
		||||
    @sizeof___int64 = config_value("SIZEOF___INT64").to_i
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_sizeof_builtin
 | 
			
		||||
    %w[char short int long float double void*].each do |type|
 | 
			
		||||
      assert_kind_of(Integer, mkmf {check_sizeof(type)}, MKMFLOG)
 | 
			
		||||
    end
 | 
			
		||||
    assert_operator(@sizeof_short, :<=, @sizeof_int)
 | 
			
		||||
    assert_operator(@sizeof_int, :<=, @sizeof_long)
 | 
			
		||||
    assert_operator(@sizeof_long, :<=, @sizeof_long_long) unless @sizeof_long_long.zero?
 | 
			
		||||
    assert_equal(8, @sizeof___int64) unless @sizeof___int64.zero?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
    def test_sizeof_builtin
 | 
			
		||||
      %w[char short int long float double void*].each do |type|
 | 
			
		||||
        assert_kind_of(Integer, mkmf {check_sizeof(type)}, MKMFLOG)
 | 
			
		||||
      end
 | 
			
		||||
      assert_operator(@sizeof_short, :<=, @sizeof_int)
 | 
			
		||||
      assert_operator(@sizeof_int, :<=, @sizeof_long)
 | 
			
		||||
      assert_operator(@sizeof_long, :<=, @sizeof_long_long) unless @sizeof_long_long.zero?
 | 
			
		||||
      assert_equal(8, @sizeof___int64) unless @sizeof___int64.zero?
 | 
			
		||||
    end
 | 
			
		||||
  def test_sizeof_struct
 | 
			
		||||
    open("confdefs.h", "w") {|f|
 | 
			
		||||
      f.puts "typedef struct {char x;} test1_t;"
 | 
			
		||||
    }
 | 
			
		||||
    assert_equal(1, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
 | 
			
		||||
    def test_sizeof_struct
 | 
			
		||||
      open("confdefs.h", "w") {|f|
 | 
			
		||||
        f.puts "typedef struct {char x;} test1_t;"
 | 
			
		||||
      }
 | 
			
		||||
      assert_equal(1, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
    open("confdefs.h", "w") {|f|
 | 
			
		||||
      f.puts "typedef struct {char x, y;} test1_t;"
 | 
			
		||||
    }
 | 
			
		||||
    assert_equal(2, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
 | 
			
		||||
      open("confdefs.h", "w") {|f|
 | 
			
		||||
        f.puts "typedef struct {char x, y;} test1_t;"
 | 
			
		||||
      }
 | 
			
		||||
      assert_equal(2, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
 | 
			
		||||
      open("confdefs.h", "w") {|f|
 | 
			
		||||
        f.puts "typedef struct {int x;} test1_t;"
 | 
			
		||||
      }
 | 
			
		||||
      assert_equal(@sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
      open("confdefs.h", "w") {|f|
 | 
			
		||||
        f.puts "typedef struct {int x, y;} test1_t;"
 | 
			
		||||
      }
 | 
			
		||||
      assert_equal(2 * @sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
    ensure
 | 
			
		||||
      File.unlink("confdefs.h")
 | 
			
		||||
    end
 | 
			
		||||
    open("confdefs.h", "w") {|f|
 | 
			
		||||
      f.puts "typedef struct {int x;} test1_t;"
 | 
			
		||||
    }
 | 
			
		||||
    assert_equal(@sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
    open("confdefs.h", "w") {|f|
 | 
			
		||||
      f.puts "typedef struct {int x, y;} test1_t;"
 | 
			
		||||
    }
 | 
			
		||||
    assert_equal(2 * @sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
 | 
			
		||||
  ensure
 | 
			
		||||
    File.unlink("confdefs.h")
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'test_optparse'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser::Acceptable < TestOptionParser
 | 
			
		||||
class TestOptionParserAcceptable < TestOptionParser
 | 
			
		||||
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,9 +2,7 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require 'optparse/ac'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser < Test::Unit::TestCase; end
 | 
			
		||||
 | 
			
		||||
class TestOptionParser::AutoConf < Test::Unit::TestCase
 | 
			
		||||
class TestOptionParserAutoConf < Test::Unit::TestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    @opt = OptionParser::AC.new
 | 
			
		||||
    @foo = @bar = self.class
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,9 +2,7 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require 'optparse'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
class TestOptionParser::BashCompletion < Test::Unit::TestCase
 | 
			
		||||
class TestOptionParserBashCompletion < Test::Unit::TestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    @opt = OptionParser.new
 | 
			
		||||
    @opt.define("-z", "zzz") {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'test_optparse'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser::CClass < TestOptionParser
 | 
			
		||||
class TestOptionParserCClass < TestOptionParser
 | 
			
		||||
  def test_no_argument
 | 
			
		||||
    flags = []
 | 
			
		||||
    @opt.def_option("-[a-z]") {|x| flags << x}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@ rescue LoadError
 | 
			
		|||
  return
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class TestOptionParser::DidYouMean < TestOptionParser
 | 
			
		||||
class TestOptionParserDidYouMean < TestOptionParser
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @opt.def_option("--foo", Integer) { |v| @foo = v }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,9 +2,7 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require 'optparse'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
class TestOptionParser::Getopts < Test::Unit::TestCase
 | 
			
		||||
class TestOptionParserGetopts < Test::Unit::TestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    @opt = OptionParser.new
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,7 @@ require 'test/unit'
 | 
			
		|||
require 'optparse'
 | 
			
		||||
require 'optparse/kwargs'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
class TestOptionParser::KwArg < Test::Unit::TestCase
 | 
			
		||||
class TestOptionParserKwArg < Test::Unit::TestCase
 | 
			
		||||
  class K
 | 
			
		||||
    def initialize(host:, port: 8080)
 | 
			
		||||
      @host = host
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'test_optparse'
 | 
			
		||||
 | 
			
		||||
module TestOptionParser::NoArg
 | 
			
		||||
module TestOptionParserNoArg
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @opt.def_option "--with_underscore" do |x| @flag = x end
 | 
			
		||||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ module TestOptionParser::NoArg
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  class Def1 < TestOptionParser
 | 
			
		||||
    include NoArg
 | 
			
		||||
    include TestOptionParserNoArg
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
      @opt.def_option("-x") {|x| @flag = x}
 | 
			
		||||
| 
						 | 
				
			
			@ -17,7 +17,7 @@ module TestOptionParser::NoArg
 | 
			
		|||
    end
 | 
			
		||||
  end
 | 
			
		||||
  class Def2 < TestOptionParser
 | 
			
		||||
    include NoArg
 | 
			
		||||
    include TestOptionParserNoArg
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
      @opt.def_option("-x", "--option") {|x| @flag = x}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'test_optparse'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser::OptArg < TestOptionParser
 | 
			
		||||
class TestOptionParserOptArg < TestOptionParser
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @opt.def_option("-x[VAL]") {|x| @flag = x}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'test_optparse'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser::PlaceArg < TestOptionParser
 | 
			
		||||
class TestOptionParserPlaceArg < TestOptionParser
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @opt.def_option("-x [VAL]") {|x| @flag = x}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'test_optparse'
 | 
			
		||||
 | 
			
		||||
module TestOptionParser::ReqArg
 | 
			
		||||
module TestOptionParserReqArg
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @opt.def_option "--with_underscore=VAL" do |x| @flag = x end
 | 
			
		||||
| 
						 | 
				
			
			@ -9,7 +9,7 @@ module TestOptionParser::ReqArg
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  class Def1 < TestOptionParser
 | 
			
		||||
    include ReqArg
 | 
			
		||||
    include TestOptionParserReqArg
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
      @opt.def_option("-xVAL") {|x| @flag = x}
 | 
			
		||||
| 
						 | 
				
			
			@ -19,21 +19,21 @@ module TestOptionParser::ReqArg
 | 
			
		|||
    end
 | 
			
		||||
  end
 | 
			
		||||
  class Def2 < TestOptionParser
 | 
			
		||||
    include ReqArg
 | 
			
		||||
    include TestOptionParserReqArg
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
      @opt.def_option("-x", "--option=VAL") {|x| @flag = x}
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  class Def3 < TestOptionParser
 | 
			
		||||
    include ReqArg
 | 
			
		||||
    include TestOptionParserReqArg
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
      @opt.def_option("--option=VAL", "-x") {|x| @flag = x}
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
  class Def4 < TestOptionParser
 | 
			
		||||
    include ReqArg
 | 
			
		||||
    include TestOptionParserReqArg
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
      @opt.def_option("-xVAL", "--option=VAL") {|x| @flag = x}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
# frozen_string_literal: false
 | 
			
		||||
require_relative 'test_optparse'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser::SummaryTest < TestOptionParser
 | 
			
		||||
class TestOptionParserSummaryTest < TestOptionParser
 | 
			
		||||
  def test_short_clash
 | 
			
		||||
    r = nil
 | 
			
		||||
    o = OptionParser.new do |opts|
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,9 +2,7 @@
 | 
			
		|||
require 'test/unit'
 | 
			
		||||
require 'optparse'
 | 
			
		||||
 | 
			
		||||
class TestOptionParser < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
class TestOptionParser::ZshCompletion < Test::Unit::TestCase
 | 
			
		||||
class TestOptionParserZshCompletion < Test::Unit::TestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    @opt = OptionParser.new
 | 
			
		||||
    @opt.define("-z", "zzz") {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,50 +4,47 @@
 | 
			
		|||
require "test/unit"
 | 
			
		||||
 | 
			
		||||
class TestEmojiBreaks < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
  class BreakTest
 | 
			
		||||
    attr_reader :string, :comment, :filename, :line_number, :type, :shortname
 | 
			
		||||
 | 
			
		||||
class TestEmojiBreaks::BreakTest
 | 
			
		||||
  attr_reader :string, :comment, :filename, :line_number, :type, :shortname
 | 
			
		||||
 | 
			
		||||
  def initialize(filename, line_number, data, comment='')
 | 
			
		||||
    @filename = filename
 | 
			
		||||
    @line_number = line_number
 | 
			
		||||
    @comment = comment.gsub(/\s+/, ' ').strip
 | 
			
		||||
    if filename=='emoji-test' or filename=='emoji-variation-sequences'
 | 
			
		||||
      codes, @type = data.split(/\s*;\s*/)
 | 
			
		||||
      @shortname = ''
 | 
			
		||||
    else
 | 
			
		||||
      codes, @type, @shortname = data.split(/\s*;\s*/)
 | 
			
		||||
    def initialize(filename, line_number, data, comment='')
 | 
			
		||||
      @filename = filename
 | 
			
		||||
      @line_number = line_number
 | 
			
		||||
      @comment = comment.gsub(/\s+/, ' ').strip
 | 
			
		||||
      if filename=='emoji-test' or filename=='emoji-variation-sequences'
 | 
			
		||||
        codes, @type = data.split(/\s*;\s*/)
 | 
			
		||||
        @shortname = ''
 | 
			
		||||
      else
 | 
			
		||||
        codes, @type, @shortname = data.split(/\s*;\s*/)
 | 
			
		||||
      end
 | 
			
		||||
      @type = @type.gsub(/\s+/, ' ').strip
 | 
			
		||||
      @shortname = @shortname.gsub(/\s+/, ' ').strip
 | 
			
		||||
      @string = codes.split(/\s+/)
 | 
			
		||||
                     .map do |ch|
 | 
			
		||||
                            c = ch.to_i(16)
 | 
			
		||||
                             # eliminate cases with surrogates
 | 
			
		||||
                            # raise ArgumentError if 0xD800 <= c and c <= 0xDFFF
 | 
			
		||||
                            c.chr('UTF-8')
 | 
			
		||||
                          end.join
 | 
			
		||||
    end
 | 
			
		||||
    @type = @type.gsub(/\s+/, ' ').strip
 | 
			
		||||
    @shortname = @shortname.gsub(/\s+/, ' ').strip
 | 
			
		||||
    @string = codes.split(/\s+/)
 | 
			
		||||
                   .map do |ch|
 | 
			
		||||
                          c = ch.to_i(16)
 | 
			
		||||
                           # eliminate cases with surrogates
 | 
			
		||||
                          # raise ArgumentError if 0xD800 <= c and c <= 0xDFFF
 | 
			
		||||
                          c.chr('UTF-8')
 | 
			
		||||
                        end.join
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class TestEmojiBreaks::BreakFile
 | 
			
		||||
  attr_reader :basename, :fullname, :version
 | 
			
		||||
  FILES = []
 | 
			
		||||
 | 
			
		||||
  def initialize(basename, path, version)
 | 
			
		||||
    @basename = basename
 | 
			
		||||
    @fullname = "#{path}/#{basename}.txt" # File.expand_path(path + version, __dir__)
 | 
			
		||||
    @version  = version
 | 
			
		||||
    FILES << self
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def self.files
 | 
			
		||||
    FILES
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
  class BreakFile
 | 
			
		||||
    attr_reader :basename, :fullname, :version
 | 
			
		||||
    FILES = []
 | 
			
		||||
 | 
			
		||||
    def initialize(basename, path, version)
 | 
			
		||||
      @basename = basename
 | 
			
		||||
      @fullname = "#{path}/#{basename}.txt" # File.expand_path(path + version, __dir__)
 | 
			
		||||
      @version  = version
 | 
			
		||||
      FILES << self
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def self.files
 | 
			
		||||
      FILES
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
class TestEmojiBreaks < Test::Unit::TestCase
 | 
			
		||||
  UNICODE_VERSION   = RbConfig::CONFIG['UNICODE_VERSION']
 | 
			
		||||
  UNICODE_DATA_PATH = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}/ucd/emoji", __dir__)
 | 
			
		||||
  EMOJI_VERSION     = RbConfig::CONFIG['UNICODE_EMOJI_VERSION']
 | 
			
		||||
| 
						 | 
				
			
			@ -71,86 +68,86 @@ class TestEmojiBreaks < Test::Unit::TestCase
 | 
			
		|||
      omit "Emoji data files not available in #{EMOJI_DATA_PATH}."
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
TestEmojiBreaks.data_files_available? and  class TestEmojiBreaks
 | 
			
		||||
  def read_data
 | 
			
		||||
    tests = []
 | 
			
		||||
    EMOJI_DATA_FILES.each do |file|
 | 
			
		||||
      version_mismatch = true
 | 
			
		||||
      file_tests = []
 | 
			
		||||
      IO.foreach(file.fullname, encoding: Encoding::UTF_8) do |line|
 | 
			
		||||
        line.chomp!
 | 
			
		||||
        if $.==1
 | 
			
		||||
          if line=="# #{file.basename}-#{file.version}.txt"
 | 
			
		||||
            version_mismatch = false
 | 
			
		||||
          elsif line!="# #{file.basename}.txt"
 | 
			
		||||
            raise "File Name Mismatch: line: #{line}, expected filename: #{file.basename}.txt"
 | 
			
		||||
  if data_files_available?
 | 
			
		||||
    def read_data
 | 
			
		||||
      tests = []
 | 
			
		||||
      EMOJI_DATA_FILES.each do |file|
 | 
			
		||||
        version_mismatch = true
 | 
			
		||||
        file_tests = []
 | 
			
		||||
        IO.foreach(file.fullname, encoding: Encoding::UTF_8) do |line|
 | 
			
		||||
          line.chomp!
 | 
			
		||||
          if $.==1
 | 
			
		||||
            if line=="# #{file.basename}-#{file.version}.txt"
 | 
			
		||||
              version_mismatch = false
 | 
			
		||||
            elsif line!="# #{file.basename}.txt"
 | 
			
		||||
              raise "File Name Mismatch: line: #{line}, expected filename: #{file.basename}.txt"
 | 
			
		||||
            end
 | 
			
		||||
          end
 | 
			
		||||
          version_mismatch = false  if line =~ /^# Version: #{file.version}/
 | 
			
		||||
          next  if line.match?(/\A(#|\z)/)
 | 
			
		||||
          if line =~ /^(\h{4,6})\.\.(\h{4,6}) *(;.+)/  # deal with Unicode ranges in emoji-sequences.txt (Bug #18028)
 | 
			
		||||
            range_start = $1.to_i(16)
 | 
			
		||||
            range_end   = $2.to_i(16)
 | 
			
		||||
            rest        = $3
 | 
			
		||||
            (range_start..range_end).each do |code_point|
 | 
			
		||||
              file_tests << BreakTest.new(file.basename, $., *(code_point.to_s(16)+rest).split('#', 2))
 | 
			
		||||
            end
 | 
			
		||||
          else
 | 
			
		||||
            file_tests << BreakTest.new(file.basename, $., *line.split('#', 2))
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
        version_mismatch = false  if line =~ /^# Version: #{file.version}/
 | 
			
		||||
        next  if line.match?(/\A(#|\z)/)
 | 
			
		||||
        if line =~ /^(\h{4,6})\.\.(\h{4,6}) *(;.+)/  # deal with Unicode ranges in emoji-sequences.txt (Bug #18028)
 | 
			
		||||
          range_start = $1.to_i(16)
 | 
			
		||||
          range_end   = $2.to_i(16)
 | 
			
		||||
          rest        = $3
 | 
			
		||||
          (range_start..range_end).each do |code_point|
 | 
			
		||||
            file_tests << BreakTest.new(file.basename, $., *(code_point.to_s(16)+rest).split('#', 2))
 | 
			
		||||
          end
 | 
			
		||||
        else
 | 
			
		||||
          file_tests << BreakTest.new(file.basename, $., *line.split('#', 2))
 | 
			
		||||
        end
 | 
			
		||||
        raise "File Version Mismatch: file: #{file.fullname}, version: #{file.version}"  if version_mismatch
 | 
			
		||||
        tests += file_tests
 | 
			
		||||
      end
 | 
			
		||||
      raise "File Version Mismatch: file: #{file.fullname}, version: #{file.version}"  if version_mismatch
 | 
			
		||||
      tests += file_tests
 | 
			
		||||
      tests
 | 
			
		||||
    end
 | 
			
		||||
    tests
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def all_tests
 | 
			
		||||
    @@tests ||= read_data
 | 
			
		||||
  rescue Errno::ENOENT
 | 
			
		||||
    @@tests ||= []
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_single_emoji
 | 
			
		||||
    all_tests.each do |test|
 | 
			
		||||
      expected = [test.string]
 | 
			
		||||
      actual = test.string.each_grapheme_cluster.to_a
 | 
			
		||||
      assert_equal expected, actual,
 | 
			
		||||
        "file: #{test.filename}, line #{test.line_number}, " +
 | 
			
		||||
        "type: #{test.type}, shortname: #{test.shortname}, comment: #{test.comment}"
 | 
			
		||||
    def all_tests
 | 
			
		||||
      @@tests ||= read_data
 | 
			
		||||
    rescue Errno::ENOENT
 | 
			
		||||
      @@tests ||= []
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_embedded_emoji
 | 
			
		||||
    all_tests.each do |test|
 | 
			
		||||
      expected = ["\t", test.string, "\t"]
 | 
			
		||||
      actual = "\t#{test.string}\t".each_grapheme_cluster.to_a
 | 
			
		||||
      assert_equal expected, actual,
 | 
			
		||||
        "file: #{test.filename}, line #{test.line_number}, " +
 | 
			
		||||
        "type: #{test.type}, shortname: #{test.shortname}, comment: #{test.comment}"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # test some pseodorandom combinations of emoji
 | 
			
		||||
  def test_mixed_emoji
 | 
			
		||||
    srand 0
 | 
			
		||||
    length = all_tests.length
 | 
			
		||||
    step =  503 # use a prime number
 | 
			
		||||
    all_tests.each do |test1|
 | 
			
		||||
      start = rand step
 | 
			
		||||
      start.step(by: step, to: length-1) do |t2|
 | 
			
		||||
        test2 = all_tests[t2]
 | 
			
		||||
        # exclude skin tones, because they glue to previous grapheme clusters
 | 
			
		||||
        next  if (0x1F3FB..0x1F3FF).include? test2.string.ord
 | 
			
		||||
        expected = [test1.string, test2.string]
 | 
			
		||||
        actual = (test1.string+test2.string).each_grapheme_cluster.to_a
 | 
			
		||||
    def test_single_emoji
 | 
			
		||||
      all_tests.each do |test|
 | 
			
		||||
        expected = [test.string]
 | 
			
		||||
        actual = test.string.each_grapheme_cluster.to_a
 | 
			
		||||
        assert_equal expected, actual,
 | 
			
		||||
          "file1: #{test1.filename}, line1 #{test1.line_number}, " +
 | 
			
		||||
          "file2: #{test2.filename}, line2 #{test2.line_number},\n" +
 | 
			
		||||
          "type1: #{test1.type}, shortname1: #{test1.shortname}, comment1: #{test1.comment},\n" +
 | 
			
		||||
          "type2: #{test2.type}, shortname2: #{test2.shortname}, comment2: #{test2.comment}"
 | 
			
		||||
          "file: #{test.filename}, line #{test.line_number}, " +
 | 
			
		||||
          "type: #{test.type}, shortname: #{test.shortname}, comment: #{test.comment}"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_embedded_emoji
 | 
			
		||||
      all_tests.each do |test|
 | 
			
		||||
        expected = ["\t", test.string, "\t"]
 | 
			
		||||
        actual = "\t#{test.string}\t".each_grapheme_cluster.to_a
 | 
			
		||||
        assert_equal expected, actual,
 | 
			
		||||
          "file: #{test.filename}, line #{test.line_number}, " +
 | 
			
		||||
          "type: #{test.type}, shortname: #{test.shortname}, comment: #{test.comment}"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    # test some pseodorandom combinations of emoji
 | 
			
		||||
    def test_mixed_emoji
 | 
			
		||||
      srand 0
 | 
			
		||||
      length = all_tests.length
 | 
			
		||||
      step =  503 # use a prime number
 | 
			
		||||
      all_tests.each do |test1|
 | 
			
		||||
        start = rand step
 | 
			
		||||
        start.step(by: step, to: length-1) do |t2|
 | 
			
		||||
          test2 = all_tests[t2]
 | 
			
		||||
          # exclude skin tones, because they glue to previous grapheme clusters
 | 
			
		||||
          next  if (0x1F3FB..0x1F3FF).include? test2.string.ord
 | 
			
		||||
          expected = [test1.string, test2.string]
 | 
			
		||||
          actual = (test1.string+test2.string).each_grapheme_cluster.to_a
 | 
			
		||||
          assert_equal expected, actual,
 | 
			
		||||
            "file1: #{test1.filename}, line1 #{test1.line_number}, " +
 | 
			
		||||
            "file2: #{test2.filename}, line2 #{test2.line_number},\n" +
 | 
			
		||||
            "type1: #{test1.type}, shortname1: #{test1.shortname}, comment1: #{test1.comment},\n" +
 | 
			
		||||
            "type2: #{test2.type}, shortname2: #{test2.shortname}, comment2: #{test2.comment}"
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,31 +4,28 @@
 | 
			
		|||
require "test/unit"
 | 
			
		||||
 | 
			
		||||
class TestGraphemeBreaksFromFile < Test::Unit::TestCase
 | 
			
		||||
end
 | 
			
		||||
  class BreakTest
 | 
			
		||||
    attr_reader :clusters, :string, :comment, :line_number
 | 
			
		||||
 | 
			
		||||
class TestGraphemeBreaksFromFile::BreakTest
 | 
			
		||||
  attr_reader :clusters, :string, :comment, :line_number
 | 
			
		||||
 | 
			
		||||
  def initialize(line_number, data, comment)
 | 
			
		||||
    @line_number = line_number
 | 
			
		||||
    @comment = comment
 | 
			
		||||
    @clusters = data.sub(/\A\s*÷\s*/, '')
 | 
			
		||||
                    .sub(/\s*÷\s*\z/, '')
 | 
			
		||||
                    .split(/\s*÷\s*/)
 | 
			
		||||
                    .map do |cl|
 | 
			
		||||
                      cl.split(/\s*×\s*/)
 | 
			
		||||
                        .map do |ch|
 | 
			
		||||
                          c = ch.to_i(16)
 | 
			
		||||
                           # eliminate cases with surrogates
 | 
			
		||||
                          raise ArgumentError if 0xD800 <= c and c <= 0xDFFF
 | 
			
		||||
                          c.chr('UTF-8')
 | 
			
		||||
                        end.join
 | 
			
		||||
                    end
 | 
			
		||||
    @string = @clusters.join
 | 
			
		||||
    def initialize(line_number, data, comment)
 | 
			
		||||
      @line_number = line_number
 | 
			
		||||
      @comment = comment
 | 
			
		||||
      @clusters = data.sub(/\A\s*÷\s*/, '')
 | 
			
		||||
                      .sub(/\s*÷\s*\z/, '')
 | 
			
		||||
                      .split(/\s*÷\s*/)
 | 
			
		||||
                      .map do |cl|
 | 
			
		||||
                        cl.split(/\s*×\s*/)
 | 
			
		||||
                          .map do |ch|
 | 
			
		||||
                            c = ch.to_i(16)
 | 
			
		||||
                             # eliminate cases with surrogates
 | 
			
		||||
                            raise ArgumentError if 0xD800 <= c and c <= 0xDFFF
 | 
			
		||||
                            c.chr('UTF-8')
 | 
			
		||||
                          end.join
 | 
			
		||||
                      end
 | 
			
		||||
      @string = @clusters.join
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class TestGraphemeBreaksFromFile < Test::Unit::TestCase
 | 
			
		||||
  UNICODE_VERSION = RbConfig::CONFIG['UNICODE_VERSION']
 | 
			
		||||
  path = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}", __dir__)
 | 
			
		||||
  UNICODE_DATA_PATH = File.directory?("#{path}/ucd/auxiliary") ? "#{path}/ucd/auxiliary" : path
 | 
			
		||||
| 
						 | 
				
			
			@ -43,53 +40,53 @@ class TestGraphemeBreaksFromFile < Test::Unit::TestCase
 | 
			
		|||
      omit "Unicode data file GraphemeBreakTest not available in #{UNICODE_DATA_PATH}."
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
TestGraphemeBreaksFromFile.file_available? and  class TestGraphemeBreaksFromFile
 | 
			
		||||
  def read_data
 | 
			
		||||
    tests = []
 | 
			
		||||
    IO.foreach(GRAPHEME_BREAK_TEST_FILE, encoding: Encoding::UTF_8) do |line|
 | 
			
		||||
      if $. == 1 and not line.start_with?("# GraphemeBreakTest-#{UNICODE_VERSION}.txt")
 | 
			
		||||
        raise "File Version Mismatch"
 | 
			
		||||
  if file_available?
 | 
			
		||||
    def read_data
 | 
			
		||||
      tests = []
 | 
			
		||||
      IO.foreach(GRAPHEME_BREAK_TEST_FILE, encoding: Encoding::UTF_8) do |line|
 | 
			
		||||
        if $. == 1 and not line.start_with?("# GraphemeBreakTest-#{UNICODE_VERSION}.txt")
 | 
			
		||||
          raise "File Version Mismatch"
 | 
			
		||||
        end
 | 
			
		||||
        next if /\A#/.match? line
 | 
			
		||||
        tests << BreakTest.new($., *line.chomp.split('#')) rescue 'whatever'
 | 
			
		||||
      end
 | 
			
		||||
      next if /\A#/.match? line
 | 
			
		||||
      tests << BreakTest.new($., *line.chomp.split('#')) rescue 'whatever'
 | 
			
		||||
      tests
 | 
			
		||||
    end
 | 
			
		||||
    tests
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def all_tests
 | 
			
		||||
    @@tests ||= read_data
 | 
			
		||||
  rescue Errno::ENOENT
 | 
			
		||||
    @@tests ||= []
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_each_grapheme_cluster
 | 
			
		||||
    all_tests.each do |test|
 | 
			
		||||
      expected = test.clusters
 | 
			
		||||
      actual = test.string.each_grapheme_cluster.to_a
 | 
			
		||||
      assert_equal expected, actual,
 | 
			
		||||
        "line #{test.line_number}, expected '#{expected}', " +
 | 
			
		||||
        "but got '#{actual}', comment: #{test.comment}"
 | 
			
		||||
    def all_tests
 | 
			
		||||
      @@tests ||= read_data
 | 
			
		||||
    rescue Errno::ENOENT
 | 
			
		||||
      @@tests ||= []
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_backslash_X
 | 
			
		||||
    all_tests.each do |test|
 | 
			
		||||
      clusters = test.clusters.dup
 | 
			
		||||
      string = test.string.dup
 | 
			
		||||
      removals = 0
 | 
			
		||||
      while string.sub!(/\A\X/, '')
 | 
			
		||||
        removals += 1
 | 
			
		||||
        clusters.shift
 | 
			
		||||
        expected = clusters.join
 | 
			
		||||
    def test_each_grapheme_cluster
 | 
			
		||||
      all_tests.each do |test|
 | 
			
		||||
        expected = test.clusters
 | 
			
		||||
        actual = test.string.each_grapheme_cluster.to_a
 | 
			
		||||
        assert_equal expected, actual,
 | 
			
		||||
          "line #{test.line_number}, expected '#{expected}', " +
 | 
			
		||||
          "but got '#{actual}', comment: #{test.comment}"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def test_backslash_X
 | 
			
		||||
      all_tests.each do |test|
 | 
			
		||||
        clusters = test.clusters.dup
 | 
			
		||||
        string = test.string.dup
 | 
			
		||||
        removals = 0
 | 
			
		||||
        while string.sub!(/\A\X/, '')
 | 
			
		||||
          removals += 1
 | 
			
		||||
          clusters.shift
 | 
			
		||||
          expected = clusters.join
 | 
			
		||||
          assert_equal expected, string,
 | 
			
		||||
            "line #{test.line_number}, removals: #{removals}, expected '#{expected}', " +
 | 
			
		||||
            "but got '#{string}', comment: #{test.comment}"
 | 
			
		||||
        end
 | 
			
		||||
        assert_equal expected, string,
 | 
			
		||||
          "line #{test.line_number}, removals: #{removals}, expected '#{expected}', " +
 | 
			
		||||
          "line #{test.line_number}, after last removal, expected '#{expected}', " +
 | 
			
		||||
          "but got '#{string}', comment: #{test.comment}"
 | 
			
		||||
      end
 | 
			
		||||
      assert_equal expected, string,
 | 
			
		||||
        "line #{test.line_number}, after last removal, expected '#{expected}', " +
 | 
			
		||||
        "but got '#{string}', comment: #{test.comment}"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
 | 
			
		||||
require 'test/unit'
 | 
			
		||||
 | 
			
		||||
class TestMethod < Test::Unit::TestCase
 | 
			
		||||
class TestMethodInlineCache < Test::Unit::TestCase
 | 
			
		||||
  def test_alias
 | 
			
		||||
    m0 = Module.new do
 | 
			
		||||
      def foo; :M0 end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue