Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 134 lines (106 sloc) 6.068 kb
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
1 use v6;
2
3 use Test;
4
b522160 [t/spec] remove a duplicate test and some evals
moritz authored
5 =begin pod
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
6
7 =head1 String interpolation
8
9 These tests derived from comments in L<http://use.perl.org/~autrijus/journal/23398>
10
b522160 [t/spec] remove a duplicate test and some evals
moritz authored
11 =end pod
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
12
6a8904c @usev6 Moved test for RT #76608 to S02-literals/misc-interpolation.t
usev6 authored
13 plan 50;
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
14
15 my $world = "World";
16 my $number = 1;
17 my @list = (1,2);
18 my %hash = (1=>2);
19 sub func { return "func-y town" }
20 sub func_w_args($x,$y) { return "[$x][$y]" }
21
22 # Double quotes
23 is("Hello $world", 'Hello World', 'double quoted string interpolation works');
24 is("@list[]\ 3 4", '1 2 3 4', 'double quoted list interpolation works');
25 is("@list 3 4", '@list 3 4', 'array without empty square brackets does not interpolate');
7becae6 @coke niecza autounfudge
coke authored
26 #?niecza todo 'No value for parameter \$index in postcircumfix:<{ }>'
ecd13f4 @moritz fix and unfudge zen hash slice tests
moritz authored
27 is("%hash{}", "1\t2", 'hash interpolation works');
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
28 is("%hash", '%hash', 'hash interpolation does not work if not followed by {}');
c63cd09 @colomon Fudge for niecza.
colomon authored
29 #?niecza skip 'Action method escape:sym<&> not yet implemented'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
30 is("Wont you take me to &func()", 'Wont you take me to func-y town', 'closure interpolation');
31 is("2 + 2 = { 2+2 }", '2 + 2 = 4', 'double quoted closure interpolation works');
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
moritz authored
32
e2a83ff @dwarring tests for RT #122583 list comprehension + $(...) interpolation
dwarring authored
33
c63cd09 @colomon Fudge for niecza.
colomon authored
34 #?niecza skip 'Action method escape:sym<&> not yet implemented'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
35 is("&func() is where I live", 'func-y town is where I live', "make sure function interpolation doesn't eat all trailing whitespace");
36 is("$number {$number}", '1 1', 'number inside and outside closure works');
37 is("$number {my $number=2}", '1 2', 'local version of number in closure works');
38 is("$number {my $number=2} $number", '1 2 1', 'original number still available after local version in closure: works' );
812a7f5 [t/spec] Lots of unfudging in another interpolation test.
jnthn authored
39
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
moritz authored
40 {
b522160 [t/spec] remove a duplicate test and some evals
moritz authored
41 is "$(my $x = 2) $x", '2 2', 'Variable should interpolate and still be available in the outer scope.';
812a7f5 [t/spec] Lots of unfudging in another interpolation test.
jnthn authored
42 is("$(my $y = 2)" ~ $y, '22', 'Variable should interpolate and still be available in the outer scope.');
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
moritz authored
43 }
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
44
45 # L<S02/Names and Variables/form of each subscript>
46 is("&func. () is where I live", '&func. () is where I live', '"&func. ()" should not interpolate');
e2ce199 @FROGGS RT116166, test for interpolating "$a."
FROGGS authored
47
48 # RT #116166
49 is("$world.", 'World.', '"$world." should not interpolate');
50 is("$world!", 'World!', '"$world!" should not interpolate');
51
c63cd09 @colomon Fudge for niecza.
colomon authored
52 #?niecza skip 'Action method escape:sym<&> not yet implemented'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
53 is("&func_w_args("foo","bar"))", '[foo][bar])', '"&func_w_args(...)" should interpolate');
812a7f5 [t/spec] Lots of unfudging in another interpolation test.
jnthn authored
54
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
55 # L<S02/Method calls/"In order to interpolate the result of a method call">
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
56 is("$world.chars()", '5', 'method calls with parens should interpolate');
57 is("$world.chars", 'World.chars', 'method calls without parens should not interpolate');
ade1f3b [t/spec] differentiate reverse from flip and invert
lwall authored
58 is("$world.flip.chars()", '5', 'cascade of argumentless methods, last ending in paren');
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
59 is("$world.substr(0,1)", 'W', 'method calls with parens and args should interpolate');
60
61 # Single quotes
62 # XXX the next tests will always succeed even if '' interpolation is buggy
63 is('Hello $world', 'Hello $world', 'single quoted string interpolation does not work (which is correct)');
64 is('2 + 2 = { 2+2 }', '2 + 2 = { 2+2 }', 'single quoted closure interpolation does not work (which is correct)');
65 is('$world @list[] %hash{} &func()', '$world @list[] %hash{} &func()', 'single quoted string interpolation does not work (which is correct)');
66
67 # Corner-cases
68 is("Hello $world!", "Hello World!", "! is not a part of var names");
69 sub list_count (*@args) { +@args }
70 is(list_count("@list[]"), 1, 'quoted interpolation gets string context');
4f9bd38 @jnthn Correct a test that was out of line with STD.
jnthn authored
71 is(qq{a{chr 98}c}, 'a{chr 98}c', "curly brace delimiters interfere with closure interpolation");
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
72
73 # Quoting constructs
74 # The next test will always succeed, but if there's a bug it probably
75 # won't compile.
76 is(Q"abc\\d\\'\/", Q"abc\\d\\'\/", "raw quotation works");
77 is(q"abc\\d\"\'\/", Q|abc\d"\'\/|, "single quotation works"); #"
78 is(qq"abc\\d\"\'\/", Q|abc\d"'/|, "double quotation works"); #"
79 is(qa"$world @list[] %hash{}", Q"$world 1 2 %hash{}", "only interpolate array");
80 is(qb"$world \\\"\n\t", "\$world \\\"\n\t", "only interpolate backslash");
81 is('$world \qq[@list[]] %hash{}', '$world 1 2 %hash{}', "interpolate quoting constructs in ''");
82
4e43db6 @Util Standardized "whitespaces" to "whitespace" or "whitespace characters".
Util authored
83 is(" \c[111] \c[107] ", ' o k ', "\\c[] respects whitespace around it");
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
84
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored
85 # L<S02/Radix interpolation/separating the numbers with comma:>
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
86 is("x \x[41,42,43] x", "x ABC x", "\\x[] allows multiple chars (1)");
91600de [t/spec] more warning suppressions
lwall authored
87 is("x \x[41,42,00043] x", "x ABC x", "\\x[] allows multiple chars (2)"); #OK not indicate octal
faa6d5a [t/spec] Test for RT #65004
kyle authored
88 is("x \x[ 41, 42, 43 ] x", "x ABC x", "\\x[] allows multiple chars with white space");
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
89 is("x \c[65,66,67] x", "x ABC x", "\\c[] allows multiple chars (1)");
91600de [t/spec] more warning suppressions
lwall authored
90 is("x \c[65,66,000067] x", "x ABC x", "\\c[] allows multiple chars (2)"); #OK not indicate octal
04185be [t/spec] A test for c[] also
kyle authored
91 is("x \c[ 65, 66, 67 ] x", "x ABC x", "\\c[] allows multiple chars with white space");
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
92
93 is("x \x[41,42,43]] x", "x ABC] x", "\\x[] should not eat following ]s");
94 is("x \c[65,66,67]] x", "x ABC] x", "\\c[] should not eat following ]s");
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
95
cffa7e5 @diakopter fix a couple more smartlinks for S12
diakopter authored
96 # L<S12/Fancy method calls/Within an interpolation, the double-quoted form>
126b5cd [t/spec] test for spec change r27054
moritz authored
97 {
98 class InterpolationTest {
99 method f { 'int' }
100 }
101 my $x = InterpolationTest.new;
102
103 # ORLY, STD.pm parses that as an indirect method call. It will warn,
104 # but strictly speaking it's legal.
91600de [t/spec] more warning suppressions
lwall authored
105 is "|$x.'f'()|", '|int|', #OK use of quotes
126b5cd [t/spec] test for spec change r27054
moritz authored
106 'interpolation of indirect method calls (different quotes)';
91600de [t/spec] more warning suppressions
lwall authored
107 is "|$x."f"()|", '|int|', #OK use of quotes
126b5cd [t/spec] test for spec change r27054
moritz authored
108 'interpolation of indirect method calls (same quotes)';
89c2de2 @lizmat Another batch of (eval_|)dies_ok -> throws_like
lizmat authored
109 throws_like { EVAL q["|$x."f "()"] },
110 X::Syntax::Confused,
4e43db6 @Util Standardized "whitespaces" to "whitespace" or "whitespace characters".
Util authored
111 '... but whitespace is not allowed';
126b5cd [t/spec] test for spec change r27054
moritz authored
112 }
113
c0c67ef @moritz RT #104594, lexicals in blocks in double-quoted strings
moritz authored
114 # RT # 104594
115 # rakudo had some trouble with lexicals from inside interpolated blocks
116 {
117 sub t($p) { t $p-1 if $p-1 > 0; return "{$p}" };
89c2de2 @lizmat Another batch of (eval_|)dies_ok -> throws_like
lizmat authored
118 is t(3), 3, 'variables interpolated into blocks and recursion interact nicely';
c0c67ef @moritz RT #104594, lexicals in blocks in double-quoted strings
moritz authored
119 }
120
e2a83ff @dwarring tests for RT #122583 list comprehension + $(...) interpolation
dwarring authored
121 # L<S04/Loop statements/'Loops at the statementlist level vs the statement level'>
8b6048b @moritz Revert "Remove # chars from fudge messages"
moritz authored
122 #?rakudo.jvm todo 'RT #122583'
e2a83ff @dwarring tests for RT #122583 list comprehension + $(...) interpolation
dwarring authored
123 is "$($_ * $_ if $_ % 2 for 0..10)", '1 9 25 49 81', '$(...) list comprehension';
124 is "{($_ * $_ if $_ % 2 for 0..10)}", '1 9 25 49 81', '{(...)} list comprehension';
125
6a8904c @usev6 Moved test for RT #76608 to S02-literals/misc-interpolation.t
usev6 authored
126 # RT #76608
127 {
128 my $y = "foo$(my $x = 42)bar";
129 ok $x eq 42, "RT #76608 simple assignment";
130 ok $y eq "foo42bar", "RT #76608 variable interpolation inside string";
131 }
132
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
133 # vim: ft=perl6
Something went wrong with that request. Please try again.