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 Identifier#match? #1305

Merged
merged 1 commit into from Jan 26, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+39 −0
Diff settings

Always

Just for now

Add Identifier#match?

  • Loading branch information...
ddfreyne committed Jan 26, 2018
commit 21d5773ebdfd05768a8e17e78869becd9aa90717
@@ -101,6 +101,11 @@ def =~(other)
Nanoc::Int::Pattern.from(other).match?(to_s) ? 0 : nil
end

contract C::Any => C::Bool
def match?(other)
Nanoc::Int::Pattern.from(other).match?(to_s)
end

contract C::Any => C::Num
def <=>(other)
to_s <=> other.to_s
@@ -249,6 +249,40 @@
end
end

describe '#match?' do
let(:identifier) { described_class.new('/foo/bar') }

subject { identifier.match?(pat) }

context 'given a regex' do
context 'matching regex' do
let(:pat) { %r{\A/foo/bar} }
it { is_expected.to be(true) }
example { expect { subject }.not_to change { Regexp.last_match } }
end

context 'non-matching regex' do
let(:pat) { %r{\A/qux/monkey} }
it { is_expected.to be(false) }
example { expect { subject }.not_to change { Regexp.last_match } }
end
end

context 'given a string' do
context 'matching string' do
let(:pat) { '/foo/*' }
it { is_expected.to be(true) }
example { expect { subject }.not_to change { Regexp.last_match } }
end

context 'non-matching string' do
let(:pat) { '/qux/*' }
it { is_expected.to be(false) }
example { expect { subject }.not_to change { Regexp.last_match } }
end
end
end

describe '#<=>' do
let(:identifier) { described_class.new('/foo/bar') }

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.