Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (79 sloc) 4.759 kb
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
1 use v6;
2
3 use Test;
4
5 =begin kwid
6
7 =head1 String interpolation
8
9 These tests derived from comments in L<http://use.perl.org/~autrijus/journal/23398>
10
11 =end kwid
12
13 plan 39;
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');
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
24 #?rakudo todo 'array interpolation'
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
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');
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
27 #?rakudo todo 'hash interpolation'
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
28 is("%hash{}", "1\t2\n", 'hash interpolation works');
29 is("%hash", '%hash', 'hash interpolation does not work if not followed by {}');
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
30 #?rakudo todo 'interpolation of &function()'
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
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');
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
33
34 #?rakudo todo 'interpolation of &function()'
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
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' );
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
39 #?rakudo skip 'Null PMC access in get_bool()'
34447c78 »
2008-12-20 [t/spec] fix fudged plan of misc-interpolation.t (required ugly fudge…
40 #?DOES 3
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
41 {
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
42 eval( q[is("$number {my $number=2} {$number}", '1 2 1', 'original number
43 still available in closure after local version in closure: works' );] ) or ok('');
44 eval( q[is("$(my $x = 2) $x", '2 2', 'Variable should interpolate and still be available in the outer scope.');] ) // ok('', 'Syntax should be recognized for $(my $x = 2)');
45 eval( q[is("$(my $x = 2)" ~ $x, '22', 'Variable should interpolate and still be available in the outer scope.');] ) // ok('', 'Syntax should be recognized for $(my $x = 2)');
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
46 }
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
47
48 # L<S02/Names and Variables/form of each subscript>
49 is("&func. () is where I live", '&func. () is where I live', '"&func. ()" should not interpolate');
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
50 #?rakudo skip 'parse failure'
34447c78 »
2008-12-20 [t/spec] fix fudged plan of misc-interpolation.t (required ugly fudge…
51 #?DOES 1
52 {
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
53 is("&func_w_args("foo","bar"))", '[foo][bar])', '"&func_w_args(...)" should interpolate');
34447c78 »
2008-12-20 [t/spec] fix fudged plan of misc-interpolation.t (required ugly fudge…
54 }
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
55 # L<S02/Literals/"In order to interpolate the result of a method call">
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
56 #?rakudo todo 'method interpolation'
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
57 is("$world.chars()", '5', 'method calls with parens should interpolate');
58 is("$world.chars", 'World.chars', 'method calls without parens should not interpolate');
224f29a1 »
2008-12-20 [t/spec] fudge misc-interpolation.t for rakudo - passes, but it's sti…
59 #?rakudo 2 todo 'method interpolation'
ade1f3b9 »
2009-04-11 [t/spec] differentiate reverse from flip and invert
60 is("$world.flip.chars()", '5', 'cascade of argumentless methods, last ending in paren');
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
61 is("$world.substr(0,1)", 'W', 'method calls with parens and args should interpolate');
62
63 # Single quotes
64 # XXX the next tests will always succeed even if '' interpolation is buggy
65 is('Hello $world', 'Hello $world', 'single quoted string interpolation does not work (which is correct)');
66 is('2 + 2 = { 2+2 }', '2 + 2 = { 2+2 }', 'single quoted closure interpolation does not work (which is correct)');
67 is('$world @list[] %hash{} &func()', '$world @list[] %hash{} &func()', 'single quoted string interpolation does not work (which is correct)');
68
69 # Corner-cases
70 is("Hello $world!", "Hello World!", "! is not a part of var names");
71 sub list_count (*@args) { +@args }
72 is(list_count("@list[]"), 1, 'quoted interpolation gets string context');
73 is(qq{a{chr 98}c}, 'abc', "curly brace delimiters don't interfere with closure interpolation");
74
75 # Quoting constructs
76 # The next test will always succeed, but if there's a bug it probably
77 # won't compile.
78 is(Q"abc\\d\\'\/", Q"abc\\d\\'\/", "raw quotation works");
79 is(q"abc\\d\"\'\/", Q|abc\d"\'\/|, "single quotation works"); #"
80 is(qq"abc\\d\"\'\/", Q|abc\d"'/|, "double quotation works"); #"
734bc95b »
2009-03-29 [t/spec]
81 #?rakudo 3 skip 'qa qb and array/hash interpolation'
1e2c5632 »
2008-12-20 [t] move interpolation/strings.t to spec/
82 is(qa"$world @list[] %hash{}", Q"$world 1 2 %hash{}", "only interpolate array");
83 is(qb"$world \\\"\n\t", "\$world \\\"\n\t", "only interpolate backslash");
84 is('$world \qq[@list[]] %hash{}', '$world 1 2 %hash{}', "interpolate quoting constructs in ''");
85
86 is(" \c[111] \c[107] ", ' o k ', "\\c[] respects whitespaces around it");
87
88 # L<S02/Literals/separating the numbers with comma:>
89 is("x \x[41,42,43] x", "x ABC x", "\\x[] allows multiple chars (1)");
90 is("x \x[41,42,00043] x", "x ABC x", "\\x[] allows multiple chars (2)");
91 is("x \c[65,66,67] x", "x ABC x", "\\c[] allows multiple chars (1)");
92 is("x \c[65,66,000067] x", "x ABC x", "\\c[] allows multiple chars (2)");
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");
Something went wrong with that request. Please try again.