From 62b9f170bcaec15780259f4dfd99cf35e903520c Mon Sep 17 00:00:00 2001 From: Soutaro Matsumoto Date: Wed, 20 Dec 2023 12:04:57 +0900 Subject: [PATCH] Revert "Merge pull request #1600 from sampersand/swesterman/23-11-07/add-test-harness-utils" This reverts commit 854be0b911580564876e93c0f475260b5dc6a933, reversing changes made to d92e90e15f6a339a765634866eb55db79e61e63e. --- test/stdlib/Dir_test.rb | 2 +- test/stdlib/Exception_test.rb | 12 +++---- test/stdlib/Marshal_test.rb | 6 ++-- test/stdlib/Signal_test.rb | 4 +-- test/stdlib/UnboundMethod_test.rb | 4 +-- test/stdlib/test_helper.rb | 59 ++++++------------------------- 6 files changed, 25 insertions(+), 62 deletions(-) diff --git a/test/stdlib/Dir_test.rb b/test/stdlib/Dir_test.rb index 6c956ac8c..5eae341d1 100644 --- a/test/stdlib/Dir_test.rb +++ b/test/stdlib/Dir_test.rb @@ -97,7 +97,7 @@ def test_entries end def test_exist? - with_path.and(with_io) do |path| + with_path.chain(with_io).each do |path| assert_send_type "(::path | ::io) -> bool", Dir, :exist?, path end diff --git a/test/stdlib/Exception_test.rb b/test/stdlib/Exception_test.rb index 2507e6beb..89e05c510 100644 --- a/test/stdlib/Exception_test.rb +++ b/test/stdlib/Exception_test.rb @@ -16,7 +16,7 @@ def test_exception assert_send_type '() -> ExceptionSingletonTest::MyException', MyException, :exception - with_string.and(1r) do |message| + with_string.chain([1r]).each do |message| assert_send_type '(string | _ToS) -> ExceptionSingletonTest::MyException', MyException, :exception, message end @@ -83,7 +83,7 @@ def test_detailed_message assert_send_type '() -> String', INSTANCE, :detailed_message - with_bool.and_nil do |highlight| + [true, false, nil].each do |highlight| assert_send_type '(highlight: bool?) -> String', INSTANCE, :detailed_message, highlight: highlight assert_send_type '(highlight: bool?, **untyped) -> String', @@ -99,14 +99,14 @@ def test_exception assert_send_type '(self) -> self', INSTANCE, :exception, INSTANCE - with_string.and(Object.new, 1r) do |message| + with_string.chain([Object.new, 1r]).each do |message| assert_send_type '(string | _ToS) -> ExceptionInstanceTest::MyException', MyException.new, :exception, message end end def test_initialize - with_string.and(Object.new, 1r) do |message| + with_string.chain([Object.new, 1r]).each do |message| assert_send_type '(string | _ToS) -> self', Exception.allocate, :initialize, message end @@ -144,11 +144,11 @@ def test_full_message assert_send_type '() -> String', INSTANCE, :full_message - with_bool.and_nil do |highlight| + [true, false, nil].each do |highlight| assert_send_type '(highlight: bool?) -> String', INSTANCE, :full_message, highlight: highlight - with_string('top').and(nil, with_string('bottom'), :top, :bottom) do |order| + with_string('top').chain(with_string('bottom'), [:top, :bottom, nil]).each do |order| assert_send_type '(highlight: bool?, order: (:top | :bottom | string)?) -> String', INSTANCE, :full_message, highlight: highlight, order: order end diff --git a/test/stdlib/Marshal_test.rb b/test/stdlib/Marshal_test.rb index fbb6fe01c..bfd626f10 100644 --- a/test/stdlib/Marshal_test.rb +++ b/test/stdlib/Marshal_test.rb @@ -26,7 +26,7 @@ def test_dump assert_send_type '(untyped, Writer) -> Writer', Marshal, :dump, obj, writer - with_int.and_nil do |limit| + with_int.chain([nil]).each do |limit| assert_send_type '(untyped, Writer, int?) -> Writer', Marshal, :dump, obj, writer, limit end @@ -69,7 +69,7 @@ def result_proc.call(loaded) 1r end Marshal, meth, source, result_proc source.reset! - with_boolish do |freeze| + [nil, :yep, true, "hello"].each do |freeze| assert_send_type '(string | Marshal::_Source, freeze: boolish) -> untyped', Marshal, meth, source, freeze: freeze source.reset! @@ -102,7 +102,7 @@ def test_dump assert_send_type '(untyped, Writer) -> Writer', Marshal, :dump, obj, writer - with_int.and_nil do |limit| + with_int.chain([nil]).each do |limit| assert_send_type '(untyped, Writer, int?) -> Writer', Marshal, :dump, obj, writer, limit end diff --git a/test/stdlib/Signal_test.rb b/test/stdlib/Signal_test.rb index 054c84ba7..e803c27ed 100644 --- a/test/stdlib/Signal_test.rb +++ b/test/stdlib/Signal_test.rb @@ -25,11 +25,11 @@ def test_signame def test_trap old_usr2 = trap(:USR2, nil) - with_interned(:USR2).and(Signal.list['USR2']) do |signal| + with_interned(:USR2).chain([Signal.list['USR2']]).each do |signal| assert_send_type '(Integer | ::interned) { (Integer) -> void } -> Signal::trap_command', Signal, :trap, signal do |n| end - with_string('').and(with_bool, nil, Class.new { def call(x) end }.new) do |command| + with_string('').chain([true, false, nil, Class.new{def call(x)end}.new]).each do |command| assert_send_type '(Integer | ::interned, Signal::trap_command) -> Signal::trap_command', Signal, :trap, signal, command end diff --git a/test/stdlib/UnboundMethod_test.rb b/test/stdlib/UnboundMethod_test.rb index 4b2ad2c2b..1b137584c 100644 --- a/test/stdlib/UnboundMethod_test.rb +++ b/test/stdlib/UnboundMethod_test.rb @@ -17,14 +17,14 @@ def no_kwargs(**nil) end end def test_eq - with_untyped.and(UMETH) do |other| + [UMETH, proc{}, Object.new, nil].each do |other| assert_send_type '(untyped) -> bool', UMETH, :==, other end end def test_eql? - with_untyped.and(UMETH) do |other| + [UMETH, proc{}, Object.new, nil].each do |other| assert_send_type '(untyped) -> bool', UMETH, :eql?, other end diff --git a/test/stdlib/test_helper.rb b/test/stdlib/test_helper.rb index 42d2acb9e..0851d5fbe 100644 --- a/test/stdlib/test_helper.rb +++ b/test/stdlib/test_helper.rb @@ -168,103 +168,66 @@ def if_ruby31(&block) end module WithAliases - class WithEnum - include Enumerable - - def initialize(enum) = @enum = enum - - def each(&block) = @enum.each(&block) - - def and_nil(&block) - self.and(nil, &block) - end - - def and(*args, &block) - return WithEnum.new to_enum(__method__, args) unless block_given? - each(&block) - args.each do |arg| - if WithEnum === arg - arg.each(&block) - else - block.call(arg) - end - end - end - end - def with_int(value = 3) - return WithEnum.new to_enum(__method__, value) unless block_given? + return to_enum(__method__, value) unless block_given? yield value yield ToInt.new(value) end def with_float(value = 0.1) - return WithEnum.new to_enum(__method__, value) unless block_given? + return to_enum(__method__, value) unless block_given? yield value yield ToF.new(value) end - def with_string(value = '') - return WithEnum.new to_enum(__method__, value) unless block_given? + def with_string(value = "") + return to_enum(__method__, value) unless block_given? yield value yield ToStr.new(value) end def with_array(*elements) - return WithEnum.new to_enum(__method__, *elements) unless block_given? + return to_enum(__method__, *elements) unless block_given? yield elements yield ToArray.new(*elements) end def with_hash(hash = {}) - return WithEnum.new to_enum(__method__, hash) unless block_given? + return to_enum(__method__, hash) unless block_given? yield hash yield ToHash.new(hash) end def with_io(io = $stdout) - return WithEnum.new to_enum(__method__, io) unless block_given? + return to_enum(__method__, io) unless block_given? yield io yield ToIO.new(io) end def with_path(path = "/tmp/foo.txt", &block) - return WithEnum.new to_enum(__method__, path) unless block_given? + return to_enum(__method__, path) unless block_given? with_string(path, &block) block.call ToPath.new(path) end def with_encoding(encoding = Encoding::UTF_8, &block) - return WithEnum.new to_enum(__method__, encoding) unless block_given? + return to_enum(__method__, encoding) unless block_given? block.call encoding with_string(encoding.to_s, &block) end def with_interned(value = :&, &block) - return WithEnum.new to_enum(__method__, value) unless block_given? + return to_enum(__method__, value) unless block_given? with_string(value.to_s, &block) block.call value.to_sym end - - def with_bool - return WithEnum.new to_enum(__method__) unless block_given? - yield true - yield false - end - - def with_boolish(&block) - return WithEnum.new to_enum(__method__) unless block_given? - with_bool(&block) - [nil, 1, Object.new, BlankSlate.new, "hello, world!"].each(&block) - end - - alias with_untyped with_boolish end + module TypeAssertions module ClassMethods attr_reader :target