diff options
author | drew cimino <dcimino@gitlab.com> | 2019-06-14 16:25:02 -0400 |
---|---|---|
committer | drew cimino <dcimino@gitlab.com> | 2019-06-14 17:58:42 -0400 |
commit | 396348dd175d70f9cb547f1e037a9b303e1a93aa (patch) | |
tree | 047f658d7224cc32c897df1469d06c2f3f40b8a8 /spec/lib/gitlab/ci/pipeline | |
parent | ad722a4e1f588382f5c5c1848c0502864993c7e7 (diff) | |
download | gitlab-ce-396348dd175d70f9cb547f1e037a9b303e1a93aa.tar.gz |
Return boolean from Lexeme::Matches#evaluateboolean-values-from-matches-operator
Diffstat (limited to 'spec/lib/gitlab/ci/pipeline')
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb | 57 |
2 files changed, 28 insertions, 43 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb index 97da66d2bcc..a6fdec832a3 100644 --- a/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb @@ -50,21 +50,21 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do let(:left_value) { 'my-string' } let(:right_value) { Gitlab::UntrustedRegexp.new('something') } - it { is_expected.to eq(nil) } + it { is_expected.to eq(false) } end context 'when left and right match' do let(:left_value) { 'my-awesome-string' } let(:right_value) { Gitlab::UntrustedRegexp.new('awesome.string$') } - it { is_expected.to eq(3) } + it { is_expected.to eq(true) } end context 'when left is nil' do let(:left_value) { nil } let(:right_value) { Gitlab::UntrustedRegexp.new('pattern') } - it { is_expected.to eq(nil) } + it { is_expected.to eq(false) } end context 'when left is a multiline string and matches right' do @@ -78,7 +78,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do let(:right_value) { Gitlab::UntrustedRegexp.new('text-string') } - it { is_expected.to eq(24) } + it { is_expected.to eq(true) } end context 'when left is a multiline string and does not match right' do @@ -92,7 +92,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do let(:right_value) { Gitlab::UntrustedRegexp.new('text-string') } - it { is_expected.to eq(nil) } + it { is_expected.to eq(false) } end context 'when a matching pattern uses regex flags' do @@ -104,7 +104,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do let(:right_value) { Gitlab::UntrustedRegexp.new('(?i)awesome') } - it { is_expected.to eq(3) } + it { is_expected.to eq(true) } end context 'when a non-matching pattern uses regex flags' do @@ -116,7 +116,7 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Matches do let(:right_value) { Gitlab::UntrustedRegexp.new('(?i)terrible') } - it { is_expected.to eq(nil) } + it { is_expected.to eq(false) } end end end diff --git a/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb index 057e2f3fbe8..a2c2e3653d5 100644 --- a/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb @@ -41,17 +41,17 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do 'null == $UNDEFINED_VARIABLE' | true '$PRESENT_VARIABLE' | 'my variable' '$UNDEFINED_VARIABLE' | nil - "$PRESENT_VARIABLE =~ /var.*e$/" | 3 - '$PRESENT_VARIABLE =~ /va\r.*e$/' | nil - '$PRESENT_VARIABLE =~ /va\/r.*e$/' | nil - "$PRESENT_VARIABLE =~ /var.*e$/" | 3 - "$PRESENT_VARIABLE =~ /^var.*/" | nil - "$EMPTY_VARIABLE =~ /var.*/" | nil - "$UNDEFINED_VARIABLE =~ /var.*/" | nil - "$PRESENT_VARIABLE =~ /VAR.*/i" | 3 - '$PATH_VARIABLE =~ /path\/variable/' | 2 - '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/' | 0 - '$FULL_PATH_VARIABLE =~ /\\/path\\/variable\\/value$/' | 7 + "$PRESENT_VARIABLE =~ /var.*e$/" | true + '$PRESENT_VARIABLE =~ /va\r.*e$/' | false + '$PRESENT_VARIABLE =~ /va\/r.*e$/' | false + "$PRESENT_VARIABLE =~ /var.*e$/" | true + "$PRESENT_VARIABLE =~ /^var.*/" | false + "$EMPTY_VARIABLE =~ /var.*/" | false + "$UNDEFINED_VARIABLE =~ /var.*/" | false + "$PRESENT_VARIABLE =~ /VAR.*/i" | true + '$PATH_VARIABLE =~ /path\/variable/' | true + '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/' | true + '$FULL_PATH_VARIABLE =~ /\\/path\\/variable\\/value$/' | true '$PRESENT_VARIABLE != "my variable"' | false '"my variable" != $PRESENT_VARIABLE' | false '$PRESENT_VARIABLE != null' | true @@ -82,7 +82,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do '"string" && "string"' | 'string' 'null && null' | nil - '$PRESENT_VARIABLE =~ /my var/ && $EMPTY_VARIABLE =~ /nope/' | nil + '$PRESENT_VARIABLE =~ /my var/ && $EMPTY_VARIABLE =~ /nope/' | false '$EMPTY_VARIABLE == "" && $PRESENT_VARIABLE' | 'my variable' '$EMPTY_VARIABLE == "" && $PRESENT_VARIABLE != "nope"' | true '$PRESENT_VARIABLE && $EMPTY_VARIABLE' | '' @@ -90,17 +90,17 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do '$UNDEFINED_VARIABLE && $EMPTY_VARIABLE' | nil '$UNDEFINED_VARIABLE && $PRESENT_VARIABLE' | nil - '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/ && $PATH_VARIABLE =~ /path\/variable/' | 2 - '$FULL_PATH_VARIABLE =~ /^\/a\/bad\/path\/variable\/value$/ && $PATH_VARIABLE =~ /path\/variable/' | nil - '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/ && $PATH_VARIABLE =~ /bad\/path\/variable/' | nil - '$FULL_PATH_VARIABLE =~ /^\/a\/bad\/path\/variable\/value$/ && $PATH_VARIABLE =~ /bad\/path\/variable/' | nil + '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/ && $PATH_VARIABLE =~ /path\/variable/' | true + '$FULL_PATH_VARIABLE =~ /^\/a\/bad\/path\/variable\/value$/ && $PATH_VARIABLE =~ /path\/variable/' | false + '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/ && $PATH_VARIABLE =~ /bad\/path\/variable/' | false + '$FULL_PATH_VARIABLE =~ /^\/a\/bad\/path\/variable\/value$/ && $PATH_VARIABLE =~ /bad\/path\/variable/' | false - '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/ || $PATH_VARIABLE =~ /path\/variable/' | 0 - '$FULL_PATH_VARIABLE =~ /^\/a\/bad\/path\/variable\/value$/ || $PATH_VARIABLE =~ /path\/variable/' | 2 - '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/ || $PATH_VARIABLE =~ /bad\/path\/variable/' | 0 - '$FULL_PATH_VARIABLE =~ /^\/a\/bad\/path\/variable\/value$/ || $PATH_VARIABLE =~ /bad\/path\/variable/' | nil + '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/ || $PATH_VARIABLE =~ /path\/variable/' | true + '$FULL_PATH_VARIABLE =~ /^\/a\/bad\/path\/variable\/value$/ || $PATH_VARIABLE =~ /path\/variable/' | true + '$FULL_PATH_VARIABLE =~ /^\/a\/full\/path\/variable\/value$/ || $PATH_VARIABLE =~ /bad\/path\/variable/' | true + '$FULL_PATH_VARIABLE =~ /^\/a\/bad\/path\/variable\/value$/ || $PATH_VARIABLE =~ /bad\/path\/variable/' | false - '$PRESENT_VARIABLE =~ /my var/ || $EMPTY_VARIABLE =~ /nope/' | 0 + '$PRESENT_VARIABLE =~ /my var/ || $EMPTY_VARIABLE =~ /nope/' | true '$EMPTY_VARIABLE == "" || $PRESENT_VARIABLE' | true '$PRESENT_VARIABLE != "nope" || $EMPTY_VARIABLE == ""' | true @@ -117,21 +117,6 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do it "evaluates to `#{params[:value].inspect}`" do expect(subject.evaluate).to eq(value) end - - # This test is used to ensure that our parser - # returns exactly the same results as if we - # were evaluating using ruby's `eval` - context 'when using Ruby eval' do - let(:expression_ruby) do - expression - .gsub(/null/, 'nil') - .gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)/) { "variables['#{Regexp.last_match(1)}']" } - end - - it 'behaves exactly the same' do - expect(instance_eval(expression_ruby)).to eq(subject.evaluate) - end - end end context 'with the ci_variables_complex_expressions feature flag disabled' do |