Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs for Regexp#linear_time? #1020

Merged
merged 1 commit into from
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/regexp/linear_time_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require_relative '../../spec_helper'

ruby_version_is "3.2" do
describe "Regexp.linear_time?" do
it "returns true if matching can be done in linear time" do
Regexp.linear_time?(/a/).should == true
Regexp.linear_time?('a').should == true
end

it "return false if matching can't be done in linear time" do
Regexp.linear_time?(/(a)\1/).should == false
Regexp.linear_time?("(a)\\1").should == false
end

it "accepts flags for string argument" do
Regexp.linear_time?('a', Regexp::IGNORECASE).should == true
end

it "warns about flags being ignored for regexp arguments" do
-> {
Regexp.linear_time?(/a/, Regexp::IGNORECASE)
}.should complain(/warning: flags ignored/)
end
end
end