diff options
author | Aaron Patterson <tenderlove@ruby-lang.org> | 2022-09-12 09:53:19 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-10-07 15:18:49 +0900 |
commit | 48a64984063532f4dedf62e8ac4958a3cf3b556d (patch) | |
tree | 751355eebdde0a0bf77e7697b129d0e6a996c5b6 /test | |
parent | 6d01b66764b6dd3fc61c297bd1ec973f8ea686aa (diff) | |
download | ruby-48a64984063532f4dedf62e8ac4958a3cf3b556d.tar.gz |
[ruby/fiddle] Add constants for unsigned values (https://github.com/ruby/fiddle/pull/111)
This commit adds constants for unsigned values. Currently we can use `-`
to mean "unsigned", but I think having a specific name makes Fiddle more
user friendly. This commit continues to support `-`, but introduces
negative constants with "unsigned" names
I think this will help to eliminate [this
code](https://github.com/ruby/ruby/blob/3a56bf0bcc66e14ffe5ec89efc32ecfceed180f4/lib/mjit/c_type.rb#L31-L38)
https://github.com/ruby/fiddle/commit/2bef0f1082
Co-authored-by: Sutou Kouhei <kou@clear-code.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/fiddle/test_import.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/fiddle/test_import.rb b/test/fiddle/test_import.rb index 831c1d310f..ca51781e8a 100644 --- a/test/fiddle/test_import.rb +++ b/test/fiddle/test_import.rb @@ -124,11 +124,21 @@ module Fiddle name = $1.sub(/P\z/,"*").gsub(/_(?!T\z)/, " ").downcase type_name = name end + type_name = "unsigned #{$1}" if type_name =~ /\Au(long|short|char|int|long long)\z/ + define_method("test_sizeof_#{name}") do assert_equal(size, Fiddle::Importer.sizeof(type_name), type) end end + # Assert that the unsigned constants are equal to the "negative" signed ones + # for backwards compatibility + def test_unsigned_equals_negative_signed + Fiddle.constants.grep(/\ATYPE_(?!VOID|VARIADIC\z)(U.*)/) do |unsigned| + assert_equal -Fiddle.const_get(unsigned.to_s.sub(/U/, '')), Fiddle.const_get(unsigned) + end + end + def test_unsigned_result() d = (2 ** 31) + 1 |