Sha256: 1ee7bf91e5688149742e17250ded0eb13b35dda533be3f34d8189c93e4dc1718

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require 'minitest'

module RaaP
  module Minitest
    def forall(*types, size_step: 0...100)
      # @type self: Minitest::Test

      if types.length == 1 && types.first.instance_of?(String) && types.first.start_with?("(")
        # forall("(Integer) -> String") { |int| Foo.new.int2str(int) }
        type = types.first
        method_type = RaaP::MethodType.new(type)
        size_step.each do |size|
          # TODO assert_send_type
          args, kwargs, _block = method_type.pick_arguments(size:)
          return_value = yield(*args, **kwargs)
          i = BindCall.inspect(return_value)
          c = BindCall.class(return_value)
          r = method_type.rbs.type.return_type
          msg = "return value: #{i}[#{c}] is not match with `#{r}`"
          assert method_type.check_return(return_value), msg
        end
      else
        # forall("Integer", "String") { |int, str| Foo.new.int_str(int, str) }
        types.map! do |type|
          case type
          in String then RaaP::Type.new(type)
          else type
          end
        end
        size_step.each do |size|
          values = types.map { |t| t.pick(size:) }
          assert yield(*values)
        end
      end
    end
  end
end

Minitest::Test.include RaaP::Minitest

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
raap-0.5.0 lib/raap/minitest.rb