#!/usr/bin/env ruby # frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("../../test", __FILE__) require "bundler/setup" require "pry" require 'rubocop' require "speculation" require "speculation/test" require "speculation/gen" def reload! Minitest::Test.reset STest.unstrument if Object.const_defined?(:STest) [:Speculation, :S, :STest, :Gen, :U, :H, :V].each do |const| Object.send :remove_const, const if Object.const_defined?(const) end load "./lib/speculation/namespaced_symbols.rb" load "./lib/speculation/pmap.rb" load "./lib/speculation/identifier.rb" load "./lib/speculation/utils.rb" load "./lib/speculation/error.rb" load "./lib/speculation/spec_impl.rb" Dir["lib/speculation/spec_impl/*.rb"].each do |f| load f end load "./lib/speculation.rb" load "./lib/speculation/gen.rb" load "./lib/speculation/test.rb" Dir["test/**/*.rb"].each do |f| load f end Object.const_set(:S, Speculation) Object.const_set(:STest, Speculation::Test) Object.const_set(:Gen, Speculation::Gen) Object.const_set(:U, Speculation::Utils) STest.instrument end def t reload! Minitest.run end def r RuboCop::CLI.new.run(['--display-cop-names']) end # allow running minitest assertions require "minitest" include Minitest::Assertions def self.assertions; 1; end def self.assertions=(_x); end extend Speculation::NamespacedSymbols def self.test_check_utils S.fdef(U.method(:hash?), :args => S.tuple(ns(S, :any)), :ret => ns(S, :boolean)) S.fdef(U.method(:array?), :args => S.tuple(ns(S, :any)), :ret => ns(S, :boolean)) S.fdef(U.method(:collection?), :args => S.tuple(ns(S, :any)), :ret => ns(S, :boolean)) S.fdef(U.method(:itself), :args => S.cat(:x => ns(S, :any)), :ret => ns(S, :any), :fn => ->(x) { x[:args][:x].equal?(x[:ret]) }) # S.fdef(U.method(:complement), # :args => ns(S, :empty), # :block => S.fspec(:args => S.zero_or_more(ns(S, :any)), # :ret => ns(S, :any)), # :ret => S.fspec(:args => S.zero_or_more(ns(S, :any)), # :ret => ns(S, :boolean))) S.fdef(U.method(:constantly), :args => S.cat(:x => ns(S, :any)), :ret => Proc, :fn => ->(x) { x[:args][:x].equal?(x[:ret].call) }) S.fdef(U.method(:distinct?), :args => S.cat(:coll => Enumerable), :ret => ns(S, :boolean)) S.fdef(U.method(:ident?), :args => S.cat(:x => ns(S, :any)), :ret => ns(S, :boolean)) S.fdef(U.method(:method?), :args => S.cat(:x => ns(S, :any)), :ret => ns(S, :boolean)) S.fdef(U.method(:empty), :args => S.cat(:coll => Enumerable), :ret => S.and(Enumerable, ->(coll) { coll.empty? }), :fn => ->(x) { x[:args][:coll].class == x[:ret].class }) STest.summarize_results(STest.check(STest.enumerate_methods(Speculation::Utils), :num_tests => 50)) end reload! Pry.start