Sha256: b014f93358543db46f1a2b685fb21a0ce0d48a701552bbc67aa501a4f3d15152
Contents?: true
Size: 1.66 KB
Versions: 3
Compression:
Stored size: 1.66 KB
Contents
RSpec.describe Operations::Xor do subject(:operation) { Operations::Xor.new(left, right) } include_context 'predicates' let(:left) { Rule::Predicate.build(array?) } let(:right) { Rule::Predicate.build(empty?) } let(:other) do Rule::Predicate.build(str?) end describe '#call' do it 'calls left and right' do expect(operation.(nil)).to be_success expect(operation.('')).to be_success expect(operation.([])).to be_failure end end describe '#to_ast' do it 'returns ast' do expect(operation.to_ast).to eql( [:xor, [[:predicate, [:array?, [[:input, Undefined]]]], [:predicate, [:empty?, [[:input, Undefined]]]]]] ) end it 'returns result ast' do expect(operation.([]).to_ast).to eql( [:xor, [[:predicate, [:array?, [[:input, []]]]], [:predicate, [:empty?, [[:input, []]]]]]] ) end it 'returns failure result ast' do expect(operation.with(id: :name).([]).to_ast).to eql( [:failure, [:name, [:xor, [[:predicate, [:array?, [[:input, []]]]], [:predicate, [:empty?, [[:input, []]]]]]]]] ) end end describe '#and' do it 'creates conjunction with the other' do expect(operation.and(other).(nil)).to be_failure expect(operation.and(other).(19)).to be_failure expect(operation.and(other).('')).to be_success end end describe '#or' do it 'creates disjunction with the other' do expect(operation.or(other).([])).to be_failure expect(operation.or(other).('')).to be_success end end describe '#to_s' do it 'returns string representation' do expect(operation.to_s).to eql('array? XOR empty?') end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dry-logic-1.0.0 | spec/unit/operations/xor_spec.rb |
dry-logic-0.6.1 | spec/unit/operations/xor_spec.rb |
dry-logic-0.6.0 | spec/unit/operations/xor_spec.rb |