Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 75 lines (56 sloc) 2.266 kB
297e783 [t] and [t/spec]
moritz authored
1 use v6;
2
3 use Test;
4
5 # Tests for the Proxy class
6
7 # L<S06/Lvalue subroutines/"or a specially tied proxy object, with suitably">
8 # Return value of assignments of Proxy objects is decided now.
9 # See thread "Assigning Proxy objects" on p6l,
10 # L<"http://www.nntp.perl.org/group/perl.perl6.language/21838">.
11 # Quoting Larry:
12 # The intention is that lvalue subs behave in all respects as if they
13 # were variables.  So consider what
14 #
15 # say $nonproxy = 40;
16 #
17 # should do.
18
19 plan 18;
20
21 my $foo = 42;
22 my $was_inside = 0;
23
24 sub lvalue_test1() is rw {
25 $was_inside++;
7748996 @moritz fix Proxy tests to not use indirect method syntax, and use methods as…
moritz authored
26 return Proxy.new:
27 FETCH => method () { 100 + $foo },
28 STORE => method ($new) { $foo = $new - 100 };
297e783 [t] and [t/spec]
moritz authored
29 };
30
31 {
32 is $foo, 42, "basic sanity (1)";
33 is $was_inside, 0, "basic sanity (2)";
34
35 is lvalue_test1(), 142, "getting var through Proxy (1)";
36 # No todo_is here to avoid unexpected succeeds (? - elaborate?)
37 is $was_inside, 1, "lvalue_test1() was called (1)";
38
39 is (lvalue_test1() = 123), 123, "setting var through Proxy";
40 is $was_inside, 2, "lvalue_test1() was called (2)";
41 is $foo, 23, "var was correctly set (1)";
42
43 is lvalue_test1(), 123, "getting var through Proxy (2)";
44 is $was_inside, 3, "lvalue_test1() was called (3)";
45 }
46
47 $foo = 4;
48 $was_inside = 0;
49
50 sub lvalue_test2() is rw {
51 $was_inside++;
7748996 @moritz fix Proxy tests to not use indirect method syntax, and use methods as…
moritz authored
52 return Proxy.new:
53 FETCH => method () { 10 + $foo },
54 STORE => method ($new) { $foo = $new - 100 };
297e783 [t] and [t/spec]
moritz authored
55 };
56
57 {
58 is $foo, 4, "basic sanity (3)";
59 is $was_inside, 0, "basic sanity (4)";
60
61
62 is lvalue_test2(), 14, "getting var through Proxy (4)";
63 # No todo_is here to avoid unexpected succeeds
64 is $was_inside, 1, "lvalue_test2() was called (4)";
65
7748996 @moritz fix Proxy tests to not use indirect method syntax, and use methods as…
moritz authored
66 is (lvalue_test2() = 106), 16, "setting var through Proxy returns new value of the var";
297e783 [t] and [t/spec]
moritz authored
67 is $was_inside, 2, "lvalue_test2() was called (5)";
68 is $foo, 6, "var was correctly set (2)";
69
70 is lvalue_test2(), 16, "getting var through Proxy (5)";
71 is $was_inside, 3, "lvalue_test2() was called (5)";
72 }
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
73
74 # vim: ft=perl6
Something went wrong with that request. Please try again.