Skip to content

Commit 7213b88

Browse files
committed
Add tests for \r, mixed, and idempotent normalization
1 parent 1034c83 commit 7213b88

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/test-ai-overview.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,38 @@ public function test_normalize_answer_text_plain_unchanged() {
190190
);
191191
}
192192

193+
/**
194+
* A standalone literal carriage return (no following n) becomes one real newline.
195+
*/
196+
public function test_normalize_answer_text_literal_lone_cr() {
197+
$this->assertSame(
198+
"line1\nline2",
199+
FaqSearchService::normalize_answer_text( 'line1\rline2' )
200+
);
201+
}
202+
203+
/**
204+
* A real newline and a literal escape sequence in the same string both
205+
* end up as real newlines, with the pre-existing real newline untouched.
206+
*/
207+
public function test_normalize_answer_text_mixed_real_and_literal_newline() {
208+
$this->assertSame(
209+
"line1\nline2\nline3",
210+
FaqSearchService::normalize_answer_text( "line1\nline2" . '\n' . 'line3' )
211+
);
212+
}
213+
214+
/**
215+
* Normalization is idempotent: running it on already-normalized output
216+
* produces the same result as a single pass.
217+
*/
218+
public function test_normalize_answer_text_idempotent() {
219+
$input = 'a\r\nb\tc' . "\n" . 'd';
220+
$once = FaqSearchService::normalize_answer_text( $input );
221+
$twice = FaqSearchService::normalize_answer_text( $once );
222+
$this->assertSame( $once, $twice );
223+
}
224+
193225
/**
194226
* The AI Overview mode defaults to conversation and honors option/filter.
195227
*/

0 commit comments

Comments
 (0)