Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 114 lines (94 sloc) 5.26 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
126b5cd [t/spec] test for spec change r27054
moritz authored
13 plan 43;
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');
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's still ...
moritz authored
24 #?rakudo todo 'array interpolation'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
25 is("@list[]\ 3 4", '1 2 3 4', 'double quoted list interpolation works');
26 is("@list 3 4", '@list 3 4', 'array without empty square brackets does not interpolate');
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's still ...
moritz authored
27 #?rakudo todo 'hash interpolation'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
28 is("%hash{}", "1\t2\n", 'hash interpolation works');
29 is("%hash", '%hash', 'hash interpolation does not work if not followed by {}');
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's still ...
moritz authored
30 #?rakudo todo 'interpolation of &function()'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
31 is("Wont you take me to &func()", 'Wont you take me to func-y town', 'closure interpolation');
32 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
33
34 #?rakudo todo 'interpolation of &function()'
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' );
b522160 [t/spec] remove a duplicate test and some evals
moritz authored
39 #?rakudo skip 'interpolatin of $(my $x = 2)'
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.';
42 is("$(my $x = 2)" ~ $x, '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');
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's still ...
moritz authored
47 #?rakudo skip 'parse failure'
34447c7 [t/spec] fix fudged plan of misc-interpolation.t (required ugly fudge ha...
moritz authored
48 #?DOES 1
49 {
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
50 is("&func_w_args("foo","bar"))", '[foo][bar])', '"&func_w_args(...)" should interpolate');
34447c7 [t/spec] fix fudged plan of misc-interpolation.t (required ugly fudge ha...
moritz authored
51 }
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
52 # L<S02/Literals/"In order to interpolate the result of a method call">
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's still ...
moritz authored
53 #?rakudo todo 'method interpolation'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
54 is("$world.chars()", '5', 'method calls with parens should interpolate');
55 is("$world.chars", 'World.chars', 'method calls without parens should not interpolate');
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's still ...
moritz authored
56 #?rakudo 2 todo 'method interpolation'
ade1f3b [t/spec] differentiate reverse from flip and invert
lwall authored
57 is("$world.flip.chars()", '5', 'cascade of argumentless methods, last ending in paren');
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
58 is("$world.substr(0,1)", 'W', 'method calls with parens and args should interpolate');
59
60 # Single quotes
61 # XXX the next tests will always succeed even if '' interpolation is buggy
62 is('Hello $world', 'Hello $world', 'single quoted string interpolation does not work (which is correct)');
63 is('2 + 2 = { 2+2 }', '2 + 2 = { 2+2 }', 'single quoted closure interpolation does not work (which is correct)');
64 is('$world @list[] %hash{} &func()', '$world @list[] %hash{} &func()', 'single quoted string interpolation does not work (which is correct)');
65
66 # Corner-cases
67 is("Hello $world!", "Hello World!", "! is not a part of var names");
68 sub list_count (*@args) { +@args }
69 is(list_count("@list[]"), 1, 'quoted interpolation gets string context');
70 is(qq{a{chr 98}c}, 'abc', "curly brace delimiters don't interfere with closure interpolation");
71
72 # Quoting constructs
73 # The next test will always succeed, but if there's a bug it probably
74 # won't compile.
75 is(Q"abc\\d\\'\/", Q"abc\\d\\'\/", "raw quotation works");
76 is(q"abc\\d\"\'\/", Q|abc\d"\'\/|, "single quotation works"); #"
77 is(qq"abc\\d\"\'\/", Q|abc\d"'/|, "double quotation works"); #"
734bc95 [t/spec]
moritz authored
78 #?rakudo 3 skip 'qa qb and array/hash interpolation'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored
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
83 is(" \c[111] \c[107] ", ' o k ', "\\c[] respects whitespaces around it");
84
85 # L<S02/Literals/separating the numbers with comma:>
86 is("x \x[41,42,43] x", "x ABC x", "\\x[] allows multiple chars (1)");
87 is("x \x[41,42,00043] x", "x ABC x", "\\x[] allows multiple chars (2)");
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)");
90 is("x \c[65,66,000067] x", "x ABC x", "\\c[] allows multiple chars (2)");
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
126b5cd [t/spec] test for spec change r27054
moritz authored
96 # L<S12/Methods/Within an interpolation, the double-quoted form>
97 #?rakudo skip 'interpolation of indirect method calls'
98 {
99 class InterpolationTest {
100 method f { 'int' }
101 }
102 my $x = InterpolationTest.new;
103
104 # ORLY, STD.pm parses that as an indirect method call. It will warn,
105 # but strictly speaking it's legal.
106 is "|$x.'f'()|", '|int|',
107 'interpolation of indirect method calls (different quotes)';
108 is "|$x."f"()|", '|int|',
109 'interpolation of indirect method calls (same quotes)';
110 eval_dies_ok q["|$x."f "()"], '... but whitespaces are not allowed';
111 }
112
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
113 # vim: ft=perl6
Something went wrong with that request. Please try again.