Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Another batch of (eval_|)dies_ok -> throws_like
  • Loading branch information
lizmat committed Aug 17, 2014
1 parent 1d0923d commit e657f36
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 87 deletions.
45 changes: 30 additions & 15 deletions S02-lexical-conventions/comments.t
Expand Up @@ -64,10 +64,18 @@ plan 51;
#?niecza skip 'Opening bracket is required for #` comment'
{

eval_dies_ok "3 * #` (invalid comment) 2", "no space allowed between '#`' and '('";
eval_dies_ok "3 * #`\t[invalid comment] 2", "no tab allowed between '#`' and '['";
eval_dies_ok "3 * #` \{invalid comment\} 2", "no spaces allowed between '#`' and '\{'";
eval_dies_ok "3 * #`\n<invalid comment> 2", "no spaces allowed between '#`' and '<'";
throws_like { EVAL "3 * #` (invalid comment) 2" },
X::Comp::AdHoc, # no exception type yet
"no space allowed between '#`' and '('";
throws_like { EVAL "3 * #`\t[invalid comment] 2" },
X::Comp::AdHoc, # no exception type yet
"no tab allowed between '#`' and '['";
throws_like { EVAL "3 * #` \{invalid comment\} 2" },
X::Comp::AdHoc, # no exception type yet
"no spaces allowed between '#`' and '\{'";
throws_like { EVAL "3 * #`\n<invalid comment> 2" },
X::Syntax::Confused,
"no spaces allowed between '#`' and '<'";

}

Expand Down Expand Up @@ -149,30 +157,37 @@ plan 51;
# L<S02/Comments in Unspaces and vice versa/"comment may not contain an unspace">
#?niecza skip 'Excess arguments to CORE eval'
{
eval_dies_ok '$a = #`\ (comment) 32', "comments can't contain unspace";
dies_ok { EVAL '$a = #`\ (comment) 32' },
"comments can't contain unspace";
}

# L<S02/Single-line Comments/"# may not be used as"
# delimiter quoting>
{
my $a;
lives_ok { EVAL('$a = q{ 32 }') }, 'sanity check';
lives_ok { EVAL '$a = q{ 32 }' }, 'sanity check';
is $a, ' 32 ', 'sanity check';
}

$a = Nil;
eval_dies_ok '$a = q# 32 #;', 'misuse of # as quote delimiters';
#?rakudo todo 'NYI'
{
my $a = Nil;
throws_like { EVAL '$a = q# 32 #;' },
X::Comp::AdHoc,
'misuse of # as quote delimiters';
ok !$a.defined, "``#'' can't be used as quote delimiters";
}

# L<S02/Single-line Comments/"single-line comments">
#?niecza todo
{
# RT #70752
eval_lives_ok "#=======\n#=======\nuse v6;", "pragma use after single line comments";
lives_ok { EVAL "#=======\n#=======\nuse v6;" },
"pragma use after single line comments";
}

