File: ReplaceTabsInTokenTabWidth1Test.php

package info (click to toggle)
php-codesniffer 3.11.2-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,772 kB
  • sloc: php: 84,771; pascal: 10,061; xml: 6,832; javascript: 2,096; sh: 11; makefile: 4
file content (111 lines) | stat: -rw-r--r-- 4,265 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
 * Tests the tab replacement logic.
 *
 * @author    Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
 * @copyright 2024 PHPCSStandards and contributors
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
 */

namespace PHP_CodeSniffer\Tests\Core\Tokenizers\Tokenizer;

/**
 * Tab replacement test using tab width 1.
 *
 * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::replaceTabsInToken
 */
final class ReplaceTabsInTokenTabWidth1Test extends ReplaceTabsInTokenTestCase
{

    /**
     * The tab width setting to use when tokenizing the file.
     *
     * @var integer
     */
    protected $tabWidth = 1;


    /**
     * Data provider helper.
     *
     * @see ReplaceTabsInTokenTestCase::dataTabReplacement()
     *
     * @return array<string, array<string, int|string>>
     */
    public static function getTabReplacementExpected()
    {
        return [
            'Tab indentation'                                                      => [
                'length'       => 2,
                'content'      => '  ',
                'orig_content' => '		',
            ],
            'Mixed tab/space indentation'                                          => [
                'length'       => 3,
                'content'      => '   ',
                'orig_content' => '	  ',
            ],
            'Inline: single tab in text string'                                    => [
                'length'       => 15,
                'content'      => "'tab separated'",
                'orig_content' => "'tab	separated'",
            ],
            'Inline: single tab between each word in text string'                  => [
                'length'       => 24,
                'content'      => '"tab $between each word"',
                'orig_content' => '"tab	$between	each	word"',
            ],
            'Inline: multiple tabs in heredoc'                                     => [
                'length'       => 15,
                'content'      => 'tab   separated
',
                'orig_content' => 'tab			separated
',
            ],
            'Inline: multiple tabs between each word in nowdoc'                    => [
                'length'       => 27,
                'content'      => 'tab  between    each   word
',
                'orig_content' => 'tab		between				each			word
',
            ],
            'Inline: mixed spaces/tabs in text string'                             => [
                'length'       => 20,
                'content'      => "'tab      separated'",
                'orig_content' => "'tab 	  		separated'",
            ],
            'Inline: mixed spaces/tabs between each word in text string'           => [
                'length'       => 31,
                'content'      => '"tab  $between   each     word"',
                'orig_content' => '"tab	 $between  	each	   	word"',
            ],
            'Inline: tab becomes single space in comment (with tabwidth 4)'        => [
                'length'       => 50,
                'content'      => '// -123 With tabwidth 4, the tab size should be 1.
',
                'orig_content' => '// -123	With tabwidth 4, the tab size should be 1.
',
            ],
            'Inline: tab becomes 2 spaces in comment (with tabwidth 4)'            => [
                'length'       => 52,
                'content'      => '/* -12 With tabwidth 4, the tab size should be 2. */',
                'orig_content' => '/* -12	With tabwidth 4, the tab size should be 2. */',
            ],
            'Inline: tab becomes 3 spaces in doc comment string (with tabwidth 4)' => [
                'length'       => 45,
                'content'      => '-1 With tabwidth 4, the tab size should be 3.',
                'orig_content' => '-1	With tabwidth 4, the tab size should be 3.',
            ],
            'Inline: tab becomes 4 spaces in comment (with tabwidth 4)'            => [
                'length'       => 47,
                'content'      => '// - With tabwidth 4, the tab size should be 4.
',
                'orig_content' => '// -	With tabwidth 4, the tab size should be 4.
',
            ],
        ];

    }//end getTabReplacementExpected()


}//end class