<?php
declare(strict_types=1);

require __DIR__ . '/contract.php';

function expect(bool $ok, string $message): void
{
    if (!$ok) throw new RuntimeException($message);
}

$rows = [['id' => 7, 'name' => '目标'], ['id' => 8, 'name' => '其他']];
expect(cat8f_row($rows, 7, '目标') === $rows[0], 'list row must match ID and name');
expect(cat8f_row([['id' => 7, 'name' => '错误']], 7, '目标') === null,
    'same ID with wrong name is not a positive result');
expect(cat8f_row([['foods' => [['id' => 7, 'name' => '目标']]]], 7, '目标') === null,
    'nested unrelated ID must not satisfy a list row');
expect(cat8f_tree([['id' => 2, 'name' => '根', 'children' => [
    ['id' => 7, 'name' => '目标']]]], 7, '目标'), 'category child must be reachable');
expect(!cat8f_tree([['id' => 2, 'name' => '根', 'children' => [
    ['id' => 7, 'name' => '错误']]]], 7, '目标'), 'category name must match');
expect(!cat8f_tree([['id' => 2, 'name' => '根', 'other' => [
    ['id' => 7, 'name' => '目标']]]], 7, '目标'), 'only children form category tree');
echo "contract_matchers_pass=6\n";
