|
14 | 14 |
|
15 | 15 | use Mekras\Speller\Aspell\Aspell;
|
16 | 16 | use Mekras\Speller\Source\EncodingAwareSource;
|
| 17 | +use Mekras\Speller\Source\StringSource; |
17 | 18 | use PHPUnit\Framework\TestCase;
|
18 | 19 | use Symfony\Component\Process\Process;
|
19 | 20 |
|
@@ -69,7 +70,7 @@ public function testGetSupportedLanguages(): void
|
69 | 70 | 'ru',
|
70 | 71 | 'ru-ye',
|
71 | 72 | 'ru-yeyo',
|
72 |
| - 'ru-yo' |
| 73 | + 'ru-yo', |
73 | 74 | ],
|
74 | 75 | $aspell->getSupportedLanguages()
|
75 | 76 | );
|
@@ -115,4 +116,54 @@ public function testCheckText(): void
|
115 | 116 | static::assertEquals('CCould', $issues[4]->word);
|
116 | 117 | static::assertEquals(4, $issues[4]->line);
|
117 | 118 | }
|
| 119 | + |
| 120 | + /** |
| 121 | + * Test spell checking when a word contains a colon |
| 122 | + * |
| 123 | + * @see https://github.com/mekras/php-speller/issues/24 |
| 124 | + */ |
| 125 | + public function testCheckTextWithColon(): void |
| 126 | + { |
| 127 | + $source = new StringSource('S:t Petersburg är i Ryssland', 'UTF-8'); |
| 128 | + |
| 129 | + $process = $this->prophesize(Process::class); |
| 130 | + $process->setTimeout(600)->shouldBeCalled(); |
| 131 | + $process->setEnv([])->shouldBeCalled(); |
| 132 | + $process->setInput('S:t Petersburg är i Ryssland')->shouldBeCalled(); |
| 133 | + $process->run()->shouldBeCalled(); |
| 134 | + $process->getExitCode()->shouldBeCalled()->willReturn(0); |
| 135 | + $process->getOutput()->shouldBeCalled()->willReturn(file_get_contents(__DIR__ . '/fixtures/check_sv.txt')); |
| 136 | + |
| 137 | + $aspell = new Aspell(); |
| 138 | + $aspell->setProcess($process->reveal()); |
| 139 | + $issues = $aspell->checkText($source, ['sv']); |
| 140 | + |
| 141 | + static::assertCount(1, $issues); |
| 142 | + static::assertEquals('S:t', $issues[0]->word); |
| 143 | + static::assertEquals(1, $issues[0]->line); |
| 144 | + static::assertEquals(0, $issues[0]->offset); |
| 145 | + static::assertEquals(['St', 'Set', 'Sot', 'Söt', 'Stl', 'Stå'], $issues[0]->suggestions); |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Test spell checking when aspell binary output is unexpected |
| 150 | + */ |
| 151 | + public function testUnexpectedOutputParsing(): void |
| 152 | + { |
| 153 | + $source = new StringSource('The quick brown fox jumps over the lazy dog', 'UTF-8'); |
| 154 | + |
| 155 | + $process = $this->prophesize(Process::class); |
| 156 | + $process->setTimeout(600)->shouldBeCalled(); |
| 157 | + $process->setEnv([])->shouldBeCalled(); |
| 158 | + $process->setInput('The quick brown fox jumps over the lazy dog')->shouldBeCalled(); |
| 159 | + $process->run()->shouldBeCalled(); |
| 160 | + $process->getExitCode()->shouldBeCalled()->willReturn(0); |
| 161 | + $process->getOutput()->shouldBeCalled()->willReturn('& unexpected output: foo, bar, baz'); |
| 162 | + |
| 163 | + $aspell = new Aspell(); |
| 164 | + $aspell->setProcess($process->reveal()); |
| 165 | + $issues = $aspell->checkText($source, ['en']); |
| 166 | + |
| 167 | + static::assertEmpty($issues); |
| 168 | + } |
118 | 169 | }
|
0 commit comments