public function test_startsWith() { $http = F\startsWith('http://'); $this->assertTrue($http('http://github.com')); $this->assertTrue(F\startsWith('the same', 'the same')); $this->assertFalse($http('github.com')); $this->assertFalse(F\startsWith('something very long', 'small thing')); $this->assertFalse(F\startsWith('something very long', 'something very')); }
public function test_satisfiesAny() { $persons = [['name' => 'foo', 'age' => 11], ['name' => 'bar', 'age' => 9], ['name' => 'baz', 'age' => 16], ['name' => 'zeta', 'age' => 33], ['name' => 'beta', 'age' => 25]]; $isValid = F\satisfiesAny(['name' => F\startsWith('b'), 'age' => F\gt(F\__(), 15)]); $this->assertEquals([['name' => 'bar', 'age' => 9], ['name' => 'baz', 'age' => 16], ['name' => 'zeta', 'age' => 33], ['name' => 'beta', 'age' => 25]], F\filter($isValid, $persons)); }
function test_any() { $startsOrEndsWith = function ($text) { return F\any(F\startsWith($text), F\endsWith($text)); }; $test = $startsOrEndsWith('b'); $alwaysFalse = F\any(); $this->assertEquals(true, $test('bar')); $this->assertEquals(true, $test('bob')); $this->assertEquals(false, $test('foo')); $this->assertEquals(false, $alwaysFalse(1)); $this->assertEquals(false, $alwaysFalse(null)); }
public function test_findLast() { $this->assertEquals(F\findLast(F\startsWith('b'), ['foo', 'bar', 'baz']), 'baz'); $this->assertEquals(F\findLast(F\startsWith('c'), ['foo', 'bar', 'baz']), null); }