Sha256: 78e9f1f79d912d3161f47b455230900402abb819e06e3505f3a37bb9b0b95e1b

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require_relative '../../../lib/csv_decision2'

describe CSVDecision2::Matchers::Numeric do
  subject { described_class.new }

  describe '#new' do
    it { is_expected.to be_a CSVDecision2::Matchers::Numeric }
    it { is_expected.to respond_to(:matches?).with(1).argument }
  end

  describe '#matches?' do
    matcher = described_class.new

    context 'comparison matches value' do
      data = [
          ['< 1',  0],
          ['< 1', '0'],
          ['> 1',  5],
          ['!= 1',  0],
          ['> 1', '5'],
          ['>= 1.1', BigDecimal('1.1')],
          ['<=-1.1', BigDecimal('-12')]
      ]

      data.each do |cell, value|
        it "comparision #{cell} matches #{value}" do
          proc = matcher.matches?(cell)
          expect(proc).to be_a(CSVDecision2::Matchers::Proc)
          expect(proc.type).to eq :proc
          expect(proc.function[value]).to eq true
        end
      end
    end

    context 'does not match non-numeric comparision' do
      data = ['1', ':column', ':= nil', ':= true', ':= 0', 'abc', 'abc.*def', '-1..1', '0...3']

      data.each do |cell|
        it "cell #{cell} is not a comparision}" do
          expect(matcher.matches?(cell)).to eq false
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv_decision2-0.5.2 spec/csv_decision2/matchers/numeric_spec.rb