Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
f16f2b59
Commit
f16f2b59
authored
May 14, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add pattern matching variables expression lexeme
parent
ac65257c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
+29
-0
spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
.../lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
+57
-0
No files found.
lib/gitlab/ci/pipeline/expression/lexeme/matches.rb
0 → 100644
View file @
f16f2b59
module
Gitlab
module
Ci
module
Pipeline
module
Expression
module
Lexeme
class
Matches
<
Lexeme
::
Operator
PATTERN
=
/=~/
.
freeze
def
initialize
(
left
,
right
)
@left
=
left
@right
=
right
end
def
evaluate
(
variables
=
{})
text
=
@left
.
evaluate
(
variables
)
regexp
=
@right
.
evaluate
(
variables
)
regexp
.
scan
(
text
).
any?
end
def
self
.
build
(
_value
,
behind
,
ahead
)
new
(
behind
,
ahead
)
end
end
end
end
end
end
end
spec/lib/gitlab/ci/pipeline/expression/lexeme/matches_spec.rb
0 → 100644
View file @
f16f2b59
require
'fast_spec_helper'
require_dependency
're2'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Matches
do
let
(
:left
)
{
double
(
'left'
)
}
let
(
:right
)
{
double
(
'right'
)
}
describe
'.build'
do
it
'creates a new instance of the token'
do
expect
(
described_class
.
build
(
'=~'
,
left
,
right
))
.
to
be_a
(
described_class
)
end
end
describe
'.type'
do
it
'is an operator'
do
expect
(
described_class
.
type
).
to
eq
:operator
end
end
describe
'#evaluate'
do
it
'returns false when left and right do not match'
do
allow
(
left
).
to
receive
(
:evaluate
).
and_return
(
'my-string'
)
allow
(
right
).
to
receive
(
:evaluate
)
.
and_return
(
Gitlab
::
UntrustedRegexp
.
new
(
'something'
))
operator
=
described_class
.
new
(
left
,
right
)
expect
(
operator
.
evaluate
).
to
eq
false
end
it
'returns true when left and right match'
do
allow
(
left
).
to
receive
(
:evaluate
).
and_return
(
'my-awesome-string'
)
allow
(
right
).
to
receive
(
:evaluate
)
.
and_return
(
Gitlab
::
UntrustedRegexp
.
new
(
'awesome.string$'
))
operator
=
described_class
.
new
(
left
,
right
)
expect
(
operator
.
evaluate
).
to
eq
true
end
it
'supports multiline strings'
do
allow
(
left
).
to
receive
(
:evaluate
).
and_return
<<~
TEXT
My awesome contents
My-text-string!
TEXT
allow
(
right
).
to
receive
(
:evaluate
)
.
and_return
(
Gitlab
::
UntrustedRegexp
.
new
(
'text-string'
))
operator
=
described_class
.
new
(
left
,
right
)
expect
(
operator
.
evaluate
).
to
eq
true
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment