Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/array/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def pack_format(count=nil, repeat=nil)
format = instance_variable_get(:@method)
format += count.to_s unless format == 'P' || format == 'p'
format *= repeat if repeat
format.dup # because it may then become tainted
format
end
end

Expand Down
3 changes: 0 additions & 3 deletions core/array/pack/a_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/string'
require_relative 'shared/taint'

describe "Array#pack with format 'A'" do
it_behaves_like :array_pack_basic, 'A'
it_behaves_like :array_pack_basic_non_float, 'A'
it_behaves_like :array_pack_no_platform, 'A'
it_behaves_like :array_pack_string, 'A'
it_behaves_like :array_pack_taint, 'A'

it "calls #to_str to convert an Object to a String" do
obj = mock("pack A string")
Expand Down Expand Up @@ -49,7 +47,6 @@
it_behaves_like :array_pack_basic_non_float, 'a'
it_behaves_like :array_pack_no_platform, 'a'
it_behaves_like :array_pack_string, 'a'
it_behaves_like :array_pack_taint, 'a'

it "adds all the bytes to the output when passed the '*' modifier" do
["abc"].pack("a*").should == "abc"
Expand Down
3 changes: 0 additions & 3 deletions core/array/pack/b_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/encodings'
require_relative 'shared/taint'

describe "Array#pack with format 'B'" do
it_behaves_like :array_pack_basic, 'B'
it_behaves_like :array_pack_basic_non_float, 'B'
it_behaves_like :array_pack_arguments, 'B'
it_behaves_like :array_pack_hex, 'B'
it_behaves_like :array_pack_taint, 'B'

it "calls #to_str to convert an Object to a String" do
obj = mock("pack B string")
Expand Down Expand Up @@ -66,7 +64,6 @@
it_behaves_like :array_pack_basic_non_float, 'b'
it_behaves_like :array_pack_arguments, 'b'
it_behaves_like :array_pack_hex, 'b'
it_behaves_like :array_pack_taint, 'b'

it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
Expand Down
3 changes: 0 additions & 3 deletions core/array/pack/h_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/encodings'
require_relative 'shared/taint'

describe "Array#pack with format 'H'" do
it_behaves_like :array_pack_basic, 'H'
it_behaves_like :array_pack_basic_non_float, 'H'
it_behaves_like :array_pack_arguments, 'H'
it_behaves_like :array_pack_hex, 'H'
it_behaves_like :array_pack_taint, 'H'

it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
Expand Down Expand Up @@ -112,7 +110,6 @@
it_behaves_like :array_pack_basic_non_float, 'h'
it_behaves_like :array_pack_arguments, 'h'
it_behaves_like :array_pack_hex, 'h'
it_behaves_like :array_pack_taint, 'h'

it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
Expand Down
3 changes: 0 additions & 3 deletions core/array/pack/m_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/taint'

describe "Array#pack with format 'M'" do
it_behaves_like :array_pack_basic, 'M'
it_behaves_like :array_pack_basic_non_float, 'M'
it_behaves_like :array_pack_arguments, 'M'
it_behaves_like :array_pack_taint, 'M'

it "encodes an empty string as an empty string" do
[""].pack("M").should == ""
Expand Down Expand Up @@ -202,7 +200,6 @@
it_behaves_like :array_pack_basic, 'm'
it_behaves_like :array_pack_basic_non_float, 'm'
it_behaves_like :array_pack_arguments, 'm'
it_behaves_like :array_pack_taint, 'm'

it "encodes an empty string as an empty string" do
[""].pack("m").should == ""
Expand Down
3 changes: 0 additions & 3 deletions core/array/pack/p_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require_relative '../../../spec_helper'
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/taint'

describe "Array#pack with format 'P'" do
it_behaves_like :array_pack_basic_non_float, 'P'
it_behaves_like :array_pack_taint, 'P'

it "produces as many bytes as there are in a pointer" do
["hello"].pack("P").size.should == [0].pack("J").size
Expand All @@ -22,7 +20,6 @@

