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

# TODO: move this test to closure-parameters.t if it works in the future

# L<S06/Closure parameters>

our $collector = 2;
sub to_be_called($x) {
    $collector += $x;
}

sub tester(&my_sub) {
    my_sub(4);
}

tester(&to_be_called);
ok $collector == 6, 'Can call my_sub() if &my_sub was a parameter';

tester(sub ($x) { $collector = 3 * $x });
ok $collector == 12, 'same with anonymous sub';

sub tester2(&my_sub) { 1 }
dies_ok {tester2(42)}, "can't pass thing that doesn't do Callable";

sub not_returns_a_sub { 3 };
dies_ok {tester2(not_returns_a_sub)}, 
        "can't pass thing that doesn't do Callable";

# vim: ft=perl6<commit_msg>[t/spec] Test for RT #68578<commit_after>use v6;
use Test;
plan 6;

# TODO: move this test to closure-parameters.t if it works in the future

# L<S06/Closure parameters>

our $collector = 2;
sub to_be_called($x) {
    $collector += $x;
}

sub tester(&my_sub) {
    my_sub(4);
}

tester(&to_be_called);
ok $collector == 6, 'Can call my_sub() if &my_sub was a parameter';

tester(sub ($x) { $collector = 3 * $x });
ok $collector == 12, 'same with anonymous sub';

sub tester2(&my_sub) { 1 }
dies_ok {tester2(42)}, "can't pass thing that doesn't do Callable";

sub not_returns_a_sub { 3 };
dies_ok {tester2(not_returns_a_sub)}, 
        "can't pass thing that doesn't do Callable";

is tester2({ 'block' }), 1, 'Can pass a block to a &parameter';

# RT #68578
{
    sub rt68578( Callable &x ) {}
    dies_ok { rt68578({ 'block' }) }, "Can't pass block that doesn't do Callable";
}

# vim: ft=perl6
{'fraction_non_alphanumeric': 0.15047619047619049, 'fraction_numerical': 0.036825396825396824, 'mean_word_length': 4.150326797385621, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5962059', 'n_tokens_mistral': 664, 'n_tokens_neox': 605, 'n_words': 190}