samedi 16 mars 2019

Test module 'isa-ok' with Buf

Using the Perl6 Test module to test an object's type with Buf:

use Test;
isa-ok Buf.new, Buf;
isa-ok Buf.new, Blob;
isa-ok Buf.new, 'Buf';
isa-ok Buf.new, 'Blob';
ok Buf.new ~~ Buf;
ok Buf.new ~~ Blob;
does-ok Buf.new, Buf;
does-ok Buf.new, Blob;

Here's the output:

not ok 1 - The object is-a 'Buf'
# Failed test 'The object is-a 'Buf''
# at buftest line 3
# Actual type: Buf
not ok 2 - The object is-a 'Blob'
# Failed test 'The object is-a 'Blob''
# at buftest line 5
# Actual type: Buf
ok 3 - The object is-a '"Buf"'
not ok 4 - The object is-a '"Blob"'
# Failed test 'The object is-a '"Blob"''
# at buftest line 9
# Actual type: Buf
ok 5 - 
ok 6 - 
ok 7 - The object does role 'Buf'
ok 8 - The object does role 'Blob'


How does isa-ok really work? How does that differ from just ~~? What is the difference between testing an object against Buf vs. 'Buf'? Why isn't a Buf considered to be isa a Buf or Blob? (while it isa a 'Buf' but still not a 'Blob'?

In general, does isa-ok understand roles or must does-ok be used for them?

Aucun commentaire:

Enregistrer un commentaire