debian-mirror-gitlab/spec/lib/gitlab/ci/pipeline/expression/parser_spec.rb

71 lines
2.3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'fast_spec_helper'
2018-03-27 19:54:05 +05:30
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Pipeline::Expression::Parser do
2018-03-27 19:54:05 +05:30
describe '#tree' do
2019-09-04 21:01:54 +05:30
context 'when using two operators' do
it 'returns a reverse descent parse tree' do
expect(described_class.seed('$VAR1 == "123"').tree)
.to be_a Gitlab::Ci::Pipeline::Expression::Lexeme::Equals
end
end
context 'when using three operators' do
2018-03-27 19:54:05 +05:30
it 'returns a reverse descent parse tree' do
expect(described_class.seed('$VAR1 == "123" == $VAR2').tree)
.to be_a Gitlab::Ci::Pipeline::Expression::Lexeme::Equals
end
end
2019-09-04 21:01:54 +05:30
context 'when using a single variable token' do
2018-03-27 19:54:05 +05:30
it 'returns a single token instance' do
expect(described_class.seed('$VAR').tree)
.to be_a Gitlab::Ci::Pipeline::Expression::Lexeme::Variable
end
end
2019-09-04 21:01:54 +05:30
context 'when using a single string token' do
it 'returns a single token instance' do
expect(described_class.seed('"some value"').tree)
.to be_a Gitlab::Ci::Pipeline::Expression::Lexeme::String
end
end
2018-03-27 19:54:05 +05:30
context 'when expression is empty' do
it 'returns a null token' do
2019-09-04 21:01:54 +05:30
expect { described_class.seed('').tree }
.to raise_error Gitlab::Ci::Pipeline::Expression::Parser::ParseError
end
end
context 'when expression is null' do
it 'returns a null token' do
expect(described_class.seed('null').tree)
2018-03-27 19:54:05 +05:30
.to be_a Gitlab::Ci::Pipeline::Expression::Lexeme::Null
end
end
2019-09-04 21:01:54 +05:30
context 'when two value tokens have no operator' do
it 'raises a parsing error' do
expect { described_class.seed('$VAR "text"').tree }
.to raise_error Gitlab::Ci::Pipeline::Expression::Parser::ParseError
end
end
context 'when an operator has no left side' do
it 'raises an OperatorError' do
expect { described_class.seed('== "123"').tree }
.to raise_error Gitlab::Ci::Pipeline::Expression::Lexeme::Operator::OperatorError
end
end
context 'when an operator has no right side' do
it 'raises an OperatorError' do
expect { described_class.seed('$VAR ==').tree }
.to raise_error Gitlab::Ci::Pipeline::Expression::Lexeme::Operator::OperatorError
end
end
2018-03-27 19:54:05 +05:30
end
end