Created
January 18, 2011 18:56
-
-
Save semmons99/784930 to your computer and use it in GitHub Desktop.
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
def parse(name) | |
case name | |
when /^\[(.+)\](.+)\[(.+)\]$/ | |
[ $1 + $2 + $3, $1 + $2, $2 + $3, $2 ] | |
when /^\[(.+)\](.+)$/ | |
[ $1 + $2, $2 ] | |
when /^(.+)\[(.+)\]$/ | |
[ $1, $1 + $2 ] | |
else | |
[ name ] | |
end | |
end | |
describe "parse" do | |
it "should list all permutations, text in brackets is optional" do | |
strings = parse("foo[bar]") | |
strings.should include('foo') | |
strings.should include('foobar') | |
strings.should_not include('bar') | |
strings.size.should == 2 | |
end | |
it "should list all permutations, text in brackets is optional" do | |
strings = parse("[foo]bar") | |
strings.should include('bar') | |
strings.should include('foobar') | |
strings.should_not include('foo') | |
strings.size.should == 2 | |
end | |
it "should list all permutations, text in brackets is optional" do | |
strings = parse("[foo]bar[baz]") | |
strings.should include('foobar') | |
strings.should include('bar') | |
strings.should include('barbaz') | |
strings.should include('foobarbaz') | |
strings.should_not include('foo') | |
strings.should_not include('baz') | |
strings.size.should == 4 | |
end | |
it "should return the string, when there are no brackets" do | |
strings = parse("foo") | |
strings.should include('foo') | |
strings.size.should == 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
no problem