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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
84c14a4a
Commit
84c14a4a
authored
Feb 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing specs for pipeline expression lexemes
parent
ba70e50e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
135 additions
and
7 deletions
+135
-7
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
+1
-1
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
+1
-1
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
+1
-1
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
+2
-2
lib/gitlab/ci/pipeline/expression/statement.rb
lib/gitlab/ci/pipeline/expression/statement.rb
+1
-1
spec/lib/gitlab/ci/pipeline/expression/lexeme/equals_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexeme/equals_spec.rb
+39
-0
spec/lib/gitlab/ci/pipeline/expression/lexeme/null_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexeme/null_spec.rb
+22
-0
spec/lib/gitlab/ci/pipeline/expression/lexeme/string_spec.rb
spec/lib/gitlab/ci/pipeline/expression/lexeme/string_spec.rb
+30
-0
spec/lib/gitlab/ci/pipeline/expression/lexeme/variable_spec.rb
...lib/gitlab/ci/pipeline/expression/lexeme/variable_spec.rb
+37
-0
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+1
-1
No files found.
lib/gitlab/ci/pipeline/expression/lexeme/equals.rb
View file @
84c14a4a
...
@@ -11,7 +11,7 @@ module Gitlab
...
@@ -11,7 +11,7 @@ module Gitlab
@right
=
right
@right
=
right
end
end
def
evaluate
(
variables
)
def
evaluate
(
**
variables
)
@left
.
evaluate
(
variables
)
==
@right
.
evaluate
(
variables
)
@left
.
evaluate
(
variables
)
==
@right
.
evaluate
(
variables
)
end
end
...
...
lib/gitlab/ci/pipeline/expression/lexeme/null.rb
View file @
84c14a4a
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
@value
=
value
@value
=
value
end
end
def
evaluate
(
_
)
def
evaluate
(
**
_
)
nil
nil
end
end
...
...
lib/gitlab/ci/pipeline/expression/lexeme/string.rb
View file @
84c14a4a
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
@value
=
value
@value
=
value
end
end
def
evaluate
(
_
)
def
evaluate
(
**
_
)
@value
.
to_s
@value
.
to_s
end
end
...
...
lib/gitlab/ci/pipeline/expression/lexeme/variable.rb
View file @
84c14a4a
...
@@ -10,8 +10,8 @@ module Gitlab
...
@@ -10,8 +10,8 @@ module Gitlab
@name
=
name
@name
=
name
end
end
def
evaluate
(
variables
)
def
evaluate
(
**
variables
)
variables
[
@name
]
variables
[
@name
.
to_sym
]
end
end
def
self
.
build
(
string
)
def
self
.
build
(
string
)
...
...
lib/gitlab/ci/pipeline/expression/statement.rb
View file @
84c14a4a
...
@@ -18,7 +18,7 @@ module Gitlab
...
@@ -18,7 +18,7 @@ module Gitlab
@lexer
=
Expression
::
Lexer
.
new
(
statement
)
@lexer
=
Expression
::
Lexer
.
new
(
statement
)
@variables
=
pipeline
.
variables
.
map
do
|
variable
|
@variables
=
pipeline
.
variables
.
map
do
|
variable
|
[
variable
.
key
,
variable
.
value
]
[
variable
.
key
.
to_sym
,
variable
.
value
]
end
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/expression/lexeme/equals_spec.rb
View file @
84c14a4a
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Equals
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 are not equal'
do
allow
(
left
).
to
receive
(
:evaluate
).
and_return
(
1
)
allow
(
right
).
to
receive
(
:evaluate
).
and_return
(
2
)
operator
=
described_class
.
new
(
left
,
right
)
expect
(
operator
.
evaluate
(
VARIABLE
:
3
)).
to
eq
false
end
it
'returns true when left and right are equal'
do
allow
(
left
).
to
receive
(
:evaluate
).
and_return
(
1
)
allow
(
right
).
to
receive
(
:evaluate
).
and_return
(
1
)
operator
=
described_class
.
new
(
left
,
right
)
expect
(
operator
.
evaluate
(
VARIABLE
:
3
)).
to
eq
true
end
end
end
spec/lib/gitlab/ci/pipeline/expression/lexeme/null_spec.rb
0 → 100644
View file @
84c14a4a
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Null
do
describe
'.build'
do
it
'creates a new instance of the token'
do
expect
(
described_class
.
build
(
'null'
))
.
to
be_a
(
described_class
)
end
end
describe
'.type'
do
it
'is a value lexeme'
do
expect
(
described_class
.
type
).
to
eq
:value
end
end
describe
'#evaluate'
do
it
'always evaluates to `nil`'
do
expect
(
described_class
.
new
(
'null'
).
evaluate
).
to
be_nil
end
end
end
spec/lib/gitlab/ci/pipeline/expression/lexeme/string_spec.rb
0 → 100644
View file @
84c14a4a
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
String
do
describe
'.build'
do
it
'creates a new instance of the token'
do
expect
(
described_class
.
build
(
'"my string"'
))
.
to
be_a
(
described_class
)
end
end
describe
'.type'
do
it
'is a value lexeme'
do
expect
(
described_class
.
type
).
to
eq
:value
end
end
describe
'#evaluate'
do
it
'returns string value it is is present'
do
string
=
described_class
.
new
(
'my string'
)
expect
(
string
.
evaluate
).
to
eq
'my string'
end
it
'returns an empty string if it is empty'
do
string
=
described_class
.
new
(
''
)
expect
(
string
.
evaluate
).
to
eq
''
end
end
end
spec/lib/gitlab/ci/pipeline/expression/lexeme/variable_spec.rb
0 → 100644
View file @
84c14a4a
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Expression
::
Lexeme
::
Variable
do
describe
'.build'
do
it
'creates a new instance of the token'
do
expect
(
described_class
.
build
(
'$VARIABLE'
))
.
to
be_a
(
described_class
)
end
end
describe
'.type'
do
it
'is a value lexeme'
do
expect
(
described_class
.
type
).
to
eq
:value
end
end
describe
'#evaluate'
do
it
'returns variable value if it is defined'
do
variable
=
described_class
.
new
(
'VARIABLE'
)
expect
(
variable
.
evaluate
(
VARIABLE
:
'my variable'
))
.
to
eq
'my variable'
end
it
'returns nil if it is not defined'
do
variable
=
described_class
.
new
(
'VARIABLE'
)
expect
(
variable
.
evaluate
(
OTHER
:
'variable'
)).
to
be_nil
end
it
'returns an empty string if it is empty'
do
variable
=
described_class
.
new
(
'VARIABLE'
)
expect
(
variable
.
evaluate
(
VARIABLE
:
''
)).
to
eq
''
end
end
end
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
View file @
84c14a4a
...
@@ -69,7 +69,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
...
@@ -69,7 +69,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
[
'$VAR == null'
,
true
],
[
'$VAR == null'
,
true
],
[
'null == $VAR'
,
true
],
[
'null == $VAR'
,
true
],
[
'$VARIABLE'
,
'my variable'
],
[
'$VARIABLE'
,
'my variable'
],
[
'$VAR'
,
nil
]
,
[
'$VAR'
,
nil
]
]
]
statements
.
each
do
|
expression
,
value
|
statements
.
each
do
|
expression
,
value
|
...
...
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