Skip to content

Commit

Permalink
fix lastnotof
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed May 10, 2013
1 parent 711a501 commit c703e03
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ruby/ycp/builtins.rb
Expand Up @@ -622,7 +622,7 @@ def self.topath object
return object
when ::String
object = "."+object unless object.start_with?(".")
return YCP::Path.new object
return YCP::Path.new(object)
else
return nil
end
Expand Down Expand Up @@ -685,7 +685,7 @@ def self.filterchars string, chars
def self.findfirstnotof string, chars
return nil if string.nil? || chars.nil?

return string.index /^[#{Regexp.escape chars}]/
return string.index /[^#{Regexp.escape chars}]/
end

# Finds position of the first matching characters in string
Expand All @@ -699,7 +699,7 @@ def self.findfirstof string, chars
def self.findlastnotof string, chars
return nil if string.nil? || chars.nil?

return string.rindex /^[#{Regexp.escape chars}]/
return string.rindex /[^#{Regexp.escape chars}]/
end

# Searches string for the last match
Expand Down
42 changes: 42 additions & 0 deletions tests/ruby/builtins_test.rb
Expand Up @@ -750,6 +750,48 @@ def test_findfirstof
end
end

FINDFIRSTNOTOF_TESTDATA = [
[nil,"ab",nil],
["ab",nil,nil],
["aaaaa","z",0],
["abcdefg","cxdv",0],
["\s\t\n","\s",1],
["\n\n\t","\n",2]
]
def test_findfirstnotof
FINDFIRSTNOTOF_TESTDATA.each do |string,chars,result|
assert_equal result, YCP::Builtins.findfirstnotof(string,chars)
end
end

FINDLASTOF_TESTDATA = [
[nil,"ab",nil],
["ab",nil,nil],
["aaaaa","z",nil],
["abcdefg","cxdv",3],
["\s\t\n","\s",0],
["\s\t\n","\n",2]
]
def test_findlastof
FINDLASTOF_TESTDATA.each do |string,chars,result|
assert_equal result, YCP::Builtins.findlastof(string,chars)
end
end

FINDLASTNOTOF_TESTDATA = [
[nil,"ab",nil],
["ab",nil,nil],
["aaaaa","z",4],
["abcdefg","cxdv",6],
["\s\t\s","\s",1],
["\t\n\n","\n",0]
]
def test_findlastnotof
FINDLASTNOTOF_TESTDATA.each do |string,chars,result|
assert_equal result, YCP::Builtins.findlastnotof(string,chars)
end
end

def test_float_tolstring
old_lang = ENV["LANG"]
ENV["LANG"] = "cs_CZ.utf-8"
Expand Down

0 comments on commit c703e03

Please sign in to comment.