Exemplo n.º 1
0
 public function testFirst()
 {
     // from js
     $this->assertEquals(1, __::first(array(1, 2, 3)), 'can pull out the first element of an array');
     $this->assertEquals(array(), __::first(array(1, 2, 3), 0), 'can pass an index to first');
     $this->assertEquals(array(1, 2), __::first(array(1, 2, 3), 2), 'can pass an index to first');
     $this->assertEquals(1, __(array(1, 2, 3))->first(), 'can perform OO-style "first()"');
     $result = __::map(array(array(1, 2, 3), array(1, 2, 3)), function ($vals) {
         return __::first($vals);
     });
     $this->assertEquals(array(1, 1), $result, 'works well with _.map');
     $func = function () {
         return __::first(func_get_args());
     };
     $result = $func(4, 3, 2, 1);
     $this->assertEquals(4, $result, 'works on an arguments object');
     // extra
     $this->assertEquals(array(1), __::first(array(1, 2, 3), 1), 'can pass an index of 1 to first');
     $this->assertEquals(array(4, 5), __(array(4, 5, 6, 7))->first(2), 'can perform OO-style "first()" with index passed');
     $this->assertEquals(1, __::head(array(1, 2, 3)), 'aliased as "head"');
     $this->assertEquals(array(), __::head(array(1, 2, 3), 0), 'aliased as "head"');
     // docs
     $this->assertEquals(5, __::first(array(5, 4, 3, 2, 1)));
     $this->assertEquals(array(5, 4, 3), __::first(array(5, 4, 3, 2, 1), 3));
 }