Commit b92ce0cc authored by Grzegorz Bizon's avatar Grzegorz Bizon

Rename pipeline expressions statement exception class

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