Skip to content

Commit

Permalink
Switch _ to __ to not conflict with gettext() alias
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhaveri committed Jun 12, 2011
1 parent 391e951 commit bd7e456
Show file tree
Hide file tree
Showing 7 changed files with 517 additions and 517 deletions.
178 changes: 89 additions & 89 deletions test/ArraysTest.php

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions test/ChainingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function testMapFlattenReduce() {
"He's a lumberjack and he's okay",
"He sleeps all night and he works all day"
);
$counts = _($lyrics)->chain()
$counts = __($lyrics)->chain()
->map(function($line) { return str_split($line); })
->flatten()
->reduce(function($hash, $l) {
Expand All @@ -27,7 +27,7 @@ public function testMapFlattenReduce() {

public function testSelectRejectSortBy() {
$numbers = array(1,2,3,4,5,6,7,8,9,10);
$numbers = _($numbers)->chain()->select(function($n) {
$numbers = __($numbers)->chain()->select(function($n) {
return $n % 2 === 0;
})->reject(function($n) {
return $n % 4 === 0;
Expand All @@ -40,7 +40,7 @@ public function testSelectRejectSortBy() {
public function testChain() {
// docs
$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$result = _($numbers)->chain()
$result = __($numbers)->chain()
->select(function($n) { return $n < 5; })
->reject(function($n) { return $n === 3; })
->sortBy(function($n) { return -$n; })
Expand All @@ -50,6 +50,6 @@ public function testChain() {

public function testValue() {
// docs
$this->assertEquals(array(1, 2, 3), _(array(1, 2, 3))->value());
$this->assertEquals(array(1, 2, 3), __(array(1, 2, 3))->value());
}
}
304 changes: 152 additions & 152 deletions test/CollectionsTest.php

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions test/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ public function testMemoize() {
$fib = function($n) use (&$fib) {
return $n < 2 ? $n : $fib($n - 1) + $fib($n - 2);
};
$fastFib = _::memoize($fib);
$fastFib = __::memoize($fib);
$this->assertEquals(55, $fib(10), 'a memoized version of fibonacci produces identical results');
$this->assertEquals(55, $fastFib(10), 'a memoized version of fibonacci produces identical results');

$o = function($str) { return $str; };
$fastO = _::memoize($o);
$fastO = __::memoize($o);
$this->assertEquals('toString', $o('toString'), 'checks hasOwnProperty');
$this->assertEquals('toString', $fastO('toString'), 'checks hasOwnProperty');

// extra
$name = function() { return 'moe'; };
$fastName = _::memoize($name);
$fastName = __::memoize($name);
$this->assertEquals('moe', $name(), 'works with no parameters');
$this->assertEquals('moe', $fastName(), 'works with no parameters');

$names = function($one, $two, $three) {
return join(', ', array($one, $two, $three));
};
$fastNames = _::memoize($names);
$fastNames = __::memoize($names);
$this->assertEquals('moe, larry, curly', $names('moe', 'larry', 'curly'), 'works with multiple parameters');
$this->assertEquals('moe, larry, curly', $fastNames('moe', 'larry', 'curly'), 'works with multiple parameters');

$foo = function() { return 'foo'; };
$fastFoo = _($foo)->memoize();
$fastFoo = __($foo)->memoize();
$this->assertEquals('foo', $foo(), 'can handle OO-style calls');
$this->assertEquals('foo', $fastFoo(), 'can handle OO-style calls');

$bar = function() { return 'bar'; };
$fastBar = _::memoize($bar, function($function, $args) {
$fastBar = __::memoize($bar, function($function, $args) {
return sha1(join('x', array(
var_export($function, 1),
var_export($args, 1)
Expand All @@ -50,15 +50,15 @@ public function testMemoize() {
$fibonacci = function($n) use (&$fibonacci) {
return $n < 2 ? $n : $fibonacci($n - 1) + $fibonacci($n - 2);
};
$fastFibonacci = _::memoize($fibonacci);
$fastFibonacci = __::memoize($fibonacci);
$this->assertEquals($fibonacci(2), $fastFibonacci(2));
}

public function testThrottle() {
// from js
$counter = 0;
$incr = function() use (&$counter) { $counter++; };
$throttledIncr = _::throttle($incr, 100);
$throttledIncr = __::throttle($incr, 100);
$throttledIncr(); $throttledIncr(); $throttledIncr();
usleep(120 * 1000); $throttledIncr();
usleep(140 * 1000); $throttledIncr();
Expand All @@ -69,7 +69,7 @@ public function testThrottle() {
// extra
$counter = 0;
$incr = function() use (&$counter) { $counter++; };
$throttledIncr = _($incr)->throttle(100);
$throttledIncr = __($incr)->throttle(100);
$throttledIncr(); $throttledIncr(); $throttledIncr();
usleep(120 * 1000); $throttledIncr();
usleep(140 * 1000); $throttledIncr();
Expand All @@ -81,14 +81,14 @@ public function testThrottle() {
public function testOnce() {
// from js + docs
$num = 0;
$increment = _::once(function() use (&$num) { return $num++; });
$increment = __::once(function() use (&$num) { return $num++; });
$increment();
$increment();
$this->assertEquals(1, $num);

// extra
$num = 0;
$increment = _(function() use (&$num) { return $num++; })->once();
$increment = __(function() use (&$num) { return $num++; })->once();
$increment();
$increment();
$this->assertEquals(1, $num);
Expand All @@ -97,23 +97,23 @@ public function testOnce() {
public function testWrap() {
// from js
$greet = function($name) { return 'hi: ' . $name; };
$backwards = _::wrap($greet, function($func, $name) { return $func($name) . ' ' . strrev($name); });
$backwards = __::wrap($greet, function($func, $name) { return $func($name) . ' ' . strrev($name); });
$this->assertEquals('hi: moe eom', $backwards('moe'), 'wrapped the salutation function');

$inner = function() { return 'Hello '; };
$arr = array('name'=>'Moe');
$arr['hi'] = _::wrap($inner, function($fn) use ($arr) { return $fn() . $arr['name']; });
$arr['hi'] = __::wrap($inner, function($fn) use ($arr) { return $fn() . $arr['name']; });
$this->assertEquals('Hello Moe', $arr['hi']());

// extra
$inner = function() { return 'Hello '; };
$arr = array('name'=>'Curly');
$arr['hi'] = _($inner)->wrap(function($fn) use ($arr) { return $fn() . $arr['name']; });
$arr['hi'] = __($inner)->wrap(function($fn) use ($arr) { return $fn() . $arr['name']; });
$this->assertEquals('Hello Curly', $arr['hi']());

// docs
$hello = function($name) { return 'hello: ' . $name; };
$hi = _::wrap($hello, function($func) {
$hi = __::wrap($hello, function($func) {
return 'before, ' . $func('moe') . ', after';
});
$this->assertEquals('before, hello: moe, after', $hi());
Expand All @@ -123,28 +123,28 @@ public function testCompose() {
// from js
$greet = function($name) { return 'hi: ' . $name; };
$exclaim = function($sentence) { return $sentence . '!'; };
$composed = _::compose($exclaim, $greet);
$composed = __::compose($exclaim, $greet);
$this->assertEquals('hi: moe!', $composed('moe'), 'can compose a function that takes another');

$composed = _::compose($greet, $exclaim);
$composed = __::compose($greet, $exclaim);
$this->assertEquals('hi: moe!', $composed('moe'), 'in this case, the functions are also commutative');

// extra
$composed = _($greet)->compose($exclaim);
$composed = __($greet)->compose($exclaim);
$this->assertEquals('hi: moe!', $composed('moe'), 'in this case, the functions are also commutative');

// docs
$greet = function($name) { return 'hi: ' . $name; };
$exclaim = function($statement) { return $statement . '!'; };
$welcome = _::compose($exclaim, $greet);
$welcome = __::compose($exclaim, $greet);
$this->assertEquals('hi: moe!', $welcome('moe'));
}

public function testAfter() {
// from js
$testAfter = function($afterAmount, $timesCalled) {
$afterCalled = 0;
$after = _::after($afterAmount, function() use (&$afterCalled) {
$after = __::after($afterAmount, function() use (&$afterCalled) {
$afterCalled++;
});
while($timesCalled--) $after();
Expand All @@ -156,7 +156,7 @@ public function testAfter() {
// extra
$testAfterAgain = function($afterAmount, $timesCalled) {
$afterCalled = 0;
$after = _($afterAmount)->after(function() use (&$afterCalled) {
$after = __($afterAmount)->after(function() use (&$afterCalled) {
$afterCalled++;
});
while($timesCalled--) $after();
Expand All @@ -167,7 +167,7 @@ public function testAfter() {

// docs
$str = '';
$func = _::after(3, function() use(&$str) { $str = 'x'; });
$func = __::after(3, function() use(&$str) { $str = 'x'; });
$func();
$func();
$func();
Expand Down
Loading

0 comments on commit bd7e456

Please sign in to comment.