Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[t/spec] tests for writing to array and hash attributes

git-svn-id: http://svn.pugscode.org/pugs@24787 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit 17aba30757899fde70360bb85a44f243adb988c7 1 parent feec0e2
authored January 06, 2009

Showing 1 changed file with 40 additions and 1 deletion. Show diff stats Hide diff stats

  1. 41  S12-attributes/instance.t
41  S12-attributes/instance.t
@@ -2,7 +2,7 @@ use v6;
2 2
 
3 3
 use Test;
4 4
 
5  
-plan 83;
  5
+plan 90;
6 6
 
7 7
 =begin pod
8 8
 
@@ -347,4 +347,43 @@ is eval('Foo9.new.attr'), 42, "default attribute value (3)";
347 347
     is $c.y, 2, '...and copies what we did not change.';
348 348
 }
349 349
 
  350
+# tests for *-1 indexing on classes, RT #61766
  351
+{
  352
+    class ArrayAttribTest {
  353
+        has @.a is rw;
  354
+        method init {
  355
+            @.a = <a b c>;
  356
+        }
  357
+        method m0 { @.a[0] };
  358
+        method m1 { @.a[*-2] };
  359
+        method m2 { @.a[*-1] };
  360
+    }
  361
+    my $o = ArrayAttribTest.new;
  362
+    $o.init;
  363
+    is $o.m0, 'a', '@.a[0] works';
  364
+    #?rakudo 2 skip 'RT #61766'
  365
+    is $o.m1, 'b', '@.a[*-2] works';
  366
+    is $o.m2, 'c', '@.a[*-2] works';
  367
+}
  368
+
  369
+{
  370
+    class AttribWriteTest {
  371
+        has @.a;
  372
+        has %.h; 
  373
+        method set_array {
  374
+            @.a = <c b a>;
  375
+        }
  376
+        method set_hash {
  377
+            %.h = (a => 1, b => 2);
  378
+        }
  379
+    }
  380
+
  381
+    my $x = AttribWriteTest.new; 
  382
+    #?rakudo 4 todo 'assignment to arrays/hashes as attributes'
  383
+    lives_ok { $x.set_array }, 'can assign to array attribute';
  384
+    is $x.a.join('|'), 'c|b|a', '... and the items are there';
  385
+    lives_ok { $x.set_hash },  'can assign to hash attribute';
  386
+    is $x.h.<a b>.join('|'), '1|2', '... and the items are there';
  387
+
  388
+}
350 389
 # vim: ft=perl6

0 notes on commit 17aba30

Please sign in to comment.
Something went wrong with that request. Please try again.