Commit 8c7374ca authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add operator / value types in pipeline expressions

parent 85176274
......@@ -3,9 +3,8 @@ module Gitlab
module Pipeline
module Expression
module Lexeme
class Equals < Lexeme::Base
class Equals < Lexeme::Operator
PATTERN = /==/.freeze
TYPE = :operator
def initialize(left, right)
@left = left
......
......@@ -3,9 +3,8 @@ module Gitlab
module Pipeline
module Expression
module Lexeme
class Null < Lexeme::Base
class Null < Lexeme::Value
PATTERN = /null/.freeze
TYPE = :value
def initialize(value = nil)
@value = value
......
module Gitlab
module Ci
module Pipeline
module Expression
module Lexeme
class Operator < Lexeme::Base
def self.type
:operator
end
end
end
end
end
end
end
......@@ -3,9 +3,8 @@ module Gitlab
module Pipeline
module Expression
module Lexeme
class String < Lexeme::Base
class String < Lexeme::Value
PATTERN = /"(?<string>.+?)"/.freeze
TYPE = :value
def initialize(value)
@value = value
......
module Gitlab
module Ci
module Pipeline
module Expression
module Lexeme
class Value < Lexeme::Base
def self.type
:value
end
end
end
end
end
end
end
......@@ -3,9 +3,8 @@ module Gitlab
module Pipeline
module Expression
module Lexeme
class Variable < Lexeme::Base
class Variable < Lexeme::Value
PATTERN = /\$(?<name>\w+)/.freeze
TYPE = :value
def initialize(name)
@name = name
......
......@@ -10,7 +10,7 @@ module Gitlab
].freeze
MAX_CYCLES = 5
SyntaxError = Class.new(StandardError)
SyntaxError = Class.new(Statement::StatementError)
def initialize(statement)
@scanner = StringScanner.new(statement)
......
......@@ -22,7 +22,7 @@ module Gitlab
end
end
rescue StopIteration
@nodes.last || Expression::Lexeme::Null.new
@nodes.last || Lexeme::Null.new
end
def self.seed(statement)
......
......@@ -23,13 +23,22 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end
context 'when expression grammar is incorrect' do
let(:text) { '$VAR "text"' }
it 'raises an error' do
expect { subject.parse_tree }
table = [
'$VAR "text"', # missing operator
'== "123"', # invalid right side
"'single quotes'", # single quotes string
'$VAR ==', # invalid right side
'12345', # unknown syntax
'' # empty statement
]
table.each do |syntax|
it "raises an error when syntax is `#{syntax}`" do
expect { described_class.new(syntax, pipeline).parse_tree }
.to raise_error described_class::StatementError
end
end
end
context 'when expression grammar is correct' do
context 'when using an operator' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment