Rust-style Option and Result Classes for PHP

refactor(tests/OptionTest.php): remove tests for methods that won't be implemented

Ciaran b105bdeb 332ccdbf

-66
-66
tests/OptionTest.php
··· 67 67 $this->assertSame(42, Option::None()->mapOr(fn () => 42, fn ($v) => strlen($v))); 68 68 } 69 69 70 - public function test_map_or_else(): void 71 - { 72 - $this->markTestIncomplete('TODO'); 73 - $k = 21; 74 - $this->assertSame(3, Option::Some('foo')->mapOrElse(fn () => 2 * $k, fn ($v) => strlen($v))); 75 - $this->assertSame(42, Option::None()->mapOrElse(fn () => 2 * $k, fn ($v) => strlen($v))); 76 - } 77 - 78 70 public function test_filter(): void 79 71 { 80 72 $result = Option::Some(4)->filter(fn ($x) => $x > 2); ··· 173 165 174 166 $result = $n->reduce($n, $f); 175 167 $this->assertTrue($result->isNone()); 176 - } 177 - 178 - public function test_replace(): void 179 - { 180 - $x = Option::Some(2); 181 - $old = $x->replace(5); 182 - $this->assertTrue($x->isSome()); 183 - $this->assertSame(5, $x->unwrap()); 184 - $this->assertTrue($old->isSome()); 185 - $this->assertSame(2, $old->unwrap()); 186 - 187 - $x = Option::None(); 188 - $old = $x->replace(3); 189 - $this->assertTrue($x->isSome()); 190 - $this->assertSame(3, $x->unwrap()); 191 - $this->assertTrue($old->isNone()); 192 - } 193 - 194 - public function test_take(): void 195 - { 196 - $x = Option::Some(2); 197 - $y = $x->take(); 198 - $this->assertTrue($x->isNone()); 199 - $this->assertTrue($y->isSome()); 200 - $this->assertSame(2, $y->unwrap()); 201 - 202 - $x = Option::None(); 203 - $y = $x->take(); 204 - $this->assertTrue($x->isNone()); 205 - $this->assertTrue($y->isNone()); 206 - } 207 - 208 - public function test_take_if(): void 209 - { 210 - $x = Option::Some(42); 211 - $prev = $x->takeIf(function (&$v) { 212 - if ($v === 42) { 213 - $v += 1; 214 - 215 - return false; 216 - } 217 - 218 - return false; 219 - }); 220 - $this->assertTrue($x->isSome()); 221 - $this->assertSame(43, $x->unwrap()); 222 - $this->assertTrue($prev->isNone()); 223 - 224 - $x = Option::Some(43); 225 - $prev = $x->takeIf(fn ($v) => $v === 43); 226 - $this->assertTrue($x->isNone()); 227 - $this->assertTrue($prev->isSome()); 228 - $this->assertSame(43, $prev->unwrap()); 229 - 230 - $x = Option::None(); 231 - $prev = $x->takeIf(fn ($v) => true); 232 - $this->assertTrue($x->isNone()); 233 - $this->assertTrue($prev->isNone()); 234 168 } 235 169 236 170 // Integration tests