# L<S02/Multiline Comments/POD sections may be>
eval_lives_ok( q{{
lives_ok { EVAL q{{
my $outerVal = EVAL(
q{my $var = 1;
Expand All @@ -188,11 +203,11 @@ a "=cut".
);
is $outerVal, "bar", '=begin comment without =cut parses to whitespace in code';
}}, '=begin comment without =cut eval throws no error' );
}} }, '=begin comment without =cut eval throws no error';


# L<S02/Multiline Comments/"single paragraph comments">
eval_lives_ok( q{{
lives_ok { EVAL q{{
my $outerVal = EVAL(
q{10 +
Expand All @@ -203,10 +218,10 @@ my $outerVal = EVAL(
);
is $outerVal, 11, 'Single paragraph Pod parses to whitespace in code';
}}, 'Single paragraph Pod eval throws no error' );
}} }, 'Single paragraph Pod eval throws no error';

#?niecza todo
eval_lives_ok( q{{
lives_ok { EVAL q{{
my $outerVal = EVAL(
q{20 +
Expand All @@ -218,6 +233,6 @@ are both here, yay!
);
is $outerVal, 22, 'Single paragraph Pod, multiple lines parses to whitespace in code';
}}, 'Single paragraph Pod, multiple lines eval throws no error' );
}} }, 'Single paragraph Pod, multiple lines eval throws no error';

# vim: ft=perl6
42 changes: 27 additions & 15 deletions S02-lexical-conventions/minimal-whitespace.t
Expand Up @@ -7,26 +7,38 @@ plan 9;
# L<S03/Minimal whitespace DWIMmery/Whitespace is no longer allowed before>

my @arr = <1 2 3 4 5>;
eval_dies_ok('@arr [0]', 'array with space before opening brackets does not work');
throws_like { EVAL '@arr [0]' },
X::Syntax::Confused,
'array with space before opening brackets does not work';

my %hash = a => 1, b => 2;
eval_dies_ok('%hash <a>', 'hash with space before opening brackets does not work (1)');
eval_dies_ok('%hash {"a"}', 'hash with space before opening braces does not work (2)');

# XXX this one is wrong, it's parsed as code( (5) )
# STD.pm agrees on that.
#sub code (Int $a) {2 * $a}
#eval_dies_ok('code (5)', 'sub call with space before opening parens does not work');
throws_like { EVAL '%hash <a>' },
X::Comp::AdHoc, # no exception type yet
'hash with space before opening brackets does not work (1)';
throws_like { EVAL '%hash {"a"}' },
X::Comp::AdHoc, # no exception type yet
'hash with space before opening braces does not work (2)';

class Thing {method whatever (Int $a) {3 * $a}}
eval_dies_ok('Thing .new', 'whitespace is not allowed before . after class name');
eval_dies_ok('Thing. new', 'whitespace is not allowed after . after class name');
throws_like { EVAL 'Thing .new' },
X::Syntax::Confused,
'whitespace is not allowed before . after class name';
throws_like { EVAL 'Thing. new' },
X::Obsolete,
'whitespace is not allowed after . after class name';

my $o = Thing.new;
eval_dies_ok('$o .whatever(5)', 'whitespace is not allowed before . before method');
eval_dies_ok('$o. whatever(5)', 'whitespace is not allowed after . before method');

eval_lives_ok 'my @rt80330; [+] @rt80330', 'a [+] with whitespace works';
eval_dies_ok 'my @rt80330; [+]@rt80330', 'a [+] without whitespace dies';
throws_like { EVAL '$o .whatever(5)' },
X::Syntax::Confused,
'whitespace is not allowed before . before method';
throws_like { EVAL '$o. whatever(5)' },
X::Obsolete,
'whitespace is not allowed after . before method';

lives_ok { EVAL 'my @rt80330; [+] @rt80330' },
'a [+] with whitespace works';
throws_like { EVAL 'my @rt80330; [+]@rt80330' },
X::Syntax::Confused,
'a [+] without whitespace dies';

# vim: ft=perl6
11 changes: 7 additions & 4 deletions S02-lexical-conventions/one-pass-parsing.t
Expand Up @@ -5,13 +5,16 @@ plan 3;

# L<S02/"One-pass parsing">

ok(EVAL('regex { <[ } > ]> }; 1'),
"can parse non-backslashed curly and right bracket in cclass");
lives_ok { EVAL 'regex { <[ } > ]> }; 1' },
"can parse non-backslashed curly and right bracket in cclass";

# RT #74988
{
eval_lives_ok 'sub if() { "#foo" }; say if();', "Can call sub if()";
eval_dies_ok 'sub if() { "#foo" }; say if;', "Calling sub if without parens parsefails";
lives_ok { EVAL 'sub if() { "#foo" }; say if();' },
"Can call sub if()";
throws_like { EVAL 'sub if() { "#foo" }; say if;' },
X::Syntax::Confused,
"Calling sub if without parens parsefails";
}

# vim: ft=perl6
18 changes: 11 additions & 7 deletions S02-lexical-conventions/sub-block-parsing.t
Expand Up @@ -19,19 +19,25 @@ ok(sub { 42 }(), 'sub {...}() works'); # TODO: clarify
ok(sub{ 42 }(), 'sub{...}() works'); # TODO: clarify

#RT #76432
eval_dies_ok q[
throws_like { EVAL q[
sub x { die }
x();
], 'block parsing works with newline';
] },
X::AdHoc, # no exception object yet
'block parsing works with newline';

eval_dies_ok q[
throws_like { EVAL q[
sub x { die };
x();
], 'block parsing works with semicolon';
] },
X::AdHoc, # no exception object yet
'block parsing works with semicolon';

# RT #85844
{
eval_dies_ok 'sub foo;', 'RT #85844'
throws_like { EVAL 'sub foo;' },
X::Syntax::Missing,
'RT #85844';
}

# RT #76896:
Expand Down Expand Up @@ -67,6 +73,4 @@ eval_dies_ok q[
is to_check_after('B'), "fb called.", 'fb called in sub/hash syntax is ok';
}

done;

# vim: ft=perl6
43 changes: 29 additions & 14 deletions S02-lexical-conventions/unicode.t
Expand Up @@ -108,24 +108,39 @@ is((do { my $दूसरा = 2; sub टोटल ($x) { $x + 2 }; टोटल
# L<S02/Unicode Semantics/Perl can count Unicode line and paragraph separators>
eval_lives_ok "\{ 1 \} \x0a \{ 1 \}", "Unicode 000A (LINE FEED (LF)) can terminate lines";
lives_ok { EVAL "\{ 1 \} \x0a \{ 1 \}" },
"Unicode 000A (LINE FEED (LF)) can terminate lines";
lives_ok { EVAL "\{ 1 \} \x0c \{ 1 \}" },
"Unicode 000C (FORM FEED (FF)) can terminate lines";
lives_ok { EVAL "\{ 1 \} \x0d \{ 1 \}" },
"Unicode 000D (CARRIAGE RETURN (CR)) can terminate lines";
lives_ok { EVAL "\{ 1 \} \x85 \{ 1 \}" },
"Unicode 0085 (NEXT LINE (NEL)) can terminate lines";
#?rakudo.parrot skip 'RT #122341 all codepoints that match \v should work as line separator'
eval_lives_ok "\{ 1 \} \x0b \{ 1 \}", "Unicode 000B (LINE TABULATION) can terminate lines";
eval_lives_ok "\{ 1 \} \x0c \{ 1 \}", "Unicode 000C (FORM FEED (FF)) can terminate lines";
eval_lives_ok "\{ 1 \} \x0d \{ 1 \}", "Unicode 000D (CARRIAGE RETURN (CR)) can terminate lines";
eval_lives_ok "\{ 1 \} \x85 \{ 1 \}", "Unicode 0085 (NEXT LINE (NEL)) can terminate lines";
#?rakudo.parrot 2 skip 'RT #122341 all codepoints that match \v should work as line separator'
eval_lives_ok "\{ 1 \} \x2028 \{ 1 \}", "Unicode 2028 (LINE SEPARATOR) can terminate lines";
eval_lives_ok "\{ 1 \} \x2029 \{ 1 \}", "Unicode 2029 (PARAGRAPH SEPARATOR) can terminate lines";
{
lives_ok { EVAL "\{ 1 \} \x0b \{ 1 \}" },
"Unicode 000B (LINE TABULATION) can terminate lines";
lives_ok { EVAL "\{ 1 \} \x2028 \{ 1 \}" },
"Unicode 2028 (LINE SEPARATOR) can terminate lines";
lives_ok { EVAL "\{ 1 \} \x2029 \{ 1 \}" },
"Unicode 2029 (PARAGRAPH SEPARATOR) can terminate lines";
}
# L<S02/Bracketing Characters/If a character is already used>
eval_lives_ok "q\x298d test \x298e", "Unicode open-298d maps to close-298e";
eval_lives_ok "q\x301d test \x301e", "Unicode open-301d maps to close-301e";
eval_dies_ok "q\x301d test \x301f", "Unicode open-301d does not map to close-301f";
eval_lives_ok "q\x2018 test \x2019", "Unicode open-2018 maps to to close-2019";
eval_lives_ok "q\x201a test \x2019", "Unicode open-201a maps to to close-2019";
eval_lives_ok "q\x2018 \x201a test \x2019", "Alternative open-brakets treat their other alternates as non-special";
lives_ok { EVAL "q\x298d test \x298e" },
"Unicode open-298d maps to close-298e";
lives_ok { EVAL "q\x301d test \x301e" },
"Unicode open-301d maps to close-301e";
dies_ok { EVAL "q\x301d test \x301f" },
"Unicode open-301d does not map to close-301f";
lives_ok { EVAL "q\x2018 test \x2019" },
"Unicode open-2018 maps to to close-2019";
lives_ok { EVAL "q\x201a test \x2019" },
"Unicode open-201a maps to to close-2019";
lives_ok { EVAL "q\x2018 \x201a test \x2019" },
"Alternative open-brakets treat their other alternates as non-special";
# vim: ft=perl6 fileencoding=utf-8
37 changes: 28 additions & 9 deletions S02-lexical-conventions/unspace.t
Expand Up @@ -71,10 +71,15 @@ is((foo\.lc ), 'a', 'short unspace');
is((foo\ .lc ), 'a', 'unspace');
is((foo\ ('x')), 'x', "unspace before arguments");
is((foo \ .lc), 'b', 'not a unspace');
eval_dies_ok('fo\ o.lc', 'unspace not allowed in identifier');
throws_like { EVAL 'fo\ o.lc' },
X::Syntax::Confused,
'unspace not allowed in identifier';
is((foo\ .lc), 'a', 'longer dot');
is((foo\#`( comment ).lc), 'a', 'unspace with embedded comment');
eval_dies_ok('foo\#\ ( comment ).lc', 'unspace can\'t hide space between # and opening bracket');
#?rakudo todo 'NYI'
throws_like { EVAL 'foo\#\ ( comment ).lc' },
X::AdHoc,
'unspace can\'t hide space between # and opening bracket';
is((foo\ # comment
.lc), 'a', 'unspace with end-of-line comment');
is((:foo\ <bar>), (:foo<bar>), 'unspace in colonpair');
Expand Down Expand Up @@ -187,7 +192,9 @@ end comment #5
# L<S04/"Statement-ending blocks"/"Because subroutine declarations are expressions">
#XXX probably shouldn't be in this file...

eval_dies_ok('sub f { 3 } sub g { 3 }', 'semicolon or newline required between blocks');
throws_like { EVAL 'sub f { 3 } sub g { 3 }' },
X::Syntax::Confused,
'semicolon or newline required between blocks';

# L<S06/"Blocks"/"unless followed immediately by a comma">
#
Expand Down Expand Up @@ -224,7 +231,9 @@ eval_dies_ok('sub f { 3 } sub g { 3 }', 'semicolon or newline required between b
sub infix:<++>($x, $y) { 42 } #OK not used

#'$n++$m' should be a syntax error
eval_dies_ok('$n++$m', 'infix requires space when ambiguous with postfix');
throws_like { EVAL '$n++$m' },
X::Syntax::Confused,
'infix requires space when ambiguous with postfix';
is($n, 1, 'check $n');
is($m, 2, 'check $m');

Expand All @@ -243,9 +252,15 @@ eval_dies_ok('sub f { 3 } sub g { 3 }', 'semicolon or newline required between b

#These should all be postfix syntax errors
$n = 1; $m = 2;
eval_dies_ok('$n.++ $m', 'postfix dot w/ infix ambiguity');
eval_dies_ok('$n\ ++ $m', 'postfix unspace w/ infix ambiguity');
eval_dies_ok('$n\ .++ $m', 'postfix unspace w/ infix ambiguity');
throws_like { EVAL '$n.++ $m' },
X::Syntax::Confused,
'postfix dot w/ infix ambiguity';
throws_like { EVAL '$n\ ++ $m' },
X::Comp,
'postfix unspace w/ infix ambiguity';
throws_like { EVAL '$n\ .++ $m' },
X::Comp,
'postfix unspace w/ infix ambiguity';
is($n, 1, 'check $n');
is($m, 2, 'check $m');

Expand All @@ -256,7 +271,9 @@ eval_dies_ok('sub f { 3 } sub g { 3 }', 'semicolon or newline required between b
is($m, 2, 'check $m');

$n = 1;
eval_dies_ok('$n ++', 'postfix requires no space');
throws_like { EVAL '$n ++' },
X::Comp::AdHoc,
'postfix requires no space';
is($n, 1, 'check $n');

$n = 1;
Expand All @@ -274,7 +291,9 @@ eval_dies_ok('sub f { 3 } sub g { 3 }', 'semicolon or newline required between b
# L<S02/"Bracketing Characters"/"U+301D codepoint has two closing alternatives">
#?niecza skip 'Unable to resolve method id in class Str'
is((foo\#`〝 comment 〞.lc), 'a', 'unspace with U+301D/U+301E comment');
eval_dies_ok('foo\#`〝 comment 〟.id', 'unspace with U+301D/U+301F is invalid');
throws_like { EVAL 'foo\#`〝 comment 〟.id' },
X::Comp::AdHoc,
'unspace with U+301D/U+301F is invalid';

# L<S02/"Implicit Topical Method Calls"/".123">
# .123 is equal to 0.123
Expand Down
4 changes: 3 additions & 1 deletion S02-literals/adverbs.t
Expand Up @@ -21,7 +21,9 @@ plan 15;
is_deeply (:%a), (a => %a), ":%a works";
is_deeply (:&a), (a => &a), ":&a works";
is_deeply (:42nd), (nd => 42), "Basic numeric adverb works";
eval_dies_ok ':69th($_)', "Numeric adverb can't have an extra value";
throws_like { EVAL ':69th($_)' },
X::Comp::AdHoc,
"Numeric adverb can't have an extra value";

is (:a{ 42 + 24 })<a>(), 66, "Adverb with postfix:<{ }> makes code object";
} # 13
Expand Down

0 comments on commit e657f36

Please sign in to comment.