describe "Array#pack with format 'p'" do
it_behaves_like :array_pack_basic_non_float, 'p'
it_behaves_like :array_pack_taint, 'p'

it "produces as many bytes as there are in a pointer" do
["hello"].pack("p").size.should == [0].pack("J").size
Expand Down
2 changes: 0 additions & 2 deletions core/array/pack/shared/taint.rb

This file was deleted.

2 changes: 0 additions & 2 deletions core/array/pack/u_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/unicode'
require_relative 'shared/taint'

describe "Array#pack with format 'U'" do
it_behaves_like :array_pack_basic, 'U'
Expand All @@ -16,7 +15,6 @@
it_behaves_like :array_pack_basic, 'u'
it_behaves_like :array_pack_basic_non_float, 'u'
it_behaves_like :array_pack_arguments, 'u'
it_behaves_like :array_pack_taint, 'u'

it "calls #to_str to convert an Object to a String" do
obj = mock("pack u string")
Expand Down
2 changes: 0 additions & 2 deletions core/array/pack/z_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/string'
require_relative 'shared/taint'

describe "Array#pack with format 'Z'" do
it_behaves_like :array_pack_basic, 'Z'
it_behaves_like :array_pack_basic_non_float, 'Z'
it_behaves_like :array_pack_no_platform, 'Z'
it_behaves_like :array_pack_string, 'Z'
it_behaves_like :array_pack_taint, 'Z'

it "calls #to_str to convert an Object to a String" do
obj = mock("pack Z string")
Expand Down
7 changes: 2 additions & 5 deletions core/complex/to_s_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
Complex(1, -5).to_s.should == "1-5i"
Complex(-2.5, -1.5).to_s.should == "-2.5-1.5i"

# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
Complex(1, 0).to_s.should == "1+0i"
Complex(1, -0).to_s.should == "1+0i"
end
Complex(1, 0).to_s.should == "1+0i"
Complex(1, -0).to_s.should == "1+0i"
end

it "returns 1+0.0i for Complex(1, 0.0)" do
Expand Down
33 changes: 15 additions & 18 deletions core/kernel/Complex_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,21 @@

describe "when passed [Integer/Float]" do
it "returns a new Complex number with 0 as the imaginary component" do
# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
Complex(1).should.instance_of?(Complex)
Complex(1).imag.should == 0
Complex(1).real.should == 1

Complex(-3).should.instance_of?(Complex)
Complex(-3).imag.should == 0
Complex(-3).real.should == -3

Complex(-4.5).should.instance_of?(Complex)
Complex(-4.5).imag.should == 0
Complex(-4.5).real.should == -4.5

Complex(bignum_value).should.instance_of?(Complex)
Complex(bignum_value).imag.should == 0
Complex(bignum_value).real.should == bignum_value
end
Complex(1).should.instance_of?(Complex)
Complex(1).imag.should == 0
Complex(1).real.should == 1

Complex(-3).should.instance_of?(Complex)
Complex(-3).imag.should == 0
Complex(-3).real.should == -3

Complex(-4.5).should.instance_of?(Complex)
Complex(-4.5).imag.should == 0
Complex(-4.5).real.should == -4.5

Complex(bignum_value).should.instance_of?(Complex)
Complex(bignum_value).imag.should == 0
Complex(bignum_value).real.should == bignum_value
end
end

Expand Down
11 changes: 4 additions & 7 deletions core/kernel/Rational_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
end

describe "passed Integer" do
# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
it "returns a new Rational number with 1 as the denominator" do
Rational(1).should.eql?(Rational(1, 1))
Rational(-3).should.eql?(Rational(-3, 1))
Rational(bignum_value).should.eql?(Rational(bignum_value, 1))
end
it "returns a new Rational number with 1 as the denominator" do
Rational(1).should.eql?(Rational(1, 1))
Rational(-3).should.eql?(Rational(-3, 1))
Rational(bignum_value).should.eql?(Rational(bignum_value, 1))
end
end

Expand Down
62 changes: 28 additions & 34 deletions core/rational/exponent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@

