Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 75 lines (57 sloc) 2.342 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
use v6;

use Test;

plan 20;

# TODO: *really* need a better smartlink
# L<S02/Bare identifiers/"If the unrecognized subroutine name">

#?pugs emit if $?PUGS_BACKEND ne "BACKEND_PUGS" {
#?pugs emit skip_rest "PIL2JS and PIL-Run do not support EVAL() yet.";
#?pugs emit exit;
#?pugs emit }

# These tests are for parse-fails:
# (They check that the parser doesn't abort, but they might still parse
# incorrectly.)
{
    sub foo(*@args, *%named) { 1 } #OK not used

    ok EVAL(q/foo; /), 'call with no args, no parens';
    ok EVAL(q/foo(); /), 'call with no args, has parens';
    ok EVAL(q/&foo.(); /), 'call with no args, has dot and parens';
    ok EVAL(q/&foo\ .(); /), 'call with no args, has long dot and parens';

    ok EVAL(q/foo 1; /), 'call with one arg, no parens';
    ok EVAL(q/foo(1); /), 'call with one arg, has parens';
    ok EVAL(q/&foo.(1); /), 'call with one arg, has dot and parens';
    ok EVAL(q/&foo\ .(1);/), 'call with one arg, has long dot and parens';
    #?pugs todo 'unspecced'
    dies_ok { EVAL(q/foo'bar'; /) }, 'call with one arg, has no space and no parens';

    ok EVAL(q/foo 1, 2; /), 'call with two args, no parens';
    ok EVAL(q/foo(1, 2);/), 'call with two args, has parens';

    #?pugs todo
    dies_ok { EVAL(q/foo:bar; /) }, 'call with adverb after no space';
    ok EVAL(q/foo :bar; /), 'call with adverb after space';

    ok EVAL(q/foo(:bar); /), 'call with adverb in parens';
    ok EVAL(q/&foo.(:bar); /), 'call with adverb in dotted-parens';
    ok EVAL(q/&foo\.(:bar);/), 'call with adverb in long-dotted parens';
}


# These tests are for mis-parses:
{
    sub succ($x) { $x + 1 }

    is(EVAL(q/succ (1+2) * 30;/), 91, "parens after space aren't call-parens");
    #?pugs todo
    $_ = sub ($x) { $x - 1 };
    is (succ .(1+2) * 30), 61, 'parsed as method call on $_';
}
{
    sub first() { "first" }

    is(EVAL(q/first.uc/), 'FIRST', '`first.second` means `(first()).second()`');
}

{
    is(EVAL(q/"hello".substr: 1, 2/), "el", "listop method");

    # foo $bar.baz: quux
    # should be (and is currently) interpreted as:
    # foo($bar.baz(quux))
    # where the alternate interpretation can be achieved by:
    # foo ($bar.baz): quux
    # which is interpreted as
    # $bar.baz.foo(quux)
    # but we need tests, tests, tests! XXX
}

# vim: ft=perl6
Something went wrong with that request. Please try again.