<commit_before>use v6;

use Test;

# L<S02/Names and Variables/To get a Perlish representation of any object>

my @tests = (
    # Basic scalar values
    42, 42/10, 4.2, sqrt(2),
    #?rakudo emit # 3e5 is converted to a Str when re-evaled
    3e5,
    #?rakudo emit # Failure objects have no .perl method and +/-Inf/NaN fail
    Inf, -Inf, NaN,

    "a string", "", "\0", "\t", "\n", "\r\n", "\o7",
    '{', # "\d123",	# XXX there is no \d escape!!!
    '}',
    '$a @string %with &sigils()',

    ?1, ?0,
    undef,
    #?rakudo emit # parse error
    rx:P5/foo/, rx:P5//, rx:P5/^.*$/,

    # References to scalars
    #?rakudo emit #
    \42, \Inf, \-Inf, \NaN, \"string", \"", \?1, \?0, \undef,

    (a => 1),
    :b(2),

    # References to aggregates
    [],      # empty array
    [ 42 ],  # only one elem
    [< a b c>],
    {},           # empty hash
    { a => 42 },  # only one elem
    { :a(1), :b(2), :c(3) },

    [ 3..42 ],
    # Infinite arrays, commented because they take infram and inftime in
    # current Pugs
    #?pugs emit # 
    [ 3..Inf ],
    #?pugs emit # 
    [ -Inf..Inf ],
    #?pugs emit # 
    [ 3..42, 17..Inf, -Inf..5 ],

    # Nested things
    { a => [1,2,3] },  # only one elem
    [      [1,2,3] ],  # only one elem
    { a => [1,2,3], b => [4,5,6] },
    [ { :a(1) }, { :b(2), :c(3) } ],
);

plan 11 + 2*@tests;
#?pugs emit force_todo 8, 45..50, 94, 96;

#?pugs emit unless $?PUGS_BACKEND eq "BACKEND_PUGS" {
#?pugs emit   skip_rest "eval() not yet implemented in $?PUGS_BACKEND.";
#?pugs emit   exit;
#?pugs emit }


# L<S02/Names and Variables/To get a Perlish representation of any object>
# Quoting S02 (emphasis added):
#   To get a Perlish representation of any data value, use the .perl method.
#   This will put quotes around strings, square brackets around list values,
#   curlies around hash values, etc., **such that standard Perl could reparse
#   the result**.
{
    for @tests -> $obj {
        #?rakudo skip 'eqv not implemented'
        ok eval($obj.perl) eqv $obj,
            "($obj.perl()).perl returned something whose eval()ed stringification is unchanged";<commit_msg>[t/spec] fudge and unfudge for current rakudo<commit_after>use v6;

use Test;

# L<S02/Names and Variables/To get a Perlish representation of any object>

my @tests = (
    # Basic scalar values
    42, 42/10, 4.2, sqrt(2),
    #?rakudo emit # 3e5 is converted to a Str when re-evaled
    3e5,
    #?rakudo emit # Failure objects have no .perl method and +/-Inf/NaN fail
    Inf, -Inf, NaN,

    "a string", "", "\0", "\t", "\n", "\r\n", "\o7",
    '{', # "\d123",	# XXX there is no \d escape!!!
    '}',
    '$a @string %with &sigils()',

    ?1, ?0,
    undef,
    #?rakudo emit # parse error
    rx:P5/foo/, rx:P5//, rx:P5/^.*$/,

    # References to scalars
    \42, \Inf, \-Inf, \NaN, \"string", \"", \?1, \?0, \undef,

    (a => 1),
    :b(2),

    # References to aggregates
    [],      # empty array
    [ 42 ],  # only one elem
    [< a b c>],
    {},           # empty hash
    { a => 42 },  # only one elem
    { :a(1), :b(2), :c(3) },

    [ 3..42 ],
    # Infinite arrays, commented because they take infram and inftime in
    # current Pugs
    #?pugs emit # 
    #?rakudo emit # Inf takes infram and inftime
    [ 3..Inf ],
    #?pugs emit #
    #?rakudo emit # Inf takes infram and inftime
    [ -Inf..Inf ],
    #?pugs emit # 
    #?rakudo emit # Inf takes infram and inftime
    [ 3..42, 17..Inf, -Inf..5 ],

    # Nested things
    { a => [1,2,3] },  # only one elem
    [      [1,2,3] ],  # only one elem
    { a => [1,2,3], b => [4,5,6] },
    [ { :a(1) }, { :b(2), :c(3) } ],
);

plan 11 + 2*@tests;
#?pugs emit force_todo 8, 45..50, 94, 96;

#?pugs emit unless $?PUGS_BACKEND eq "BACKEND_PUGS" {
#?pugs emit   skip_rest "eval() not yet implemented in $?PUGS_BACKEND.";
#?pugs emit   exit;
#?pugs emit }


# L<S02/Names and Variables/To get a Perlish representation of any object>
# Quoting S02 (emphasis added):
#   To get a Perlish representation of any data value, use the .perl method.
#   This will put quotes around strings, square brackets around list values,
#   curlies around hash values, etc., **such that standard Perl could reparse
#   the result**.
{
    for @tests -> $obj {
        ok eval($obj.perl) eq $obj,
            "($obj.perl()).perl returned something whose eval()ed stringification is unchanged";
{'fraction_non_alphanumeric': 0.17340644276901987, 'fraction_numerical': 0.03655471784327165, 'mean_word_length': 2.370284834488068, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '751621', 'n_tokens_mistral': 1754, 'n_tokens_neox': 1605, 'n_words': 533}