<?php

declare(strict_types=1);

namespace Drupal\Tests\flowdrop\Unit\DTO\Tool;

use Drupal\Tests\UnitTestCase;
use Drupal\flowdrop\DTO\Tool\ToolName;

/**
 * Tests the ToolName slug helper.
 *
 * @coversDefaultClass \Drupal\flowdrop\DTO\Tool\ToolName
 * @group flowdrop
 */
class ToolNameTest extends UnitTestCase {

  /**
   * @covers ::fromLabel
   * @dataProvider labelProvider
   */
  public function testFromLabel(string $label, string $expected): void {
    $this->assertSame($expected, ToolName::fromLabel($label));
  }

  /**
   * Provides labels and their expected slugs.
   *
   * @return array<string, array{string, string}>
   *   Test cases.
   */
  public static function labelProvider(): array {
    return [
      "simple" => ["Web Search", "web_search"],
      "hyphen collides with space" => ["web-search", "web_search"],
      "preserves underscore, canonicalizes dash" => ["my_tool-2", "my_tool_2"],
      "strips punctuation" => ["Search (v2)!", "search_v2"],
      "trims separators" => ["  Spaced  ", "spaced"],
      "empty falls back" => ["", "tool"],
      "symbols only fall back" => ["***", "tool"],
    ];
  }

  /**
   * Names are clamped to the 64-character tool-name limit.
   *
   * @covers ::fromLabel
   */
  public function testLengthClamp(): void {
    $name = ToolName::fromLabel(str_repeat("a", 100));
    $this->assertSame(64, strlen($name));
  }

}
