Skip to content

Commit

Permalink
Added Text::Patterns::VERSION_CONSTRAINT (closes #555).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Dec 12, 2024
1 parent 5ff479e commit 5ac0a70
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ronin/support/text/patterns/software.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ module Patterns
#
# @since 1.0.0
VERSION_NUMBER = /\d+(?:\.\d+){1,3}(?:[-.]?[A-Za-z]+(?:[-.]?\d+)?)?/

# Regular expression for finding version constraints in text.
#
# @since 1.2.0
VERSION_CONSTRAINT = /(?:>=|>|<=|<|=)\s*#{VERSION_NUMBER}/
end
end
end
Expand Down
44 changes: 44 additions & 0 deletions spec/text/patterns/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -864,4 +864,48 @@
expect(version).to fully_match(subject)
end
end

describe "VERSION_CONSTRAINT" do
subject { described_class::VERSION_CONSTRAINT }

it "must match '>= X.Y.Z'" do
expect('>= 1.2.3').to fully_match(subject)
end

it "must match '> X.Y.Z'" do
expect('> 1.2.3').to fully_match(subject)
end

it "must match '<= X.Y.Z'" do
expect('<= 1.2.3').to fully_match(subject)
end

it "must match '< X.Y.Z'" do
expect('< 1.2.3').to fully_match(subject)
end

it "must match '= X.Y.Z'" do
expect('= 1.2.3').to fully_match(subject)
end

it "must match '>=X.Y.Z'" do
expect('>=1.2.3').to fully_match(subject)
end

it "must match '>X.Y.Z'" do
expect('>1.2.3').to fully_match(subject)
end

it "must match '<=X.Y.Z'" do
expect('<=1.2.3').to fully_match(subject)
end

it "must match '<X.Y.Z'" do
expect('<1.2.3').to fully_match(subject)
end

it "must match '=X.Y.Z'" do
expect('=1.2.3').to fully_match(subject)
end
end
end

0 comments on commit 5ac0a70

Please sign in to comment.