Changeset 6658

Show
Ignore:
Timestamp:
09/02/05 16:11:15 (3 years ago)
Author:
iblech
Message:

* pugs::hack: Extremely minor cosmetic fixes.
* t/statements/for_with_only_one_item.t: Expanded tests based on p6l feedback,

Juerd++, see http://www.nntp.perl.org/group/perl.perl6.language/22971.

* Removed t/operators/binding.t and added t/operators/binding/scalars.t (former

binding.t), t/operators/binding/arrays.t (39 tests), and
t/operators/binding/hashes.t (30 tests).

* PIL2JS: Prelude::JS::Array, Prelude::JS::Hash: Binding of not yet existing

array/hash elements should autovivify (i.e., @array[$out_of_bounds_index] :=
..., %hash<not_existing_key> := ... should work). With these fixes, PIL2JS
passes binding/scalars.t 28/28, arrays.t 36/39, and hashes.t 30/30. :)

Files:
3 added
4 modified
1 moved

Legend:

Unmodified
Added
Removed
  • lib/pugs/hack.pod

    r6655 r6658  
    266266 
    267267Where applicable, conventions documented in Damian Conway's "Perl Best 
    268 Practices" book (Oreilly, 2005) should be followed by default.  At the very 
     268Practices" book (O'Reilly, 2005) should be followed by default.  At the very 
    269269least, all indenting should be done with spaces (4 per indent level) rather than 
    270270tabs, so the code and documentation looks the same to everyone. 
     
    279279    $ export PERL6LIB=blib6/lib 
    280280 
    281 You can also just say F<./pugs -Iblib6/lib t/.../mumble.t>. 
     281You can also just say C<./pugs -Iblib6/lib t/.../mumble.t>. 
    282282 
    283283=head3 Regex testing 
  • perl5/PIL2JS/lib6/Prelude/JS/Array.pm

    r6623 r6658  
    321321      ret.BINDTO = function (other) { 
    322322        if(array[idx] == undefined) 
    323           PIL2JS.die("Can\'t rebind non-existant array container!"); 
     323          array[idx] = new PIL2JS.Box(undefined); 
    324324 
    325325        return array[idx].BINDTO(other); 
  • perl5/PIL2JS/lib6/Prelude/JS/Hash.pm

    r6623 r6658  
    7373      ret.BINDTO = function (other) { 
    7474        if(!hash.exists(key)) 
    75           PIL2JS.die("Can\'t rebind non-existant hash container!"); 
     75          hash.add_pair(new PIL2JS.Pair( 
     76            new PIL2JS.Box.ReadOnly(key), 
     77            new PIL2JS.Box(undefined) 
     78          )); 
    7679 
    7780        return hash.get_value(key).BINDTO(other); 
  • t/operators/binding/scalars.t

    r6520 r6658  
    1717 
    1818# L<S03/"Binding" /replaces the container itself.  For instance:/> 
     19# Basic scalar binding tests 
     20{ 
     21  my $x = 'Just Another'; 
     22  is($x, 'Just Another', 'normal assignment works'); 
    1923 
    20 my $x = 'Just Another'; 
    21 is($x, 'Just Another', 'normal assignment works'); 
     24  my $y := $x; 
     25  is($y, 'Just Another', 'y is now bound to x'); 
    2226 
    23 my $y := $x; 
    24 is($y, 'Just Another', 'y is now bound to x'); 
     27  ok($y =:= $x, 'y is bound to x (we checked with the =:= identity op)'); 
    2528 
    26 ok($y =:= $x, 'y is bound to x (we checked with the =:= identity op)'); 
     29  my $z = $x; 
     30  is($z, 'Just Another', 'z is not bound to x'); 
    2731 
    28 my $z = $x; 
    29 is($z, 'Just Another', 'z is not bound to x'); 
     32  ok(!($z =:= $x), 'z is not bound to x (we checked with the =:= identity op)', :todo); 
    3033 
    31 ok(!($z =:= $x), 'z is not bound to x (we checked with the =:= identity op)', :todo); 
     34  $y = 'Perl Hacker'; 
     35  is($y, 'Perl Hacker', 'y has been changed to "Perl Hacker"'); 
     36  is($x, 'Perl Hacker', 'x has also been changed to "Perl Hacker"'); 
    3237 
    33 $y = 'Perl Hacker'; 
    34 is($y, 'Perl Hacker', 'y has been changed to "Perl Hacker"'); 
    35 is($x, 'Perl Hacker', 'x has also been changed to "Perl Hacker"'); 
    36  
    37 is($z, 'Just Another', 'z is still "Just Another" because it was not bound to x'); 
    38  
    39 sub bar { 
    40   return $CALLER::a eq $CALLER::b; 
     38  is($z, 'Just Another', 'z is still "Just Another" because it was not bound to x'); 
    4139} 
    4240 
    43 sub foo { 
    44   my $a = "foo"; 
    45   my $b := $a; 
    46   return bar(); # && bar2(); 
     41# Binding and $CALLER:: 
     42{ 
     43  sub bar { 
     44    return $CALLER::a eq $CALLER::b; 
     45  } 
     46 
     47  sub foo { 
     48    my $a = "foo"; 
     49    my $b := $a; 
     50    return bar(); # && bar2(); 
     51  } 
     52 
     53  ok(foo(), "CALLER resolves bindings in caller's dynamic scope"); 
    4754} 
    48  
    49 ok(foo(), "CALLER resolves bindings in caller's dynamic scope"); 
    5055 
    5156# Binding to swap 
     
    112117} 
    113118 
    114 # := actually takes function parameter list 
     119# := actually takes subroutine parameter list 
    115120{ 
    116121  my $a; 
  • t/statements/for_with_only_one_item.t

    r6639 r6658  
    66# Test primarily aimed at PIL2JS 
    77 
    8 plan 5; 
     8plan 8; 
    99 
     10# sanity tests 
    1011{ 
    1112  my $res; 
     
    2223} 
    2324 
     25# for with only one item, a constant 
    2426{ 
    2527  my $res; 
     
    4244  is $res, "a", "for works with \"a_single_constant\""; 
    4345} 
     46 
     47# for with only one item, an arrayref 
     48# See thread "for $arrayref {...}" on p6l started by Ingo Blechschmidt, 
     49# http://www.nntp.perl.org/group/perl.perl6.language/22970. 
     50{ 
     51  my $arrayref = [1,2,3]; 
     52 
     53  my $count; 
     54  for ($arrayref,) { $count++ } 
     55 
     56  is $count, 1, 'for ($arrayref,) {...} executes the loop body only once'; 
     57} 
     58 
     59{ 
     60  my $arrayref = [1,2,3]; 
     61 
     62  my $count; 
     63  for ($arrayref) { $count++ } 
     64 
     65  is $count, 1, 'for ($arrayref) {...} executes the loop body only once'; 
     66} 
     67 
     68{ 
     69  my $arrayref = [1,2,3]; 
     70 
     71  my $count; 
     72  for $arrayref { $count++ } 
     73 
     74  is $count, 1, 'for $arrayref {...} executes the loop body only once'; 
     75}