Skip to content
Newer
Older
100644 120 lines (97 sloc) 5.72 KB
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
1 use v6;
2
3 use Test;
4
b522160 [t/spec] remove a duplicate test and some evals
moritz authored Aug 8, 2009
5 =begin pod
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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 Aug 8, 2009
11 =end pod
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
12
c0c67ef @moritz RT #104594, lexicals in blocks in double-quoted strings
moritz authored Jan 30, 2012
13 plan 44;
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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');
c63cd09 @colomon Fudge for niecza.
colomon authored Dec 31, 2011
24 #?niecza skip 'No value for parameter \$index in postcircumfix:<[ ]>'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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');
c63cd09 @colomon Fudge for niecza.
colomon authored Dec 31, 2011
27 #?niecza skip 'No value for parameter \$index in postcircumfix:<{ }>'
ecd13f4 @moritz fix and unfudge zen hash slice tests
moritz authored Feb 11, 2012
28 is("%hash{}", "1\t2", 'hash interpolation works');
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
29 is("%hash", '%hash', 'hash interpolation does not work if not followed by {}');
c63cd09 @colomon Fudge for niecza.
colomon authored Dec 31, 2011
30 #?niecza skip 'Action method escape:sym<&> not yet implemented'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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 sti…
moritz authored Dec 20, 2008
33
c63cd09 @colomon Fudge for niecza.
colomon authored Dec 31, 2011
34 #?niecza skip 'Action method escape:sym<&> not yet implemented'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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 Apr 4, 2010
39
224f29a [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
moritz authored Dec 20, 2008
40 {
b522160 [t/spec] remove a duplicate test and some evals
moritz authored Aug 8, 2009
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 Apr 4, 2010
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 Dec 20, 2008
43 }
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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 Dec 31, 2011
47 #?niecza skip 'Action method escape:sym<&> not yet implemented'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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 Apr 4, 2010
49
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored Aug 23, 2011
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 Dec 20, 2008
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 Apr 11, 2009
53 is("$world.flip.chars()", '5', 'cascade of argumentless methods, last ending in paren');
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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 }
c63cd09 @colomon Fudge for niecza.
colomon authored Dec 31, 2011
65 #?niecza skip 'No value for parameter \$index in postcircumfix:<[ ]>'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
66 is(list_count("@list[]"), 1, 'quoted interpolation gets string context');
c63cd09 @colomon Fudge for niecza.
colomon authored Dec 31, 2011
67 #?niecza todo 'apparently curly brace delimiters DO interfere with closure interpolation'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
68 is(qq{a{chr 98}c}, 'abc', "curly brace delimiters don't interfere with closure interpolation");
69
70 # Quoting constructs
71 # The next test will always succeed, but if there's a bug it probably
72 # won't compile.
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 Mar 29, 2009
76 #?rakudo 3 skip 'qa qb and array/hash interpolation'
c63cd09 @colomon Fudge for niecza.
colomon authored Dec 31, 2011
77 #?niecza skip 'No value for parameter \$index in postcircumfix:<[ ]>'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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");
c63cd09 @colomon Fudge for niecza.
colomon authored Dec 31, 2011
80 #?niecza skip 'No value for parameter \$index in postcircumfix:<[ ]>'
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
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
75bf7cb @diakopter fix all the remaining S02/Literals smartlinks I broke by adding headi…
diakopter authored Aug 23, 2011
85 # L<S02/Radix interpolation/separating the numbers with comma:>
1e2c563 [t] move interpolation/strings.t to spec/
moritz authored Dec 20, 2008
86 is("x \x[41,42,43] x", "x ABC x", "\\x[] allows multiple chars (1)");
91600de [t/spec] more warning suppressions
lwall authored Jul 15, 2010
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 Aug 13, 2009
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 Dec 20, 2008
89 is("x \c[65,66,67] x", "x ABC x", "\\c[] allows multiple chars (1)");
91600de [t/spec] more warning suppressions
lwall authored Jul 15, 2010
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 Aug 13, 2009
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 Dec 20, 2008
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 Aug 8, 2009
95
cffa7e5 @diakopter fix a couple more smartlinks for S12
diakopter authored Aug 11, 2011
96 # L<S12/Fancy method calls/Within an interpolation, the double-quoted form>
126b5cd [t/spec] test for spec change r27054
moritz authored Aug 23, 2009
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 Jul 15, 2010
105 is "|$x.'f'()|", '|int|', #OK use of quotes
126b5cd [t/spec] test for spec change r27054
moritz authored Aug 23, 2009
106 'interpolation of indirect method calls (different quotes)';
91600de [t/spec] more warning suppressions
lwall authored Jul 15, 2010
107 is "|$x."f"()|", '|int|', #OK use of quotes
126b5cd [t/spec] test for spec change r27054
moritz authored Aug 23, 2009
108 'interpolation of indirect method calls (same quotes)';
109 eval_dies_ok q["|$x."f "()"], '... but whitespaces are not allowed';
110 }
111
c0c67ef @moritz RT #104594, lexicals in blocks in double-quoted strings
moritz authored Jan 30, 2012
112 # RT # 104594
113 # rakudo had some trouble with lexicals from inside interpolated blocks
114 {
115 sub t($p) { t $p-1 if $p-1 > 0; return "{$p}" };
116 is t(3), 3, 'variables interpoalted into blocks and recursion interact nicely';
117 }
118
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored Aug 8, 2009
119 # vim: ft=perl6
Something went wrong with that request. Please try again.