5 use BookStack\Search\Vectors\TextChunker;
8 class TextChunkerTest extends TestCase
10 public function test_it_chunks_text()
12 $chunker = new TextChunker(3, []);
13 $chunks = $chunker->chunk('123456789');
15 $this->assertEquals(['123', '456', '789'], $chunks);
18 public function test_chunk_size_must_be_greater_than_zero()
20 $this->expectException(\InvalidArgumentException::class);
21 $chunker = new TextChunker(-5, []);
24 public function test_it_works_through_given_delimiters()
26 $chunker = new TextChunker(5, ['-', '.', '']);
27 $chunks = $chunker->chunk('12-3456.789abcdefg');
29 $this->assertEquals(['12', '3456', '789ab', 'cdefg'], $chunks);
32 public function test_it_attempts_to_pack_chunks()
34 $chunker = new TextChunker(8, [' ', '']);
35 $chunks = $chunker->chunk('123 456 789 abc def');
37 $this->assertEquals(['123 456', '789 abc', 'def'], $chunks);
40 public function test_it_attempts_to_pack_using_subchunks()
42 $chunker = new TextChunker(8, [' ', '-', '']);
43 $chunks = $chunker->chunk('123 456-789abc');
45 $this->assertEquals(['123 456', '789abc'], $chunks);