diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-03 16:19:40 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-08-03 16:19:40 +0000 |
commit | b53cf149ad8d7c46572e4567ca949b4f82ebb22c (patch) | |
tree | ee5032bcb38573dade8ba2c46acbcc0d5f3ddfe3 /spec/ruby/optional | |
parent | aeeaadaad08038217440c1e9e7c5ca126d7dc633 (diff) | |
download | ruby-b53cf149ad8d7c46572e4567ca949b4f82ebb22c.tar.gz |
Update to ruby/spec@9be7c7e
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r-- | spec/ruby/optional/capi/encoding_spec.rb | 18 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/encoding_spec.c | 2 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/rubyspec.h | 6 | ||||
-rw-r--r-- | spec/ruby/optional/capi/module_spec.rb | 24 |
4 files changed, 41 insertions, 9 deletions
diff --git a/spec/ruby/optional/capi/encoding_spec.rb b/spec/ruby/optional/capi/encoding_spec.rb index 33587bf03a..88b3e47833 100644 --- a/spec/ruby/optional/capi/encoding_spec.rb +++ b/spec/ruby/optional/capi/encoding_spec.rb @@ -46,10 +46,12 @@ describe "C-API Encoding function" do @s = CApiEncodingSpecs.new end - describe "rb_enc_alias" do - it "creates an alias for an existing Encoding" do - @s.rb_enc_alias("ZOMGWTFBBQ", "UTF-8").should >= 0 - Encoding.find("ZOMGWTFBBQ").name.should == "UTF-8" + ruby_version_is "2.6" do + describe "rb_enc_alias" do + it "creates an alias for an existing Encoding" do + @s.rb_enc_alias("ZOMGWTFBBQ", "UTF-8").should >= 0 + Encoding.find("ZOMGWTFBBQ").name.should == "UTF-8" + end end end @@ -148,9 +150,11 @@ describe "C-API Encoding function" do @s.send(@method, 1).should == -1 end - it "returns -1 for an object without an encoding" do - obj = Object.new - @s.send(@method, obj).should == -1 + ruby_version_is "2.6" do + it "returns -1 for an object without an encoding" do + obj = Object.new + @s.send(@method, obj).should == -1 + end end end diff --git a/spec/ruby/optional/capi/ext/encoding_spec.c b/spec/ruby/optional/capi/ext/encoding_spec.c index 87b97f3a1b..9ab893b86a 100644 --- a/spec/ruby/optional/capi/ext/encoding_spec.c +++ b/spec/ruby/optional/capi/ext/encoding_spec.c @@ -94,8 +94,6 @@ static VALUE encoding_spec_rb_default_external_encoding(VALUE self) { #endif #ifdef HAVE_RB_ENC_ALIAS -extern int rb_enc_alias(const char* alias, const char* orig); - static VALUE encoding_spec_rb_enc_alias(VALUE self, VALUE alias, VALUE orig) { return INT2NUM(rb_enc_alias(RSTRING_PTR(alias), RSTRING_PTR(orig))); } diff --git a/spec/ruby/optional/capi/ext/rubyspec.h b/spec/ruby/optional/capi/ext/rubyspec.h index 1ece9541c7..e5a90bfc88 100644 --- a/spec/ruby/optional/capi/ext/rubyspec.h +++ b/spec/ruby/optional/capi/ext/rubyspec.h @@ -23,6 +23,10 @@ (RUBY_VERSION_MAJOR == (major) && RUBY_VERSION_MINOR < (minor)) || \ (RUBY_VERSION_MAJOR == (major) && RUBY_VERSION_MINOR == (minor) && RUBY_VERSION_TEENY < (teeny))) +#if RUBY_VERSION_MAJOR > 2 || (RUBY_VERSION_MAJOR == 2 && RUBY_VERSION_MINOR >= 6) +#define RUBY_VERSION_IS_2_6 +#endif + #if RUBY_VERSION_MAJOR > 2 || (RUBY_VERSION_MAJOR == 2 && RUBY_VERSION_MINOR >= 4) #define RUBY_VERSION_IS_2_4 #endif @@ -204,7 +208,9 @@ #define HAVE_RB_DEFAULT_INTERNAL_ENCODING 1 #define HAVE_RB_DEFAULT_EXTERNAL_ENCODING 1 +#ifdef RUBY_VERSION_IS_2_6 #define HAVE_RB_ENC_ALIAS 1 +#endif #define HAVE_RB_ENC_ASSOCIATE 1 #define HAVE_RB_ENC_ASSOCIATE_INDEX 1 #define HAVE_RB_ENC_CODEPOINT_LEN 1 diff --git a/spec/ruby/optional/capi/module_spec.rb b/spec/ruby/optional/capi/module_spec.rb index 5ce1ed205b..b94e96e846 100644 --- a/spec/ruby/optional/capi/module_spec.rb +++ b/spec/ruby/optional/capi/module_spec.rb @@ -30,6 +30,20 @@ describe "CApiModule" do }.should complain(/already initialized constant/) CApiModuleSpecs::C::Z.should == 8 end + + it "allows arbitrary names, including constant names not valid in Ruby" do + -> { + CApiModuleSpecs::C.const_set(:_INVALID, 1) + }.should raise_error(NameError, /wrong constant name/) + + @m.rb_const_set(CApiModuleSpecs::C, :_INVALID, 2) + @m.rb_const_get(CApiModuleSpecs::C, :_INVALID).should == 2 + + # Ruby-level should still not allow access + -> { + CApiModuleSpecs::C.const_get(:_INVALID) + }.should raise_error(NameError, /wrong constant name/) + end end describe "rb_define_module" do @@ -140,6 +154,16 @@ describe "CApiModule" do it "resolves autoload constants in Object" do @m.rb_const_get(Object, :CApiModuleSpecsAutoload).should == 123 end + + it "allows arbitrary names, including constant names not valid in Ruby" do + -> { + CApiModuleSpecs::A.const_get(:_INVALID) + }.should raise_error(NameError, /wrong constant name/) + + -> { + @m.rb_const_get(CApiModuleSpecs::A, :_INVALID) + }.should raise_error(NameError, /uninitialized constant/) + end end describe "rb_const_get_from" do |