From 07bff3956e6149565919255ac2a2b83b68b32248 Mon Sep 17 00:00:00 2001 From: skandhas Date: Sat, 16 Feb 2013 22:22:08 +0800 Subject: fix error output for Module#remove_const --- src/class.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class.c b/src/class.c index e2ee288f4..1715abff1 100644 --- a/src/class.c +++ b/src/class.c @@ -1758,7 +1758,7 @@ mrb_mod_remove_const(mrb_state *mrb, mrb_value mod) check_const_name(mrb, sym); val = mrb_iv_remove(mrb, mod, sym); if (mrb_undef_p(val)) { - mrb_name_error(mrb, sym, "instance variable %s not defined", mrb_sym2name(mrb, sym)); + mrb_name_error(mrb, sym, "constant %s not defined", mrb_sym2name(mrb, sym)); } return val; } -- cgit v1.2.3 From 0aa35895f9f385680cfcccd2077103cc6686ab8a Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 16 Feb 2013 18:15:25 +0000 Subject: Add Module#remove_const test --- test/t/module.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/t/module.rb b/test/t/module.rb index 286c2c085..6c1c1acda 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -241,6 +241,28 @@ assert('Module#remove_class_variable', '15.2.2.4.39') do not Test4RemoveClassVariable.class_variables.include? :@@cv end +assert('Module#remove_const', '15.2.2.4.40') do + module Test4RemoveConst + ExistingConst = 23 + end + + result = Test4RemoveConst.module_eval { remove_const :ExistingConst } + + name_error = false + begin + Test4RemoveConst.module_eval { remove_const :NonExistingConst } + rescue NameError + name_error = true + end + + # Constant removed from Module + not Test4RemoveConst.const_defined? :ExistingConst and + # Return value of binding + result == 23 and + # Name Error raised when Constant doesn't exist + name_error +end + assert('Module#remove_method', '15.2.2.4.41') do module Test4RemoveMethod class Parent -- cgit v1.2.3 From e8c0b61c0decc9bab480b59dc98075c34259a0d8 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 17 Feb 2013 12:13:46 +0000 Subject: String#gsub fix with last character --- mrblib/string.rb | 4 +++- test/t/string.rb | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mrblib/string.rb b/mrblib/string.rb index 9b11bb2e5..8a4894dd4 100644 --- a/mrblib/string.rb +++ b/mrblib/string.rb @@ -28,8 +28,10 @@ class String # # ISO 15.2.10.5.18 def gsub(*args, &block) + lc = '' if args.size == 2 - split(args[0]).join(args[1]) + lc = args[1] if self[-1] == args[0] + split(args[0]).join(args[1]) + lc elsif args.size == 1 && block split(args[0]).join(block.call(args[0])) else diff --git a/test/t/string.rb b/test/t/string.rb index fac77075b..7d0b147d0 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -193,7 +193,9 @@ assert('String#eql?', '15.2.10.5.17') do end assert('String#gsub', '15.2.10.5.18') do - 'abcabc'.gsub('b', 'B') == 'aBcaBc' && 'abcabc'.gsub('b') { |w| w.capitalize } == 'aBcaBc' + 'abcabc'.gsub('b', 'B') == 'aBcaBc' and + 'abcabc'.gsub('b') { |w| w.capitalize } == 'aBcaBc' and + '#a#a#'.gsub('#', '$') == '$a$a$' end assert('String#gsub!', '15.2.10.5.19') do @@ -318,7 +320,9 @@ assert('String#split', '15.2.10.5.35') do end assert('String#sub', '15.2.10.5.36') do - 'abcabc'.sub('b', 'B') == 'aBcabc' && 'abcabc'.sub('b') { |w| w.capitalize } == 'aBcabc' + 'abcabc'.sub('b', 'B') == 'aBcabc' and + 'abcabc'.sub('b') { |w| w.capitalize } == 'aBcabc' and + 'aa#'.sub('#', '$') == 'aa$' end assert('String#sub!', '15.2.10.5.37') do -- cgit v1.2.3 From fb5e83a69b86ec76ccd2b321d0628fc15e00b46c Mon Sep 17 00:00:00 2001 From: Carson McDonald Date: Sun, 17 Feb 2013 07:23:32 -0500 Subject: Fix crash when exiting mirb using ctrl-d when compiled with readline support. --- tools/mirb/mirb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c index 85c3249d2..29685cf28 100644 --- a/tools/mirb/mirb.c +++ b/tools/mirb/mirb.c @@ -191,6 +191,10 @@ main(void) last_code_line[char_index] = '\0'; #else char* line = readline(code_block_open ? "* " : "> "); + if(line == NULL) { + printf("\n"); + break; + } strncat(last_code_line, line, sizeof(last_code_line)-1); add_history(line); free(line); -- cgit v1.2.3