Path: blob/master/src/applications/differential/parser/__tests__/DifferentialTabReplacementTestCase.php
12262 views
<?php12final class DifferentialTabReplacementTestCase3extends PhabricatorTestCase {45public function testTabReplacement() {6$tab1 = "<span data-copy-text=\"\t\"> </span>";7$tab2 = "<span data-copy-text=\"\t\"> </span>";89$cat = "\xF0\x9F\x90\xB1";1011$cases = array(12'' => '',13'x' => 'x',1415// Tabs inside HTML tags should not be replaced.16"<\t>x" => "<\t>x",1718// Normal tabs should be replaced. These are all aligned to the tab19// width, so they'll be replaced inline.20"\tx" => "{$tab2}x",21" \tx" => " {$tab2}x",22"\t x" => "{$tab2} x",23"aa\tx" => "aa{$tab2}x",24"aa \tx" => "aa {$tab2}x",25"aa\t x" => "aa{$tab2} x",2627// This tab is not tabstop-aligned, so it is replaced with fewer28// spaces to bring us to the next tabstop.29" \tx" => " {$tab1}x",3031// Text inside HTML tags should not count when aligning tabs with32// tabstops.33"<tag> </tag>\tx" => "<tag> </tag>{$tab1}x",34"<tag2> </tag>\tx" => "<tag2> </tag>{$tab1}x",3536// The code has to take a slow path when inputs contain unicode, but37// should produce the right results and align tabs to tabstops while38// respecting UTF8 display character widths, not byte widths.39"{$cat}\tx" => "{$cat}{$tab1}x",40"{$cat}{$cat}\tx" => "{$cat}{$cat}{$tab2}x",41);4243foreach ($cases as $input => $expect) {44$actual = DifferentialChangesetParser::replaceTabsWithSpaces(45$input,462);4748$this->assertEqual(49$expect,50$actual,51pht('Tabs to Spaces: %s', $input));52}53}5455}565758