<commit_before>use v6;

use Test;

plan 38;

# L<S04/The Relationship of Blocks and Declarations/function has been renamed>
{
  my $a = 42;
  {
    is($(temp $a = 23; $a), 23, "temp() changed the variable (1)");
  }
  is $a, 42, "temp() restored the variable (1)";
}

# Test that temp() restores the variable at scope exit, not at subroutine
# entry.
{<commit_msg>Add tests for temp array and hash (#206)<commit_after>use v6;

use Test;

plan 42;

# L<S04/The Relationship of Blocks and Declarations/function has been renamed>
{
  my $a = 42;
  {
    # warning - do {temp $a = 23; $a} not the same
    #   https://irclog.perlgeek.de/perl6/2016-12-23#i_13791566
    is($(temp $a = 23; $a), 23, "temp() changed the variable (1)");
  }
  is $a, 42, "temp() restored the variable (1)";

  my @a = (42);
  {
    is-deeply( (temp @a).push(64), [42, 64], 'changed the temp array' )
  }
  is-deeply(@a, [42], 'temp() restored the array');

  my %h = k1 => 3;
  {
    (temp %h)<k2> = 5;
    is-deeply(%h, {k1 => 3, k2 => 5}, 'changed the temp hash' )
  }
  is-deeply(%h, {k1 => 3}, 'temp() restored the hash')
}

# Test that temp() restores the variable at scope exit, not at subroutine
# entry.
{
{'fraction_non_alphanumeric': 0.17424242424242425, 'fraction_numerical': 0.06060606060606061, 'mean_word_length': 3.186619718309859, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 1, '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': '7297646', 'n_tokens_mistral': 519, 'n_tokens_neox': 465, 'n_words': 156}