diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-11-29 15:50:28 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-11-29 15:50:28 +0100 |
commit | 67a1e2258974df4b597d019739595c18fbb9a7c1 (patch) | |
tree | 992ad4fc0fc08a6af8f04373703a339f957eb143 /spec/ruby/optional | |
parent | e6d93a27afa058319e6dad093bbef637e49fce47 (diff) | |
download | ruby-67a1e2258974df4b597d019739595c18fbb9a7c1.tar.gz |
Update to ruby/spec@7f22a0b
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r-- | spec/ruby/optional/capi/class_spec.rb | 5 | ||||
-rw-r--r-- | spec/ruby/optional/capi/ext/string_spec.c | 10 | ||||
-rw-r--r-- | spec/ruby/optional/capi/fixtures/class.rb | 3 | ||||
-rw-r--r-- | spec/ruby/optional/capi/string_spec.rb | 27 |
4 files changed, 44 insertions, 1 deletions
diff --git a/spec/ruby/optional/capi/class_spec.rb b/spec/ruby/optional/capi/class_spec.rb index c2424668b9..a2d8b3e38a 100644 --- a/spec/ruby/optional/capi/class_spec.rb +++ b/spec/ruby/optional/capi/class_spec.rb @@ -12,6 +12,7 @@ autoload :ClassIdUnderAutoload, "#{object_path}/class_id_under_autoload_spec" describe :rb_path_to_class, shared: true do it "returns a class or module from a scoped String" do @s.send(@method, "CApiClassSpecs::A::B").should equal(CApiClassSpecs::A::B) + @s.send(@method, "CApiClassSpecs::A::M").should equal(CApiClassSpecs::A::M) end it "resolves autoload constants" do @@ -27,7 +28,9 @@ describe :rb_path_to_class, shared: true do end it "raises a TypeError if the constant is not a class or module" do - -> { @s.send(@method, "CApiClassSpecs::A::C") }.should raise_error(TypeError) + -> { + @s.send(@method, "CApiClassSpecs::A::C") + }.should raise_error(TypeError, 'CApiClassSpecs::A::C does not refer to class/module') end it "raises an ArgumentError even if a constant in the path exists on toplevel" do diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index 099363c951..2a21304a10 100644 --- a/spec/ruby/optional/capi/ext/string_spec.c +++ b/spec/ruby/optional/capi/ext/string_spec.c @@ -577,6 +577,14 @@ static VALUE string_spec_rb_str_catf(VALUE self, VALUE mesg) { return rb_str_catf(mesg, "fmt %d %d number", 41, 6); } +static VALUE string_spec_rb_str_locktmp(VALUE self, VALUE str) { + return rb_str_locktmp(str); +} + +static VALUE string_spec_rb_str_unlocktmp(VALUE self, VALUE str) { + return rb_str_unlocktmp(str); +} + void Init_string_spec(void) { VALUE cls = rb_define_class("CApiStringSpecs", rb_cObject); rb_define_method(cls, "rb_cstr2inum", string_spec_rb_cstr2inum, 2); @@ -672,6 +680,8 @@ void Init_string_spec(void) { rb_define_method(cls, "rb_utf8_str_new_cstr", string_spec_rb_utf8_str_new_cstr, 0); rb_define_method(cls, "rb_str_vcatf", string_spec_rb_str_vcatf, 1); rb_define_method(cls, "rb_str_catf", string_spec_rb_str_catf, 1); + rb_define_method(cls, "rb_str_locktmp", string_spec_rb_str_locktmp, 1); + rb_define_method(cls, "rb_str_unlocktmp", string_spec_rb_str_unlocktmp, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/fixtures/class.rb b/spec/ruby/optional/capi/fixtures/class.rb index dbb0b69967..193c7174e0 100644 --- a/spec/ruby/optional/capi/fixtures/class.rb +++ b/spec/ruby/optional/capi/fixtures/class.rb @@ -87,5 +87,8 @@ class CApiClassSpecs class B end + + module M + end end end diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 3cd88a7390..ce387ffa49 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -1209,4 +1209,31 @@ end str.should == "test fmt 41 6 number" end end + + describe "rb_str_locktmp" do + it "raises an error when trying to lock an already locked string" do + str = "test" + @s.rb_str_locktmp(str).should == str + -> { @s.rb_str_locktmp(str) }.should raise_error(RuntimeError, 'temporal locking already locked string') + end + + it "locks a string so that modifications would raise an error" do + str = "test" + @s.rb_str_locktmp(str).should == str + -> { str.upcase! }.should raise_error(RuntimeError, 'can\'t modify string; temporarily locked') + end + end + + describe "rb_str_unlocktmp" do + it "unlocks a locked string" do + str = "test" + @s.rb_str_locktmp(str) + @s.rb_str_unlocktmp(str).should == str + str.upcase!.should == "TEST" + end + + it "raises an error when trying to unlock an already unlocked string" do + -> { @s.rb_str_unlocktmp("test") }.should raise_error(RuntimeError, 'temporal unlocking already unlocked string') + end + end end |