Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 122 lines (99 sloc) 5.692 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
c0c67ef @moritz RT #104594, lexicals in blocks in double-quoted strings
moritz authored
13 plan 44;
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 still ...
moritz authored
32
c63cd09 @colomon Fudge for niecza.
colomon authored
33 #?niecza skip 'Action method escape:sym<&> not yet implemented'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
34 is("&func() is where I live", 'func-y town is where I live', "make sure function interpolation doesn't eat all trailing whitespace");
35 is("$number {$number}", '1 1', 'number inside and outside closure works');
36 is("$number {my $number=2}", '1 2', 'local version of number in closure works');
37 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
38
246ed8d @coke pugs fudges
coke authored
39 #?pugs skip '?'
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's still ...
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 still ...
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');
c63cd09 @colomon Fudge for niecza.
colomon authored
47 #?niecza skip 'Action method escape:sym<&> not yet implemented'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
48 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
49
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headings...
diakopter authored
50 # L<S02/Method calls/"In order to interpolate the result of a method call">
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
51 is("$world.chars()", '5', 'method calls with parens should interpolate');
52 is("$world.chars", 'World.chars', 'method calls without parens should not interpolate');
ade1f3b [t/spec] differentiate reverse from flip and invert
lwall authored
53 is("$world.flip.chars()", '5', 'cascade of argumentless methods, last ending in paren');
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
54 is("$world.substr(0,1)", 'W', 'method calls with parens and args should interpolate');
55
56 # Single quotes
57 # XXX the next tests will always succeed even if '' interpolation is buggy
58 is('Hello $world', 'Hello $world', 'single quoted string interpolation does not work (which is correct)');
59 is('2 + 2 = { 2+2 }', '2 + 2 = { 2+2 }', 'single quoted closure interpolation does not work (which is correct)');
60 is('$world @list[] %hash{} &func()', '$world @list[] %hash{} &func()', 'single quoted string interpolation does not work (which is correct)');
61
62 # Corner-cases
63 is("Hello $world!", "Hello World!", "! is not a part of var names");
64 sub list_count (*@args) { +@args }
65 is(list_count("@list[]"), 1, 'quoted interpolation gets string context');
c63cd09 @colomon Fudge for niecza.
colomon authored
66 #?niecza todo 'apparently curly brace delimiters DO interfere with closure interpolation'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
67 is(qq{a{chr 98}c}, 'abc', "curly brace delimiters don't interfere with closure interpolation");
68
69 # Quoting constructs
70 # The next test will always succeed, but if there's a bug it probably
71 # won't compile.
246ed8d @coke pugs fudges
coke authored
72 #?pugs 3 skip 'parsefail'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
73 is(Q"abc\\d\\'\/", Q"abc\\d\\'\/", "raw quotation works");
74 is(q"abc\\d\"\'\/", Q|abc\d"\'\/|, "single quotation works"); #"
75 is(qq"abc\\d\"\'\/", Q|abc\d"'/|, "double quotation works"); #"
734bc95 [t/spec]
moritz authored
76 #?rakudo 3 skip 'qa qb and array/hash interpolation'
246ed8d @coke pugs fudges
coke authored
77 #?pugs skip 'parsefail'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
78 is(qa"$world @list[] %hash{}", Q"$world 1 2 %hash{}", "only interpolate array");
79 is(qb"$world \\\"\n\t", "\$world \\\"\n\t", "only interpolate backslash");
80 is('$world \qq[@list[]] %hash{}', '$world 1 2 %hash{}', "interpolate quoting constructs in ''");
81
82 is(" \c[111] \c[107] ", ' o k ', "\\c[] respects whitespaces around it");
83
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headings...
diakopter authored
84 # L<S02/Radix interpolation/separating the numbers with comma:>
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
85 is("x \x[41,42,43] x", "x ABC x", "\\x[] allows multiple chars (1)");
91600de [t/spec] more warning suppressions
lwall authored
86 is("x \x[41,42,00043] x", "x ABC x", "\\x[] allows multiple chars (2)"); #OK not indicate octal
246ed8d @coke pugs fudges
coke authored
87 #?pugs todo
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
246ed8d @coke pugs fudges
coke authored
91 #?pugs todo
04185be [t/spec] A test for c[] also
kyle authored
92 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
93
94 is("x \x[41,42,43]] x", "x ABC] x", "\\x[] should not eat following ]s");
95 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
96
cffa7e5 @diakopter fix a couple more smartlinks for S12
diakopter authored
97 # L<S12/Fancy method calls/Within an interpolation, the double-quoted form>
246ed8d @coke pugs fudges
coke authored
98 #?pugs skip 'parsefail'
126b5cd [t/spec] test for spec change r27054
moritz authored
99 {
100 class InterpolationTest {
101 method f { 'int' }
102 }
103 my $x = InterpolationTest.new;
104
105 # ORLY, STD.pm parses that as an indirect method call. It will warn,
106 # but strictly speaking it's legal.
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 (different quotes)';
91600de [t/spec] more warning suppressions
lwall authored
109 is "|$x."f"()|", '|int|', #OK use of quotes
126b5cd [t/spec] test for spec change r27054
moritz authored
110 'interpolation of indirect method calls (same quotes)';
111 eval_dies_ok q["|$x."f "()"], '... but whitespaces are not allowed';
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}" };
118 is t(3), 3, 'variables interpoalted into blocks and recursion interact nicely';
119 }
120
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
121 # vim: ft=perl6
Something went wrong with that request. Please try again.