Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/parser/__tests__/DifferentialTabReplacementTestCase.php
12262 views
1
<?php
2
3
final class DifferentialTabReplacementTestCase
4
extends PhabricatorTestCase {
5
6
public function testTabReplacement() {
7
$tab1 = "<span data-copy-text=\"\t\"> </span>";
8
$tab2 = "<span data-copy-text=\"\t\"> </span>";
9
10
$cat = "\xF0\x9F\x90\xB1";
11
12
$cases = array(
13
'' => '',
14
'x' => 'x',
15
16
// Tabs inside HTML tags should not be replaced.
17
"<\t>x" => "<\t>x",
18
19
// Normal tabs should be replaced. These are all aligned to the tab
20
// width, so they'll be replaced inline.
21
"\tx" => "{$tab2}x",
22
" \tx" => " {$tab2}x",
23
"\t x" => "{$tab2} x",
24
"aa\tx" => "aa{$tab2}x",
25
"aa \tx" => "aa {$tab2}x",
26
"aa\t x" => "aa{$tab2} x",
27
28
// This tab is not tabstop-aligned, so it is replaced with fewer
29
// spaces to bring us to the next tabstop.
30
" \tx" => " {$tab1}x",
31
32
// Text inside HTML tags should not count when aligning tabs with
33
// tabstops.
34
"<tag> </tag>\tx" => "<tag> </tag>{$tab1}x",
35
"<tag2> </tag>\tx" => "<tag2> </tag>{$tab1}x",
36
37
// The code has to take a slow path when inputs contain unicode, but
38
// should produce the right results and align tabs to tabstops while
39
// respecting UTF8 display character widths, not byte widths.
40
"{$cat}\tx" => "{$cat}{$tab1}x",
41
"{$cat}{$cat}\tx" => "{$cat}{$cat}{$tab2}x",
42
);
43
44
foreach ($cases as $input => $expect) {
45
$actual = DifferentialChangesetParser::replaceTabsWithSpaces(
46
$input,
47
2);
48
49
$this->assertEqual(
50
$expect,
51
$actual,
52
pht('Tabs to Spaces: %s', $input));
53
}
54
}
55
56
}
57
58