Skip to content

Commit

Permalink
Add test coverage for more edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mudge committed Sep 24, 2023
1 parent 09b9b90 commit 6ba13eb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
16 changes: 16 additions & 0 deletions spec/kernel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@

expect(re).not_to be_case_sensitive
end

it "raises an error if given an inappropriate type" do
expect { RE2(nil) }.to raise_error(TypeError)
end

it "allows invalid patterns to be created" do
re = RE2('???', :log_errors => false)

expect(re).to be_a(RE2::Regexp)
end

it "supports passing something that can be coerced to a String as input" do
re = RE2(StringLike.new('w(o)(o)'))

expect(re).to be_a(RE2::Regexp)
end
end
end
22 changes: 19 additions & 3 deletions spec/re2/regexp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
re = RE2::Regexp.new('???', :log_errors => false)
expect(re).to be_a(RE2::Regexp)
end

it "supports passing something that can be coerced to a String as input" do
re = RE2::Regexp.new(StringLike.new('w(o)(o)'))

expect(re).to be_a(RE2::Regexp)
end
end

describe "#compile" do
describe ".compile" do
it "returns an instance given only a pattern" do
re = RE2::Regexp.compile('woo')
expect(re).to be_a(RE2::Regexp)
Expand All @@ -31,10 +37,20 @@
expect(re).to be_a(RE2::Regexp)
end

it "raises an error if given an inappropriate type" do
expect { RE2::Regexp.compile(nil) }.to raise_error(TypeError)
end

it "allows invalid patterns to be created" do
re = RE2::Regexp.compile('???', :log_errors => false)
expect(re).to be_a(RE2::Regexp)
end

it "supports passing something that can be coerced to a String as input" do
re = RE2::Regexp.compile(StringLike.new('w(o)(o)'))

expect(re).to be_a(RE2::Regexp)
end
end

describe "#options" do
Expand All @@ -59,7 +75,7 @@

it "is populated with overridden options when specified" do
options = RE2::Regexp.new('woo', :case_sensitive => false).options
expect(options[:case_sensitive]).to eq(false)
expect(options).to include(:case_sensitive => false)
end
end

Expand All @@ -82,7 +98,7 @@
expect(error_arg).to be_nil
end

it "returns the offending portin of the regexp if there is an error" do
it "returns the offending portion of the regexp if there is an error" do
error_arg = RE2::Regexp.new('wo(o', :log_errors => false).error_arg
expect(error_arg).to eq("wo(o")
end
Expand Down
10 changes: 6 additions & 4 deletions spec/re2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
expect(RE2.Replace("Good morning", "(?i)gOOD MORNING", "hi")).to eq("hi")
end

it "does not perform replacements in-place" do
it "does not perform replacements in-place", :aggregate_failures do
name = "Robert"
replacement = RE2.Replace(name, "R", "Cr")

expect(name).not_to equal(replacement)
expect(name).to eq("Robert")
expect(replacement).to eq("Crobert")
end

it "supports passing an RE2::Regexp as the pattern" do
Expand Down Expand Up @@ -89,11 +90,12 @@
expect(RE2.GlobalReplace("Robert", "(?i)r", "w")).to eq("wobewt")
end

it "does not perform replacement in-place" do
it "does not perform replacement in-place", :aggregate_failures do
name = "Robert"
replacement = RE2.GlobalReplace(name, "(?i)R", "w")

expect(name).not_to equal(replacement)
expect(name).to eq("Robert")
expect(replacement).to eq("wobewt")
end

it "supports passing an RE2::Regexp as the pattern" do
Expand Down

0 comments on commit 6ba13eb

Please sign in to comment.