Sha256: 4d397d0e5e77bae08076bcf8e145e8c37f759274d4f5656289eb7e268b8c161c

Contents?: true

Size: 899 Bytes

Versions: 3

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Yardcheck::Typedef do
  def typedef(*types)
    typedefs =
      types.map do |type|
        described_class::Literal.new(Yardcheck::Const.new(type))
      end

    described_class.new(typedefs)
  end

  it 'matches exact type matches' do
    expect(typedef(Integer).match?(Yardcheck::TestValue.new(1))).to be(true)
  end

  it 'matches descendants' do
    parent = Class.new
    child  = Class.new(parent)

    expect(typedef(parent).match?(Yardcheck::TestValue.new(child.new))).to be(true)
  end

  it 'matches union type definitions' do
    aggregate_failures do
      definition = typedef(Integer, String)
      expect(definition.match?(Yardcheck::TestValue.new(1))).to be(true)
      expect(definition.match?(Yardcheck::TestValue.new('hi'))).to be(true)
      expect(definition.match?(Yardcheck::TestValue.new(:hi))).to be(false)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yardcheck-0.0.3 spec/unit/yardcheck/typedef_spec.rb
yardcheck-0.0.2 spec/unit/yardcheck/typedef_spec.rb
yardcheck-0.0.1 spec/unit/yardcheck/typedef_spec.rb