### ----------------------------------------------------
### -- PrettyDump
### -- Licenses: Artistic-2.0
### -- Authors: brian d foy, Raku Community
### -- File: t/03.Unknown.rakutest
### ----------------------------------------------------
use Test;
use PrettyDump;

plan 5;

my $p = PrettyDump.new;

# This class should not respond to .Str or .PrettyDump. The easiest
# way to do that is to fake that they can't do anything is to have
# can always return False
class TinyClass {
    has $.foo;
    method can ( Str $method ) { False }
}

my $tiny-class-str = 'TinyClass';
my $tiny-class = ::($tiny-class-str);

is PrettyDump.can( $tiny-class-str ).elems, 0, "PrettyDump does not handle $tiny-class-str";

can-ok $tiny-class, 'can';
is $tiny-class.can( 'Str' ), False, "$tiny-class-str does not do .Str";
is $tiny-class.can( 'PrettyDump' ), False, "$tiny-class-str does not do .PrettyDump";

subtest 'Object with no .Str or .PrettyDump' => {
    my $object = $tiny-class.new;
    isa-ok $object, $tiny-class;

    my $string = $p.dump: $object;
    isa-ok $string, Str, 'Got Str back';
    my $expected = qq/(Unhandled {$tiny-class-str})/;

    is $string, $expected, 'Dumping @array returns expected string';
}

# vim: expandtab shiftwidth=4


