Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
1926eca0
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1926eca0
编写于
2月 28, 2018
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add method that checks if pipeline expression is truthy
上级
64e86dab
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
42 addition
and
11 deletion
+42
-11
lib/gitlab/ci/pipeline/expression/statement.rb
lib/gitlab/ci/pipeline/expression/statement.rb
+4
-0
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+38
-11
未找到文件。
lib/gitlab/ci/pipeline/expression/statement.rb
浏览文件 @
1926eca0
...
...
@@ -38,6 +38,10 @@ module Gitlab
parse_tree
.
evaluate
(
@variables
.
to_h
)
end
def
truthful?
evaluate
.
present?
end
def
inspect
"syntax:
#{
@lexer
.
lexemes
.
join
(
' '
)
}
"
end
...
...
spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
浏览文件 @
1926eca0
...
...
@@ -8,13 +8,16 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end
before
do
pipeline
.
variables
.
build
([
key:
'VARIABLE'
,
value:
'my variable'
])
variables
=
[{
key:
'PRESENT_VARIABLE'
,
value:
'my variable'
},
{
key:
'EMPTY_VARIABLE'
,
value:
''
}]
pipeline
.
variables
.
build
(
variables
)
end
describe
'.new'
do
context
'when pipeline is not provided'
do
it
'allows to properly initialize the statement'
do
statement
=
described_class
.
new
(
'$VARIABLE'
)
statement
=
described_class
.
new
(
'$
PRESENT_
VARIABLE'
)
expect
(
statement
.
evaluate
).
to
be_nil
end
...
...
@@ -72,7 +75,7 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end
context
'when using a single token'
do
let
(
:text
)
{
'$VARIABLE'
}
let
(
:text
)
{
'$
PRESENT_
VARIABLE'
}
it
'returns a single token instance'
do
expect
(
subject
.
parse_tree
)
...
...
@@ -84,14 +87,17 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
describe
'#evaluate'
do
statements
=
[
[
'$VARIABLE == "my variable"'
,
true
],
[
"$VARIABLE == 'my variable'"
,
true
],
[
'"my variable" == $VARIABLE'
,
true
],
[
'$VARIABLE == null'
,
false
],
[
'$VAR == null'
,
true
],
[
'null == $VAR'
,
true
],
[
'$VARIABLE'
,
'my variable'
],
[
'$VAR'
,
nil
]
[
'$PRESENT_VARIABLE == "my variable"'
,
true
],
[
"$PRESENT_VARIABLE == 'my variable'"
,
true
],
[
'"my variable" == $PRESENT_VARIABLE'
,
true
],
[
'$PRESENT_VARIABLE == null'
,
false
],
[
'$EMPTY_VARIABLE == null'
,
false
],
[
'"" == $EMPTY_VARIABLE'
,
true
],
[
'$EMPTY_VARIABLE'
,
''
],
[
'$UNDEFINED_VARIABLE == null'
,
true
],
[
'null == $UNDEFINED_VARIABLE'
,
true
],
[
'$PRESENT_VARIABLE'
,
'my variable'
],
[
'$UNDEFINED_VARIABLE'
,
nil
]
]
statements
.
each
do
|
expression
,
value
|
...
...
@@ -104,4 +110,25 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end
end
end
describe
'#truthful?'
do
statements
=
[
[
'$PRESENT_VARIABLE == "my variable"'
,
true
],
[
"$PRESENT_VARIABLE == 'no match'"
,
false
],
[
'$UNDEFINED_VARIABLE == null'
,
true
],
[
'$PRESENT_VARIABLE'
,
true
],
[
'$UNDEFINED_VARIABLE'
,
false
],
[
'$EMPTY_VARIABLE'
,
false
]
]
statements
.
each
do
|
expression
,
value
|
context
"when using expression `
#{
expression
}
`"
do
let
(
:text
)
{
expression
}
it
"returns `
#{
value
.
inspect
}
`"
do
expect
(
subject
.
truthful?
).
to
eq
value
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录