Sha256: c421224c203262d85eb29ea0e34534c2b48ca82db19772923fcee56ffb3d057f

Contents?: true

Size: 1.66 KB

Versions: 4

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.new(array?) }
  let(:right) { Rule::Predicate.new(empty?) }

  let(:other) do
    Rule::Predicate.new(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

4 entries across 4 versions & 1 rubygems

Version Path
dry-logic-0.5.0 spec/unit/operations/xor_spec.rb
dry-logic-0.4.2 spec/unit/operations/xor_spec.rb
dry-logic-0.4.1 spec/unit/operations/xor_spec.rb
dry-logic-0.4.0 spec/unit/operations/xor_spec.rb