diff --git a/ext/-test-/testutil/extconf.rb b/ext/-test-/testutil/extconf.rb new file mode 100644 index 0000000000..157a3d62b8 --- /dev/null +++ b/ext/-test-/testutil/extconf.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: false +$INCFLAGS << " -I$(topdir) -I$(top_srcdir)" +$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] +inits = $srcs.map {|s| File.basename(s, ".*")} +inits.delete("init") +inits.map! {|s|"X(#{s})"} +$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\"" +create_makefile("-test-/testutil") diff --git a/ext/-test-/testutil/init.c b/ext/-test-/testutil/init.c new file mode 100644 index 0000000000..cf2804df4f --- /dev/null +++ b/ext/-test-/testutil/init.c @@ -0,0 +1,11 @@ +#include "ruby.h" + +#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);} + +void +Init_testutil(void) +{ + VALUE mBug = rb_define_module("Bug"); + VALUE klass = rb_define_class_under(mBug, "TestUtil", rb_cObject); + TEST_INIT_FUNCS(init); +} diff --git a/ext/-test-/testutil/integer.c b/ext/-test-/testutil/integer.c new file mode 100644 index 0000000000..da5812c616 --- /dev/null +++ b/ext/-test-/testutil/integer.c @@ -0,0 +1,29 @@ +#include "internal.h" + +static VALUE +int_bignum_p(VALUE self) +{ + return RB_TYPE_P(self, T_BIGNUM) ? Qtrue : Qfalse; +} + +static VALUE +int_fixnum_p(VALUE self) +{ + return FIXNUM_P(self) ? Qtrue : Qfalse; +} + +static VALUE +rb_int_to_bignum(VALUE x) +{ + if (FIXNUM_P(x)) + x = rb_int2big(FIX2LONG(x)); + return x; +} + +void +Init_integer(VALUE klass) +{ + rb_define_method(rb_cInteger, "bignum?", int_bignum_p, 0); + rb_define_method(rb_cInteger, "fixnum?", int_fixnum_p, 0); + rb_define_method(rb_cInteger, "to_bignum", rb_int_to_bignum, 0); +}