Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 125 lines (105 sloc) 2.869 kb
8a5b9bf [t] set some svn attributes
moritz authored
1 use v6;
2
3 use Test;
4
3475a05 @kyleha Test for RT81718
kyleha authored
5 plan 22;
8a5b9bf [t] set some svn attributes
moritz authored
6
6714432 [gsoc_spectest] adding smartlink for tests of $!method syntax
Auzon authored
7 # L<S12/Methods/"For a call on your own private method">
8
8a5b9bf [t] set some svn attributes
moritz authored
9 class Counter {
10 has $!x;
11 method init { $!x = 41 }
12 method get { $!x }
13 method inc { $!x++ }
14 }
15
16 my $c = Counter.new();
17 try {
18 $c.x
19 }
20 ok($!, 'no public accessor for private attribute');
21 $c.init();
22 is($c.get(), 41, 'can assign and get from within the class');
23 $c.inc();
24 is($c.get(), 42, 'can auto-increment an attribute');
25
26
27 class WithAlias {
28 has $x;
29 method set($a) { $x = $a }
30 method get { $!x }
31 }
32
33 my $wa = WithAlias.new();
34 $wa.set(99);
35 is($wa.get, 99, 'has with no twigil creates alias');
9e51a69 [rakudo] Some extra tests for attributes, where you declare many at o…
jnthn authored
36
37
38 class ManyTest {
39 has ($a, $b);
40 has ($.c, $.d);
41 has ($!e, $!f);
42 method t1 {
43 $a + $b
44 }
45 method t2 {
46 $!a + $!b
47 }
48 method t3 {
49 $!e + $!f
50 }
51 }
52
53 my $m = ManyTest.new(a => 1, b => 2, c => 3, d => 4, e => 5, f => 6);
54 is($m.c, 3, 'list attribute declaration of publics works');
55 is($m.d, 4, 'list attribute declaration of publics works');
56 is($m.t1, 3, 'list attribute declaration of alias works');
57 is($m.t2, 3, 'list attribute declaration of alias works');
58 is($m.t3, 11, 'list attribute declaration of privates works');
392e484 [spectest] Some tests for array and hash attributes.
jnthn authored
59
60
61 class Foo {
62 has %.bar is rw;
63 method set_bar {
64 %.bar<a> = 'baz';
65 }
66 }
67 my $foo = Foo.new;
2a9e6b8 [t/spec] Fudge out test with weird indeterminate results.
colomon authored
68 #?rakudo todo "Somehow this is Hash and not Hash at the same time?"
69 isa_ok($foo.bar, Hash, 'hash attribute initialized');
392e484 [spectest] Some tests for array and hash attributes.
jnthn authored
70 $foo.set_bar();
71 is($foo.bar<a>, 'baz', 'hash attribute initialized/works');
72 my %s = $foo.bar;
73 is(%s<a>, 'baz', 'hash attribute initialized/works');
74 $foo.bar<b> = 'wob';
75 is($foo.bar<b>, 'wob', 'hash attribute initialized/works');
76
77 class Bar {
78 has @.bar is rw;
79 method set_bar {
80 @.bar[0] = 100;
81 @.bar[1] = 200;
82 }
83 }
84 my $bar = Bar.new;
82d9c01 [t/spec]: Use isa_ok instead of WHAT to test types.
pmichaud authored
85 isa_ok($bar.bar.WHAT, Array, 'array attribute initialized');
392e484 [spectest] Some tests for array and hash attributes.
jnthn authored
86 $bar.set_bar();
87 is($bar.bar[0], 100, 'array attribute initialized/works');
88 is($bar.bar[1], 200, 'array attribute initialized/works');
89 my @t = $bar.bar;
90 is(@t[0], 100, 'array attribute initialized/works');
91 is(@t[1], 200, 'array attribute initialized/works');
92 $bar.bar[2] = 300;
93 is($bar.bar[2], 300, 'array attribute initialized/works');
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
94
7a5e74d [t/spec] tests for RT #73808 Providing a list of attributes to a sing…
bbkr authored
95 # RT #73808
96 {
97 class RT73808 {
98 has ($!a, $!b);
99 method foo {
100 $!a = 1;
101 $!b = 3;
102 return $!a + $!b;
103 }
104 }
105 is RT73808.new.foo, 4,
106 'Providing a list of attributes to a single "has" works';
107 }
108
3475a05 @kyleha Test for RT81718
kyleha authored
109 # RT 81718
110 {
111 class RT81718 {
112 has $.bughunt is rw;
113 sub bomb { "life is a $.bughunt" }
114 method meta_bomb { "the good " ~ bomb() }
115 }
116
117 my $rt81718 = RT81718.new();
118
119 dies_ok { $rt81718.bomb() }, 'no attribute access for sub';
a632eba @moritz Revert "unfudge test for RT #81718"
moritz authored
120 #?rakudo todo 'RT81718'
3475a05 @kyleha Test for RT81718
kyleha authored
121 dies_ok { $rt81718.meta_bomb() }, 'no attr access for sub from method';
122 }
123
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored
124 # vim: ft=perl6
Something went wrong with that request. Please try again.