Conversation
c2f1960 to
b01da8d
Compare
| def with_array(*elements) | ||
| return WithEnum.new to_enum(__method__ || raise, *elements) unless block_given? | ||
|
|
||
| yield elements | ||
| yield ToArray.new(*elements) | ||
| end | ||
|
|
||
| def with_hash(hash = {}) |
There was a problem hiding this comment.
with_array(*elements), but not with_hash(**elements)?
Note: kwargs isn’t Symbols only and that – good?
p('any key' => 'is valid', 420 => 69)
#=> {"any key"=>"is valid", 420=>69}There was a problem hiding this comment.
We can pass hash without curly brace with the current definition. So any other good reason to make it kwargs?
There was a problem hiding this comment.
I just prefer consistency.
test/stdlib/test_helper.rb
Outdated
| BlankSlate = RBS::UnitTest::Convertibles::BlankSlate | ||
| ToIO = RBS::UnitTest::Convertibles::ToIO | ||
| ToI = RBS::UnitTest::Convertibles::ToI | ||
| ToInt = RBS::UnitTest::Convertibles::ToInt | ||
| ToF = RBS::UnitTest::Convertibles::ToF | ||
| ToR = RBS::UnitTest::Convertibles::ToR | ||
| ToC = RBS::UnitTest::Convertibles::ToC | ||
| ToStr = RBS::UnitTest::Convertibles::ToStr | ||
| ToS = RBS::UnitTest::Convertibles::ToS | ||
| ToSym = RBS::UnitTest::Convertibles::ToSym | ||
| ToA = RBS::UnitTest::Convertibles::ToA | ||
| ToArray = RBS::UnitTest::Convertibles::ToArray | ||
| ToHash = RBS::UnitTest::Convertibles::ToHash | ||
| ToPath = RBS::UnitTest::Convertibles::ToPath | ||
| CustomRange = RBS::UnitTest::Convertibles::CustomRange | ||
| Each = RBS::UnitTest::Convertibles::Each |
There was a problem hiding this comment.
include RBS::UnitTest::Convertibles?
There was a problem hiding this comment.
Ah this is in fact for RBS runtime type checker. I'm not sure if including works for it...
|
I see potential for property based testing (or fuzzing) in this framework. with_int(count: 100) do |i|
# Yields 100 times random integer value
end |
lib/rbs/unit_test/convertibles.rb
Outdated
| module Convertibles | ||
| class BlankSlate < BasicObject | ||
| instance_methods.each do |im| | ||
| next if %i[__send__ __id__].include? im |
There was a problem hiding this comment.
We might want to remove __id__ from this list, as it doesnt warn when you undef it
| def each(&block) = @enum.each(&block) | ||
|
|
||
| def and_nil(&block) | ||
| self.and(nil, &_ = block) |
There was a problem hiding this comment.
We should add return WithEnum.new to_enum(__method__ || raise) unless block here
There was a problem hiding this comment.
and accepts no block call. So it should be ok.
|
|
||
| # An object with `#to_io` method | ||
| class ToIO < BlankSlate | ||
| @io: untyped |
There was a problem hiding this comment.
Shouldn't these untypeds be given types? ditto for initialize and to_xxx for each of the ToXXX classes
There was a problem hiding this comment.
What is the type of IO here? I think it's not very clear and decided to keep them untyped.
There was a problem hiding this comment.
@io should be ::IO; Same for ToStr and String, etc
sig/unit_test/with_aliases.rbs
Outdated
|
|
||
| # Yields `::array` objects | ||
| # | ||
| def with_array: (*untyped elements) { (array[untyped]) -> void } -> void |
There was a problem hiding this comment.
We should give this a type, like def with_array: [T] (*T elements). Same with hash and range
There was a problem hiding this comment.
Skip range method because it requires <=> method.
There was a problem hiding this comment.
unintentional inclusion?
There was a problem hiding this comment.
Yeah, it's unrelated, but I think it's acceptable to mix it.
b01da8d to
438e43e
Compare
438e43e to
980b56d
Compare
This PR moves the helpers like
with_intfromtest/stdlibtolib/rbs/unit_test, so that other gems can use them to test their type definitions.