summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/regex_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/regex_spec.rb')
-rw-r--r--spec/lib/gitlab/regex_spec.rb134
1 files changed, 133 insertions, 1 deletions
diff --git a/spec/lib/gitlab/regex_spec.rb b/spec/lib/gitlab/regex_spec.rb
index 9e596400904..2f220272651 100644
--- a/spec/lib/gitlab/regex_spec.rb
+++ b/spec/lib/gitlab/regex_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'spec_helper'
+require 'fast_spec_helper'
describe Gitlab::Regex do
shared_examples_for 'project/group name regex' do
@@ -163,4 +163,136 @@ describe Gitlab::Regex do
it { is_expected.not_to match('-foo-') }
it { is_expected.not_to match('foo/bar') }
end
+
+ describe '.conan_file_name_regex' do
+ subject { described_class.conan_file_name_regex }
+
+ it { is_expected.to match('conanfile.py') }
+ it { is_expected.to match('conan_package.tgz') }
+ it { is_expected.not_to match('foo.txt') }
+ it { is_expected.not_to match('!!()()') }
+ end
+
+ describe '.conan_package_reference_regex' do
+ subject { described_class.conan_package_reference_regex }
+
+ it { is_expected.to match('123456789') }
+ it { is_expected.to match('asdf1234') }
+ it { is_expected.not_to match('@foo') }
+ it { is_expected.not_to match('0/pack+age/1@1/0') }
+ it { is_expected.not_to match('!!()()') }
+ end
+
+ describe '.conan_revision_regex' do
+ subject { described_class.conan_revision_regex }
+
+ it { is_expected.to match('0') }
+ it { is_expected.not_to match('foo') }
+ it { is_expected.not_to match('!!()()') }
+ end
+
+ describe '.conan_recipe_component_regex' do
+ subject { described_class.conan_recipe_component_regex }
+
+ let(:fifty_one_characters) { 'f_a' * 17}
+
+ it { is_expected.to match('foobar') }
+ it { is_expected.to match('foo_bar') }
+ it { is_expected.to match('foo+bar') }
+ it { is_expected.to match('_foo+bar-baz+1.0') }
+ it { is_expected.to match('1.0.0') }
+ it { is_expected.not_to match('-foo_bar') }
+ it { is_expected.not_to match('+foo_bar') }
+ it { is_expected.not_to match('.foo_bar') }
+ it { is_expected.not_to match('foo@bar') }
+ it { is_expected.not_to match('foo/bar') }
+ it { is_expected.not_to match('!!()()') }
+ it { is_expected.not_to match(fifty_one_characters) }
+ end
+
+ describe '.package_name_regex' do
+ subject { described_class.package_name_regex }
+
+ it { is_expected.to match('123') }
+ it { is_expected.to match('foo') }
+ it { is_expected.to match('foo/bar') }
+ it { is_expected.to match('@foo/bar') }
+ it { is_expected.to match('com/mycompany/app/my-app') }
+ it { is_expected.to match('my-package/1.0.0@my+project+path/beta') }
+ it { is_expected.not_to match('my-package/1.0.0@@@@@my+project+path/beta') }
+ it { is_expected.not_to match('$foo/bar') }
+ it { is_expected.not_to match('@foo/@/bar') }
+ it { is_expected.not_to match('@@foo/bar') }
+ it { is_expected.not_to match('my package name') }
+ it { is_expected.not_to match('!!()()') }
+ it { is_expected.not_to match("..\n..\foo") }
+ end
+
+ describe '.maven_file_name_regex' do
+ subject { described_class.maven_file_name_regex }
+
+ it { is_expected.to match('123') }
+ it { is_expected.to match('foo') }
+ it { is_expected.to match('foo+bar-2_0.pom') }
+ it { is_expected.to match('foo.bar.baz-2.0-20190901.47283-1.jar') }
+ it { is_expected.to match('maven-metadata.xml') }
+ it { is_expected.to match('1.0-SNAPSHOT') }
+ it { is_expected.not_to match('../../foo') }
+ it { is_expected.not_to match('..\..\foo') }
+ it { is_expected.not_to match('%2f%2e%2e%2f%2essh%2fauthorized_keys') }
+ it { is_expected.not_to match('$foo/bar') }
+ it { is_expected.not_to match('my file name') }
+ it { is_expected.not_to match('!!()()') }
+ end
+
+ describe '.maven_path_regex' do
+ subject { described_class.maven_path_regex }
+
+ it { is_expected.to match('123') }
+ it { is_expected.to match('foo') }
+ it { is_expected.to match('foo/bar') }
+ it { is_expected.to match('@foo/bar') }
+ it { is_expected.to match('com/mycompany/app/my-app') }
+ it { is_expected.to match('com/mycompany/app/my-app/1.0-SNAPSHOT') }
+ it { is_expected.to match('com/mycompany/app/my-app/1.0-SNAPSHOT+debian64') }
+ it { is_expected.not_to match('com/mycompany/app/my+app/1.0-SNAPSHOT') }
+ it { is_expected.not_to match('$foo/bar') }
+ it { is_expected.not_to match('@foo/@/bar') }
+ it { is_expected.not_to match('my package name') }
+ it { is_expected.not_to match('!!()()') }
+ end
+
+ describe '.semver_regex' do
+ subject { described_class.semver_regex }
+
+ it { is_expected.to match('1.2.3') }
+ it { is_expected.to match('1.2.3-beta') }
+ it { is_expected.to match('1.2.3-alpha.3') }
+ it { is_expected.not_to match('1') }
+ it { is_expected.not_to match('1.2') }
+ it { is_expected.not_to match('1./2.3') }
+ it { is_expected.not_to match('../../../../../1.2.3') }
+ it { is_expected.not_to match('%2e%2e%2f1.2.3') }
+ end
+
+ describe '.go_package_regex' do
+ subject { described_class.go_package_regex }
+
+ it { is_expected.to match('example.com') }
+ it { is_expected.to match('example.com/foo') }
+ it { is_expected.to match('example.com/foo/bar') }
+ it { is_expected.to match('example.com/foo/bar/baz') }
+ it { is_expected.to match('tl.dr.foo.bar.baz') }
+ end
+
+ describe '.unbounded_semver_regex' do
+ subject { described_class.unbounded_semver_regex }
+
+ it { is_expected.to match('1.2.3') }
+ it { is_expected.to match('1.2.3-beta') }
+ it { is_expected.to match('1.2.3-alpha.3') }
+ it { is_expected.not_to match('1') }
+ it { is_expected.not_to match('1.2') }
+ it { is_expected.not_to match('1./2.3') }
+ end
end