<commit_before>use v6;
use Test;
plan 32;

=begin pod

=head1 DESCRIPTION

This test tests the C<WHAT> builtin.

=end pod

# L<S12/Introspection/"WHAT">

# Basic subroutine/method form tests for C<WHAT>.
{
  my $a = 3;
  ok((WHAT $a) === Int, "subroutine form of WHAT");
  ok(($a.WHAT) === Int, "method form of WHAT");
}

# Now testing basic correct inheritance.
{
  my $a = 3;
  ok($a.WHAT ~~ Numeric, "an Int isa Numeric");
  ok($a.WHAT ~~ Mu,  "an Int isa Mu");
}

# And a quick test for Code:
{
  my $a = sub ($x) { 100 + $x };
  ok($a.WHAT === Sub,    "a sub's type is Sub");
  ok($a.WHAT ~~ Routine, "a sub isa Routine");
  ok($a.WHAT ~~ Code,    "a sub isa Code");
}

# L<S12/Introspection/"which also bypasses the macros.">

# RT #60992
{
    class Foo {
        method WHAT {'Bar'}
    }
    my $o = Foo.new;
    is($o."WHAT"(), 'Bar', '."WHAT" calls the method instead of the macro');
    is($o.WHAT.gist,   'Foo()', '.WHAT still works as intended');
    my $meth = method () { 'Bar' };
    is($o.$meth,  'Bar', '.$meth calls the method instead of the macro');
}

# these used to be Rakudo regressions, RT #62006
{
    # proto as a term
    lives_ok {  Match }, 'type object as a term lives';
    lives_ok { +Match }, 'numification of type object lives';
    isa_ok ("bac" ~~ /a/).WHAT, Match, '.WHAT on a Match works';
    #?niecza skip '#84: System.FormatException: Unknown char: M'
    is +("bac" ~~ /a/).WHAT.gist, 0, 'numification of .WHAT of a Match works';
}

ok &infix:<+>.WHAT ~~ Sub, '.WHAT of built-in infix op is Multi (RT 66928)';

# RT #69915
{
    sub rt69915f($b, :$a! ) { return WHAT($a).gist ~ '~' ~ WHAT($b).gist }
    sub rt69915m( $b, :$a! ) { return $a.WHAT.gist  ~ '~' ~ $b.WHAT.gist }

    is rt69915m( a => 42, 23 ), 'Int()~Int()', 'WHAT method on ints';

    is rt69915f( a => 42, 23 ), 'Int()~Int()', 'WHAT function on ints (1)';
    is rt69915f( 23, a => 42 ), 'Int()~Int()', 'WHAT function on ints (2)';

    is rt69915f( :a, 23 ), 'Bool()~Int()', 'WHAT function on bool and int';
    is rt69915m( :a, 23 ), 'Bool()~Int()', 'WHAT method on bool and int';<commit_msg>[S12-methods/what] Fix over-zealous .gist usage from f85b8bf9, was testing the wrong thing as a result (fixes sorear/niecza#84)<commit_after>use v6;
use Test;
plan 32;

=begin pod

=head1 DESCRIPTION

This test tests the C<WHAT> builtin.

=end pod

# L<S12/Introspection/"WHAT">

# Basic subroutine/method form tests for C<WHAT>.
{
  my $a = 3;
  ok((WHAT $a) === Int, "subroutine form of WHAT");
  ok(($a.WHAT) === Int, "method form of WHAT");
}

# Now testing basic correct inheritance.
{
  my $a = 3;
  ok($a.WHAT ~~ Numeric, "an Int isa Numeric");
  ok($a.WHAT ~~ Mu,  "an Int isa Mu");
}

# And a quick test for Code:
{
  my $a = sub ($x) { 100 + $x };
  ok($a.WHAT === Sub,    "a sub's type is Sub");
  ok($a.WHAT ~~ Routine, "a sub isa Routine");
  ok($a.WHAT ~~ Code,    "a sub isa Code");
}

# L<S12/Introspection/"which also bypasses the macros.">

# RT #60992
{
    class Foo {
        method WHAT {'Bar'}
    }
    my $o = Foo.new;
    is($o."WHAT"(), 'Bar', '."WHAT" calls the method instead of the macro');
    is($o.WHAT.gist,   'Foo()', '.WHAT still works as intended');
    my $meth = method () { 'Bar' };
    is($o.$meth,  'Bar', '.$meth calls the method instead of the macro');
}

# these used to be Rakudo regressions, RT #62006
{
    # proto as a term
    lives_ok {  Match }, 'type object as a term lives';
    lives_ok { +Match }, 'numification of type object lives';
    isa_ok ("bac" ~~ /a/).WHAT, Match, '.WHAT on a Match works';
    is +("bac" ~~ /a/).WHAT, 0, 'numification of .WHAT of a Match works';
}

ok &infix:<+>.WHAT ~~ Sub, '.WHAT of built-in infix op is Multi (RT 66928)';

# RT #69915
{
    sub rt69915f($b, :$a! ) { return WHAT($a).gist ~ '~' ~ WHAT($b).gist }
    sub rt69915m( $b, :$a! ) { return $a.WHAT.gist  ~ '~' ~ $b.WHAT.gist }

    is rt69915m( a => 42, 23 ), 'Int()~Int()', 'WHAT method on ints';

    is rt69915f( a => 42, 23 ), 'Int()~Int()', 'WHAT function on ints (1)';
    is rt69915f( 23, a => 42 ), 'Int()~Int()', 'WHAT function on ints (2)';

    is rt69915f( :a, 23 ), 'Bool()~Int()', 'WHAT function on bool and int';
    is rt69915m( :a, 23 ), 'Bool()~Int()', 'WHAT method on bool and int';
{'fraction_non_alphanumeric': 0.19440526563234603, 'fraction_numerical': 0.043253408556652564, 'mean_word_length': 3.0795781399808244, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6673503', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1660, 'n_words': 554}