Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-04-08 15:25:26 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-04-08 17:06:28 +0300
commit0cfa97e236a63f56c5997880e54ba04a428b41a9 (patch)
treeb7e00b3f9b0dcd71b41718dc9338b560c4ff926e /tests
parent619037b35fa122b5b2a163787adbaffa67a5fc21 (diff)
Add an array_flat_map function
More functional and more expressive. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/FunctionsTest.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/Unit/FunctionsTest.php b/tests/Unit/FunctionsTest.php
new file mode 100644
index 000000000..c128055c3
--- /dev/null
+++ b/tests/Unit/FunctionsTest.php
@@ -0,0 +1,65 @@
+<?php
+
+declare(strict_types=1);
+
+/*
+ * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\mail\tests\Unit;
+
+use ChristophWurst\Nextcloud\Testing\TestCase;
+use function OCA\Mail\array_flat_map;
+
+class FunctionsTest extends TestCase {
+ public function testFlatMapEmpty(): void {
+ $map = function () {
+ };
+
+ $result = array_flat_map($map, []);
+
+ self::assertEmpty($result);
+ }
+
+ public function testFlatMap(): void {
+ $double = function ($x) {
+ return [$x, $x];
+ };
+ $data = [
+ 1,
+ 2,
+ 3,
+ ];
+
+ $result = array_flat_map($double, $data);
+
+ self::assertEquals(
+ [
+ 1,
+ 1,
+ 2,
+ 2,
+ 3,
+ 3,
+ ],
+ $result
+ );
+ }
+}