コード例 #1
0
ファイル: StackTest.php プロジェクト: twhiston/twlib
 public function testStack()
 {
     $a = 23;
     $b = 'string it up';
     $s = new Stack();
     $pb = new Reference($b);
     $s->takeReference($a);
     $s->takeReference($pb);
     try {
         $s[] = $pb;
     } catch (TwLibException $e) {
         $this->assertRegExp('/Do not set stack references with the array operator/', $e->getMessage());
     }
     $this->assertEquals(23, $s[0]->copy());
     $this->assertRegExp('/string it up/', $s[1]->copy());
     $a = 'gone';
     $b = 'girl';
     $this->assertRegExp('/gone/', $s[0]->copy());
     $this->assertRegExp('/girl/', $s[1]->copy());
     $ref = 'take me';
     $s->takeReference($ref);
     $this->assertRegExp('/take me/', $s[2]->copy());
     $ref = 'thus i was taken';
     $this->assertRegExp('/thus i was taken/', $s[2]->copy());
     $s[2]->set('rewind');
     $this->assertRegExp('/rewind/', $ref);
     $g = $s[2];
     $g->set('bo selecta');
     //Test that you cant alter the top if you forget to take it by reference
     /** @var Pointer $top */
     $top = $s->top();
     $tr = $top->getRef();
     $tr = 'beans';
     $this->assertRegExp('/bo selecta/', $ref);
     //Test that you do alter the location if you take it by reference
     /** @var Pointer $top */
     $top =& $s->top();
     $tr =& $top->getRef();
     $tr = 'beans';
     $this->assertRegExp('/beans/', $ref);
     //Pop the top item off the stack
     $cs = count($s);
     /** @var Pointer $p */
     $p = $s->pop();
     $cp = count($s);
     $this->assertEquals($cs - 1, $cp);
     //assert our array got smaller
     $ra =& $p->getRef();
     $ra = 'show me the sunshine';
     $this->assertRegExp('/show me the sunshine/', $p->copy());
     $this->assertRegExp('/show me the sunshine/', $ref);
     $pl = $s->shift();
     $cl = count($s);
     $this->assertEquals($cp - 1, $cl);
     //assert our array got smaller
     $pa =& $pl->getRef();
     $pa = 'it looks like everything is falling';
     $this->assertRegExp('/it looks like everything is falling/', $a);
     //goodbye stack
     foreach ($s as $k => $point) {
         unset($s[$k]);
     }
     $this->assertCount(0, $s);
 }
コード例 #2
0
ファイル: PointerTest.php プロジェクト: twhiston/twlib
 public function testArrayAccess()
 {
     $data = $this->getData();
     $s = new Stack();
     $s->takeReference($data[0]);
     $s->takeReference($data['bees']);
     $r =& $s->top();
     $rf =& $r->getRef();
     $rf[0] = 'changed';
     $pt =& $rf['depth'];
     $pt = 'you\'re superhuman';
     $ind = 'depth';
     $pn =& $rf[$ind];
     $pn = 'if you dont want to loose me forever';
 }