Skip to content

Commit 8b231ef

Browse files
committed
Added Text::Patterns::VERSION_CONSTRAINT (closes #555).
1 parent 1ddf3bd commit 8b231ef

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+(?:(?!\.(?:tar|tgz|tbz|zip|rar|txt|htm|xml))[._-][A-Za-z0-9]+)*/
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
@@ -931,4 +931,48 @@
931931
end
932932
end
933933
end
934+
935+
describe "VERSION_CONSTRAINT" do
936+
subject { described_class::VERSION_CONSTRAINT }
937+
938+
it "must match '>= X.Y.Z'" do
939+
expect('>= 1.2.3').to fully_match(subject)
940+
end
941+
942+
it "must match '> X.Y.Z'" do
943+
expect('> 1.2.3').to fully_match(subject)
944+
end
945+
946+
it "must match '<= X.Y.Z'" do
947+
expect('<= 1.2.3').to fully_match(subject)
948+
end
949+
950+
it "must match '< X.Y.Z'" do
951+
expect('< 1.2.3').to fully_match(subject)
952+
end
953+
954+
it "must match '= X.Y.Z'" do
955+
expect('= 1.2.3').to fully_match(subject)
956+
end
957+
958+
it "must match '>=X.Y.Z'" do
959+
expect('>=1.2.3').to fully_match(subject)
960+
end
961+
962+
it "must match '>X.Y.Z'" do
963+
expect('>1.2.3').to fully_match(subject)
964+
end
965+
966+
it "must match '<=X.Y.Z'" do
967+
expect('<=1.2.3').to fully_match(subject)
968+
end
969+
970+
it "must match '<X.Y.Z'" do
971+
expect('<1.2.3').to fully_match(subject)
972+
end
973+
974+
it "must match '=X.Y.Z'" do
975+
expect('=1.2.3').to fully_match(subject)
976+
end
977+
end
934978
end

0 commit comments

Comments
 (0)