-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
module YCP | ||
module Helper | ||
|
||
# helper for transforming YCP regexps to Ruby regexps | ||
# replace YCP regexp metacharacters by Ruby ones | ||
# ^ -> \A, $ -> \z | ||
def self.ruby_regexp reg_str | ||
return nil if reg_str.nil? | ||
|
||
reg_str.gsub(/\A\^/, '\\A').gsub(/\$\z/, '\\z') | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
$LOAD_PATH << File.dirname(__FILE__) | ||
require "test_helper" | ||
|
||
require "ycp/helper" | ||
|
||
class HelperTest < YCP::TestCase | ||
|
||
def test_ruby_regexp | ||
assert_equal "", YCP::Helper.ruby_regexp("") | ||
assert_equal "\\A", YCP::Helper.ruby_regexp("^") | ||
assert_equal "\\z", YCP::Helper.ruby_regexp("$") | ||
assert_equal "\\A\\z", YCP::Helper.ruby_regexp("^$") | ||
assert_equal "\\Aabcd\\z", YCP::Helper.ruby_regexp("^abcd$") | ||
end | ||
|
||
end |