Sha256: 42c47837075e7ef0773ee6cfbf5203b12fc7f15ad745f80860c23ed5737519ef
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
RSpec.describe Operations::Or do subject(:operation) { Operations::Or.new(left, right) } include_context 'predicates' let(:left) { Rule::Predicate.new(nil?) } let(:right) { Rule::Predicate.new(gt?).curry(18) } let(:other) do Rule::Predicate.new(int?) & Rule::Predicate.new(lt?).curry(14) end describe '#call' do it 'calls left and right' do expect(operation.(nil)).to be_success expect(operation.(19)).to be_success expect(operation.(18)).to be_failure end end describe '#to_ast' do it 'returns ast' do expect(operation.to_ast).to eql( [:or, [ [:predicate, [:nil?, [[:input, Undefined]]]], [:predicate, [:gt?, [[:num, 18], [:input, Undefined]]]]] ] ) end it 'returns result ast' do expect(operation.(17).to_ast).to eql( [:or, [ [:predicate, [:nil?, [[:input, 17]]]], [:predicate, [:gt?, [[:num, 18], [:input, 17]]]]] ] ) end it 'returns failure result ast' do expect(operation.with(id: :age).(17).to_ast).to eql( [:failure, [:age, [:or, [ [:predicate, [:nil?, [[:input, 17]]]], [:predicate, [:gt?, [[:num, 18], [:input, 17]]]]] ]]] ) end end describe '#and' do it 'creates and with the other' do expect(operation.and(other).(nil)).to be_failure expect(operation.and(other).(19)).to be_failure expect(operation.and(other).(13)).to be_failure expect(operation.and(other).(14)).to be_failure end end describe '#or' do it 'creates or with the other' do expect(operation.or(other).(nil)).to be_success expect(operation.or(other).(19)).to be_success expect(operation.or(other).(13)).to be_success expect(operation.or(other).(14)).to be_failure end end describe '#to_s' do it 'returns string representation' do expect(operation.to_s).to eql('nil? OR gt?(18)') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dry-logic-0.5.0 | spec/unit/operations/or_spec.rb |