Skip to content

Commit 5ac0a70

Browse files
committed
Added Text::Patterns::VERSION_CONSTRAINT (closes #555).
1 parent 5ff479e commit 5ac0a70

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

lib/ronin/support/text/patterns/software.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ module Patterns
3131
#
3232
# @since 1.0.0
3333
VERSION_NUMBER = /\d+(?:\.\d+){1,3}(?:[-.]?[A-Za-z]+(?:[-.]?\d+)?)?/
34+
35+
# Regular expression for finding version constraints in text.
36+
#
37+
# @since 1.2.0
38+
VERSION_CONSTRAINT = /(?:>=|>|<=|<|=)\s*#{VERSION_NUMBER}/
3439
end
3540
end
3641
end

spec/text/patterns/software_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,4 +864,48 @@
864864
expect(version).to fully_match(subject)
865865
end
866866
end
867+
868+
describe "VERSION_CONSTRAINT" do
869+
subject { described_class::VERSION_CONSTRAINT }
870+
871+
it "must match '>= X.Y.Z'" do
872+
expect('>= 1.2.3').to fully_match(subject)
873+
end
874+
875+
it "must match '> X.Y.Z'" do
876+
expect('> 1.2.3').to fully_match(subject)
877+
end
878+
879+
it "must match '<= X.Y.Z'" do
880+
expect('<= 1.2.3').to fully_match(subject)
881+
end
882+
883+
it "must match '< X.Y.Z'" do
884+
expect('< 1.2.3').to fully_match(subject)
885+
end
886+
887+
it "must match '= X.Y.Z'" do
888+
expect('= 1.2.3').to fully_match(subject)
889+
end
890+
891+
it "must match '>=X.Y.Z'" do
892+
expect('>=1.2.3').to fully_match(subject)
893+
end
894+
895+
it "must match '>X.Y.Z'" do
896+
expect('>1.2.3').to fully_match(subject)
897+
end
898+
899+
it "must match '<=X.Y.Z'" do
900+
expect('<=1.2.3').to fully_match(subject)
901+
end
902+
903+
it "must match '<X.Y.Z'" do
904+
expect('<1.2.3').to fully_match(subject)
905+
end
906+
907+
it "must match '=X.Y.Z'" do
908+
expect('=1.2.3').to fully_match(subject)
909+
end
910+
end
867911
end

0 commit comments

Comments
 (0)