Skip to content

Commit

Permalink
Try fixing false assumptions about wordsize==long_size in ruby/spec
Browse files Browse the repository at this point in the history
  • Loading branch information
XrXr committed Jul 9, 2024
1 parent 5797394 commit f352847
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
12 changes: 12 additions & 0 deletions spec/mspec/lib/mspec/guards/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def self.wsl?
WORD_SIZE
end

C_LONG_SIZE = if defined?(RbConfig::SIZEOF[])
RbConfig::SIZEOF["long"] * 8
else
WORD_SIZE
end

def self.wordsize?(size)
size == WORD_SIZE
end
Expand All @@ -70,6 +76,10 @@ def self.pointer_size?(size)
size == POINTER_SIZE
end

def self.c_long_size?(size)
size == C_LONG_SIZE
end

def initialize(*args)
if args.last.is_a?(Hash)
@options, @platforms = args.last, args[0..-2]
Expand All @@ -89,6 +99,8 @@ def match?
match &&= PlatformGuard.wordsize? value
when :pointer_size
match &&= PlatformGuard.pointer_size? value
when :c_long_size
match &&= PlatformGuard::c_long_size? value
end
end
match
Expand Down
16 changes: 8 additions & 8 deletions spec/ruby/core/array/pack/l_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
it_behaves_like :array_pack_32bit_be, 'L>'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'L<_'
it_behaves_like :array_pack_32bit_le, 'L_<'
Expand All @@ -51,7 +51,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'L<_'
it_behaves_like :array_pack_64bit_le, 'L_<'
Expand Down Expand Up @@ -83,7 +83,7 @@
it_behaves_like :array_pack_32bit_be, 'l>'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'l<_'
it_behaves_like :array_pack_32bit_le, 'l_<'
Expand All @@ -105,7 +105,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'l<_'
it_behaves_like :array_pack_64bit_le, 'l_<'
Expand Down Expand Up @@ -137,7 +137,7 @@
it_behaves_like :array_pack_32bit_le, 'l'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'L_'
end
Expand All @@ -155,7 +155,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'L_'
end
Expand Down Expand Up @@ -183,7 +183,7 @@
it_behaves_like :array_pack_32bit_be, 'l'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'L_'
end
Expand All @@ -201,7 +201,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'L_'
end
Expand Down
16 changes: 8 additions & 8 deletions spec/ruby/core/string/unpack/l_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it_behaves_like :string_unpack_32bit_be_unsigned, 'L>'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_32bit_le, 'L<_'
it_behaves_like :string_unpack_32bit_le, 'L_<'
Expand Down Expand Up @@ -44,7 +44,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_64bit_le, 'L<_'
it_behaves_like :string_unpack_64bit_le, 'L_<'
Expand Down Expand Up @@ -86,7 +86,7 @@
it_behaves_like :string_unpack_32bit_be_signed, 'l>'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_32bit_le, 'l<_'
it_behaves_like :string_unpack_32bit_le, 'l_<'
Expand Down Expand Up @@ -116,7 +116,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_64bit_le, 'l<_'
it_behaves_like :string_unpack_64bit_le, 'l_<'
Expand Down Expand Up @@ -160,7 +160,7 @@
it_behaves_like :string_unpack_32bit_le_signed, 'l'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_32bit_le, 'L_'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L_'
Expand All @@ -182,7 +182,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_64bit_le, 'L_'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L_'
Expand Down Expand Up @@ -218,7 +218,7 @@
it_behaves_like :string_unpack_32bit_be_signed, 'l'
end

platform_is wordsize: 32 do
platform_is c_long_size: 32 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_32bit_be, 'L_'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L_'
Expand All @@ -240,7 +240,7 @@
end
end

platform_is wordsize: 64 do
platform_is c_long_size: 64 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_64bit_be, 'L_'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L_'
Expand Down

0 comments on commit f352847

Please sign in to comment.