Commit b92ce0cc authored by Grzegorz Bizon's avatar Grzegorz Bizon

Rename pipeline expressions statement exception class

parent d532a9cb
...@@ -20,7 +20,7 @@ module Gitlab ...@@ -20,7 +20,7 @@ module Gitlab
def tokenize def tokenize
MAX_CYCLES.times do MAX_CYCLES.times do
LEXEMES.each do |lexeme| LEXEMES.each do |lexeme|
@scanner.scan(/\s+/) # ignore whitespace @scanner.skip(/\s+/) # ignore whitespace
lexeme.scan(@scanner).tap do |token| lexeme.scan(@scanner).tap do |token|
@tokens.push(token) if token.present? @tokens.push(token) if token.present?
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
module Pipeline module Pipeline
module Expression module Expression
class Statement class Statement
ParserError = Class.new(StandardError) StatementError = Class.new(StandardError)
GRAMMAR = [ GRAMMAR = [
%w[variable equals string], %w[variable equals string],
...@@ -37,10 +37,10 @@ module Gitlab ...@@ -37,10 +37,10 @@ module Gitlab
# a reverse descent parse tree "by hand". # a reverse descent parse tree "by hand".
# #
def parse_tree def parse_tree
raise ParserError if lexemes.empty? raise StatementError if lexemes.empty?
unless GRAMMAR.find { |syntax| syntax == lexemes } unless GRAMMAR.find { |syntax| syntax == lexemes }
raise ParserError, 'Unknown pipeline expression!' raise StatementError, 'Unknown pipeline expression!'
end end
if tokens.many? if tokens.many?
......
...@@ -25,10 +25,21 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do ...@@ -25,10 +25,21 @@ describe Gitlab::Ci::Pipeline::Expression::Statement do
end end
describe '#parse_tree' do describe '#parse_tree' do
context 'when expression is empty' do
let(:text) { '' }
it 'raises an error' do
expect { subject.parse_tree }
.to raise_error described_class::StatementError
end
end
context 'when expression grammar is incorrect' do context 'when expression grammar is incorrect' do
let(:text) { '$VAR "text"' }
it 'raises an error' do it 'raises an error' do
expect { subject.parse_tree } expect { subject.parse_tree }
.to raise_error described_class::ParserError .to raise_error described_class::StatementError
end end
end end
......
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