Skip to content

Commit

Permalink
flip anchor default for to_regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jun 22, 2010
1 parent a38a201 commit 4a637bc
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions lib/regin/character.rb
Expand Up @@ -26,14 +26,14 @@ def to_s(parent = false)
end
end

def to_regexp(anchored = true)
def to_regexp(anchored = false)
re = to_s(true)
re = "\\A#{re}\\Z" if anchored
Regexp.compile(re, ignorecase)
end

def match(char)
to_regexp.match(char)
to_regexp(true).match(char)
end

def include?(char)
Expand Down
2 changes: 1 addition & 1 deletion lib/regin/collection.rb
Expand Up @@ -32,7 +32,7 @@ def +(other)
self.class.new(@array + ary)
end

def to_regexp(anchored = true)
def to_regexp(anchored = false)
re = to_s(true)
re = "\\A#{re}\\Z" if anchored
Regexp.compile(re, flags)
Expand Down
2 changes: 1 addition & 1 deletion lib/regin/group.rb
Expand Up @@ -34,7 +34,7 @@ def to_s(parent = false)
end
end

def to_regexp(anchored = true)
def to_regexp(anchored = false)
re = to_s
re = "\\A#{re}\\Z" if anchored
Regexp.compile(re)
Expand Down
4 changes: 2 additions & 2 deletions spec/alternation_spec.rb
Expand Up @@ -19,7 +19,7 @@
end

it "should return a regexp of itself" do
@alternation.to_regexp.should == /\Aa|b|c\Z/
@alternation.to_regexp.should == /a|b|c/
end

it "should match 'a'" do
Expand Down Expand Up @@ -97,7 +97,7 @@
end

it "should return a regexp of itself" do
@alternation.to_regexp.should == /\Aa|b|c\Z/
@alternation.to_regexp.should == /a|b|c/
end

it "should apply ignorecase to child expression" do
Expand Down
12 changes: 6 additions & 6 deletions spec/character_range_spec.rb
Expand Up @@ -26,7 +26,7 @@
end

it "should return a regexp of itself" do
@range.to_regexp.should == /\A[a-z]\Z/
@range.to_regexp.should == /[a-z]/
end

it "should be inspectable" do
Expand Down Expand Up @@ -92,7 +92,7 @@
end

it "should return a regexp of itself" do
@range.to_regexp.should == /\A.\Z/
@range.to_regexp.should == /./
end

it "should be inspectable" do
Expand Down Expand Up @@ -137,7 +137,7 @@
end

it "should return a regexp of itself" do
@range.to_regexp.should == /\A[a-z]{2,3}\Z/
@range.to_regexp.should == /[a-z]{2,3}/
end

it "should be inspectable" do
Expand Down Expand Up @@ -167,7 +167,7 @@
end

it "should return a regexp of itself" do
@range.to_regexp.should == /\A[^a-z]\Z/
@range.to_regexp.should == /[^a-z]/
end

it "should be inspectable" do
Expand Down Expand Up @@ -209,7 +209,7 @@
end

it "should return a regexp of itself" do
@range.to_regexp.should == /\A[a-z]\Z/i
@range.to_regexp.should == /[a-z]/i
end

it "should be inspectable" do
Expand Down Expand Up @@ -246,7 +246,7 @@
end

it "should return a regexp of itself" do
@range.to_regexp.should == /\A.\Z/i
@range.to_regexp.should == /./i
end

it "should be inspectable" do
Expand Down
8 changes: 4 additions & 4 deletions spec/character_spec.rb
Expand Up @@ -17,7 +17,7 @@
end

it "should return a regexp of itself" do
@character.to_regexp.should == /\Aa\Z/
@character.to_regexp.should == /a/
end

it "should be inspectable" do
Expand Down Expand Up @@ -80,7 +80,7 @@
end

it "should return a regexp of itself" do
@character.to_regexp.should == /\Aa?\Z/
@character.to_regexp.should == /a?/
end

it "should be inspectable" do
Expand Down Expand Up @@ -124,7 +124,7 @@
end

it "should return a regexp of itself" do
@character.to_regexp.should == /\Aa{2,3}\Z/
@character.to_regexp.should == /a{2,3}/
end

it "should be inspectable" do
Expand Down Expand Up @@ -157,7 +157,7 @@
end

it "should return a regexp of itself" do
@character.to_regexp.should == /\Aa\Z/i
@character.to_regexp.should == /a/i
end

it "should be inspectable" do
Expand Down
6 changes: 3 additions & 3 deletions spec/expression_spec.rb
Expand Up @@ -18,7 +18,7 @@
end

it "should return a regexp of itself" do
@expression.to_regexp.should == /\Afoo\Z/
@expression.to_regexp.should == /foo/
end

it "should have no flags" do
Expand Down Expand Up @@ -120,7 +120,7 @@
end

it "should return a regexp of itself" do
@expression.to_regexp.should == /\Afoo\Z/i
@expression.to_regexp.should == /foo/i
end

it "should have ignorecase flag" do
Expand Down Expand Up @@ -177,7 +177,7 @@
end

it "should return a regexp of itself" do
@expression.to_regexp.should == /\Afoo\Z/
@expression.to_regexp.should == /foo/
end

it "should have ignorecase flag" do
Expand Down
6 changes: 3 additions & 3 deletions spec/group_spec.rb
Expand Up @@ -31,7 +31,7 @@
end

it "should return a regexp of itself" do
@group.to_regexp.should == /\A(foo)\Z/
@group.to_regexp.should == /(foo)/
end

it "should match 'foo'" do
Expand Down Expand Up @@ -110,7 +110,7 @@
end

it "should return a regexp of itself" do
@group.to_regexp.should == /\A((?i-mx:foo))\Z/
@group.to_regexp.should == /((?i-mx:foo))/
end

it "should match 'foo'" do
Expand Down Expand Up @@ -166,7 +166,7 @@
end

it "should return a regexp of itself" do
@group.to_regexp.should == /\A((?i-mx:foo))?\Z/
@group.to_regexp.should == /((?i-mx:foo))?/
end

it "should match 'foo'" do
Expand Down
2 changes: 1 addition & 1 deletion spec/parsable_spec.rb
Expand Up @@ -4,7 +4,7 @@
match do |actual|
expression = Regin.parse(actual)
expression.should be_a(Regin::Expression)
expected = Regexp.compile("\\A#{actual.source}\\Z", actual.options)
expected = Regexp.compile(actual.source, actual.options)
expression.to_regexp.should eql(expected)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/parser_spec.rb
Expand Up @@ -195,21 +195,21 @@
re = Regin.parse(/abc/i)
re.should be_casefold
re.to_s.should eql('(?i-mx:abc)')
re.to_regexp.should eql(%r{\Aabc\Z}i)
re.to_regexp.should eql(%r{abc}i)
end

it "should parse explict nested ignorecase" do
re = Regin.parse(%r{(?-mix:foo)}i)
re.should be_casefold
re.to_s.should eql('(?i-mx:(?-mix:foo))')
re.to_regexp.should eql(%r{\A(?-mix:foo)\Z}i)
re.to_regexp.should eql(%r{(?-mix:foo)}i)
end

it "should parse implicit nested ignorecase" do
re = Regin.parse(%r{(?:foo)}i)
re.should be_casefold
re.to_s.should eql('(?i-mx:(?i-mx:foo))')
re.to_regexp.should eql(%r{\A(?i-mx:foo)\Z}i)
re.to_regexp.should eql(%r{(?i-mx:foo)}i)
end

it "should parse spaces and pound sign in normal expression" do
Expand Down

0 comments on commit 4a637bc

Please sign in to comment.