mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-05-04 18:08:46 +03:00
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Search;
|
|
|
|
use BookStack\Search\Vectors\TextChunker;
|
|
use Tests\TestCase;
|
|
|
|
class TextChunkerTest extends TestCase
|
|
{
|
|
public function test_it_chunks_text()
|
|
{
|
|
$chunker = new TextChunker(3, []);
|
|
$chunks = $chunker->chunk('123456789');
|
|
|
|
$this->assertEquals(['123', '456', '789'], $chunks);
|
|
}
|
|
|
|
public function test_chunk_size_must_be_greater_than_zero()
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$chunker = new TextChunker(-5, []);
|
|
}
|
|
|
|
public function test_it_works_through_given_delimiters()
|
|
{
|
|
$chunker = new TextChunker(5, ['-', '.', '']);
|
|
$chunks = $chunker->chunk('12-3456.789abcdefg');
|
|
|
|
$this->assertEquals(['12', '3456', '789ab', 'cdefg'], $chunks);
|
|
}
|
|
|
|
public function test_it_attempts_to_pack_chunks()
|
|
{
|
|
$chunker = new TextChunker(8, [' ', '']);
|
|
$chunks = $chunker->chunk('123 456 789 abc def');
|
|
|
|
$this->assertEquals(['123 456', '789 abc', 'def'], $chunks);
|
|
}
|
|
|
|
public function test_it_attempts_to_pack_using_subchunks()
|
|
{
|
|
$chunker = new TextChunker(8, [' ', '-', '']);
|
|
$chunks = $chunker->chunk('123 456-789abc');
|
|
|
|
$this->assertEquals(['123 456', '789abc'], $chunks);
|
|
}
|
|
}
|