Closed postmodern closed 2 years ago
I've found two issues:
Hexdump::Type::Int#initialize
has a size
parameter. That uses Int32
instead of ::Int32
, so it accidentally references the Int32
class below it..to be(nil)
doesn't behave correctly against value-types. In this instance, Endian
is nillable. The be
matcher uses the #same
method for comparison. But this is only found on Nil
and reference types. Spectator has custom logic for values, but didn't handle nil and value types quite right. This has been fixed and pushed to master.After addressing both of these issues, the spec passes.
Alternatively, for 2, be_nil
can be used in place of be(nil)
.
Could a special case be added for be(nil)
and Value types?
Could a special case be added for
be(nil)
and Value types?
Yup, one has been added and is on master.
I've made the suggested changes and updated spectator, but now I'm hitting this issue when using .to be(...)
to compare entries in a Hash.
TYPES = Hash(Symbol,Type).new
TYPES[:uint8] = Type::UInt8.new
TYPES[:byte] = TYPES[:uint8]
require "./spec_helper"
require "../src/hexdump/types"
Spectator.describe "Hexdump::TYPES" do
subject { Hexdump::TYPES }
describe "byte" do
it "must be an alias to uint8" do
expect(subject[:byte]).to be(subject[:uint8])
end
end
In spec/types_spec.cr:9:31
9 | expect(subject[:byte]).to be(subject[:uint8])
^-
Error: instantiating 'Spectator::Expectation::Target(Hexdump::Type)#to(Spectator::Matchers::ReferenceMatcher(Hexdump::Type))'
In lib/spectator/src/spectator/expectation.cr:104:7
104 | def to(matcher, message = nil) : Nil
^-
Error: instantiating 'to(Spectator::Matchers::ReferenceMatcher(Hexdump::Type), Nil)'
In lib/spectator/src/spectator/expectation.cr:105:30
105 | match_data = matcher.match(@expression)
^----
Error: instantiating 'Spectator::Matchers::ReferenceMatcher(Hexdump::Type)#match(Spectator::Expression(Hexdump::Type)+)'
In lib/spectator/src/spectator/matchers/standard_matcher.cr:27:10
27 | if match?(actual)
^-----
Error: instantiating 'match?(Spectator::Expression(Hexdump::Type)+)'
In lib/spectator/src/spectator/matchers/reference_matcher.cr:20:15
20 | value.same?(actual.value)
^----
Error: instantiating 'Hexdump::Type+#same?(Hexdump::Type+)'
In /var/lib/snapd/snap/crystal/793/share/crystal/src/reference.cr:29:5
29 | object_id == other.object_id
^--------
Error: instantiating 'object_id()'
In /var/lib/snapd/snap/crystal/793/share/crystal/src/primitives.cr:50:19
50 | def object_id : UInt64
^-----
Error: method Hexdump::Type+#object_id must return UInt64 but it is returning Hexdump::Type::UInt64
Hexdump::Type::UInt64 trace:
/var/lib/snapd/snap/crystal/793/share/crystal/src/primitives.cr:50
def object_id : UInt64
An interesting problem. I'm attempting to port [this Ruby code]() which defines a
Type
class which contains other classes such asInt32
. In Crystal I had to explicitly specify::Int32
to avoid constant shadowing. However, Spectator is having issues withcrystal_type_id
. It appears that when describingHexdump::Type
theInt32
class contained within is shadowing the top levelInt32
.Source
Specs
Error