describe "Rational#**" do
describe "when passed Rational" do
# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
it "returns Rational(1) if the exponent is Rational(0)" do
(Rational(0) ** Rational(0)).should.eql?(Rational(1))
(Rational(1) ** Rational(0)).should.eql?(Rational(1))
(Rational(3, 4) ** Rational(0)).should.eql?(Rational(1))
(Rational(-1) ** Rational(0)).should.eql?(Rational(1))
(Rational(-3, 4) ** Rational(0)).should.eql?(Rational(1))
(Rational(bignum_value) ** Rational(0)).should.eql?(Rational(1))
(Rational(-bignum_value) ** Rational(0)).should.eql?(Rational(1))
end
it "returns Rational(1) if the exponent is Rational(0)" do
(Rational(0) ** Rational(0)).should.eql?(Rational(1))
(Rational(1) ** Rational(0)).should.eql?(Rational(1))
(Rational(3, 4) ** Rational(0)).should.eql?(Rational(1))
(Rational(-1) ** Rational(0)).should.eql?(Rational(1))
(Rational(-3, 4) ** Rational(0)).should.eql?(Rational(1))
(Rational(bignum_value) ** Rational(0)).should.eql?(Rational(1))
(Rational(-bignum_value) ** Rational(0)).should.eql?(Rational(1))
end

it "returns self raised to the argument as a Rational if the exponent's denominator is 1" do
(Rational(3, 4) ** Rational(1, 1)).should.eql?(Rational(3, 4))
(Rational(3, 4) ** Rational(2, 1)).should.eql?(Rational(9, 16))
(Rational(3, 4) ** Rational(-1, 1)).should.eql?(Rational(4, 3))
(Rational(3, 4) ** Rational(-2, 1)).should.eql?(Rational(16, 9))
end
it "returns self raised to the argument as a Rational if the exponent's denominator is 1" do
(Rational(3, 4) ** Rational(1, 1)).should.eql?(Rational(3, 4))
(Rational(3, 4) ** Rational(2, 1)).should.eql?(Rational(9, 16))
(Rational(3, 4) ** Rational(-1, 1)).should.eql?(Rational(4, 3))
(Rational(3, 4) ** Rational(-2, 1)).should.eql?(Rational(16, 9))
end

it "returns self raised to the argument as a Float if the exponent's denominator is not 1" do
(Rational(3, 4) ** Rational(4, 3)).should be_close(0.681420222312052, TOLERANCE)
(Rational(3, 4) ** Rational(-4, 3)).should be_close(1.46752322173095, TOLERANCE)
(Rational(3, 4) ** Rational(4, -3)).should be_close(1.46752322173095, TOLERANCE)
end
it "returns self raised to the argument as a Float if the exponent's denominator is not 1" do
(Rational(3, 4) ** Rational(4, 3)).should be_close(0.681420222312052, TOLERANCE)
(Rational(3, 4) ** Rational(-4, 3)).should be_close(1.46752322173095, TOLERANCE)
(Rational(3, 4) ** Rational(4, -3)).should be_close(1.46752322173095, TOLERANCE)
end

it "returns a complex number when self is negative and the passed argument is not 0" do
(Rational(-3, 4) ** Rational(-4, 3)).should be_close(Complex(-0.7337616108654732, 1.2709123906625817), TOLERANCE)
end
it "returns a complex number when self is negative and the passed argument is not 0" do
(Rational(-3, 4) ** Rational(-4, 3)).should be_close(Complex(-0.7337616108654732, 1.2709123906625817), TOLERANCE)
end
end

Expand All @@ -46,16 +43,13 @@
(Rational(3, -bignum_value) ** -4).should == Rational(115792089237316195423570985008687907853269984665640564039457584007913129639936, 81)
end

# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
it "returns Rational(1, 1) when the passed argument is 0" do
(Rational(3, 4) ** 0).should.eql?(Rational(1, 1))
(Rational(-3, 4) ** 0).should.eql?(Rational(1, 1))
(Rational(3, -4) ** 0).should.eql?(Rational(1, 1))
it "returns Rational(1, 1) when the passed argument is 0" do
(Rational(3, 4) ** 0).should.eql?(Rational(1, 1))
(Rational(-3, 4) ** 0).should.eql?(Rational(1, 1))
(Rational(3, -4) ** 0).should.eql?(Rational(1, 1))

(Rational(bignum_value, 4) ** 0).should.eql?(Rational(1, 1))
(Rational(3, -bignum_value) ** 0).should.eql?(Rational(1, 1))
end
(Rational(bignum_value, 4) ** 0).should.eql?(Rational(1, 1))
(Rational(3, -bignum_value) ** 0).should.eql?(Rational(1, 1))
end
end

Expand Down
5 changes: 1 addition & 4 deletions core/rational/inspect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
Rational(-5, 8).inspect.should == "(-5/8)"
Rational(-1, -2).inspect.should == "(1/2)"

# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
Rational(bignum_value, 1).inspect.should == "(#{bignum_value}/1)"
end
Rational(bignum_value, 1).inspect.should == "(#{bignum_value}/1)"
end
end
7 changes: 2 additions & 5 deletions core/rational/integer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require_relative "../../spec_helper"
describe "Rational#integer?" do
# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
it "returns false for a rational with a numerator and no denominator" do
Rational(20).integer?.should == false
end
it "returns false for a rational with a numerator and no denominator" do
Rational(20).integer?.should == false
end

it "returns false for a rational with a numerator and a denominator" do
Expand Down
7 changes: 2 additions & 5 deletions core/rational/round_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@
it "returns a Rational" do
@rational.round(1).should.is_a?(Rational)
@rational.round(2).should.is_a?(Rational)
# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
Rational(0, 1).round(1).should.is_a?(Rational)
Rational(2, 1).round(1).should.is_a?(Rational)
end
Rational(0, 1).round(1).should.is_a?(Rational)
Rational(2, 1).round(1).should.is_a?(Rational)
end

it "moves the truncation point n decimal places right" do
Expand Down
7 changes: 2 additions & 5 deletions core/rational/to_s_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

describe "Rational#to_s" do
it "returns a string representation of self" do
# Guard against the Mathn library
guard -> { !defined?(Math.rsqrt) } do
Rational(1, 1).to_s.should == "1/1"
Rational(2, 1).to_s.should == "2/1"
end
Rational(1, 1).to_s.should == "1/1"
Rational(2, 1).to_s.should == "2/1"
Rational(1, 2).to_s.should == "1/2"
Rational(-1, 3).to_s.should == "-1/3"
Rational(1, -3).to_s.should == "-1/3"
Expand Down
2 changes: 1 addition & 1 deletion core/string/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Object
def unpack_format(count=nil, repeat=nil)
format = "#{instance_variable_get(:@method)}#{count}"
format *= repeat if repeat
format.dup # because it may then become tainted
format
end
end

Expand Down
3 changes: 0 additions & 3 deletions core/string/unpack/a_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
require_relative '../fixtures/classes'
require_relative 'shared/basic'
require_relative 'shared/string'
require_relative 'shared/taint'

describe "String#unpack with format 'A'" do
it_behaves_like :string_unpack_basic, 'A'
it_behaves_like :string_unpack_no_platform, 'A'
it_behaves_like :string_unpack_string, 'A'
it_behaves_like :string_unpack_Aa, 'A'
it_behaves_like :string_unpack_taint, 'A'

it "removes trailing space and NULL bytes from the decoded string" do
[ ["a\x00 b \x00", ["a\x00 b", ""]],
Expand Down Expand Up @@ -42,7 +40,6 @@
it_behaves_like :string_unpack_no_platform, 'a'
it_behaves_like :string_unpack_string, 'a'
it_behaves_like :string_unpack_Aa, 'a'
it_behaves_like :string_unpack_taint, 'a'

it "does not remove trailing whitespace or NULL bytes from the decoded string" do
[ ["a\x00 b \x00", ["a\x00 b \x00"]],
Expand Down
Loading
Loading