File: code.php

package info (click to toggle)
php-nunomaduro-termwind 2.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,172 kB
  • sloc: php: 3,969; makefile: 34
file content (129 lines) | stat: -rw-r--r-- 4,676 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php

use function Termwind\parse;

it('renders the element', function () {
    $html = parse(<<<'HTML'
        <div>
            <code start-line="11400">&lt;?php</code>
        </div>
HTML
    );

    expect($html)->toBe(<<<'HTML'

<fg=gray>11400</><fg=gray>▕ </><?php
HTML
    );
});

it('renders the element with multiline code', function () {
    $html = parse(<<<'HTML'
        <div>
            <code line="7">
&lt;?php

/** @test */
function sentryReport()
{
    try {
        throw new \Exception('Something went wrong');
    } catch (\Throwable $e) {
        report($e);
    }
}
            </code>
        </div>
HTML
    );

    expect($html)->toBe(<<<'HTML'

    <fg=gray>  1</><fg=gray>▕ </><?php
    <fg=gray>  2</><fg=gray>▕ </>
    <fg=gray>  3</><fg=gray>▕ </><fg=gray>/** @test */</>
    <fg=gray>  4</><fg=gray>▕ </><fg=magenta>function </>sentryReport<fg=magenta>()</>
    <fg=gray>  5</><fg=gray>▕ </><fg=magenta>{</>
    <fg=gray>  6</><fg=gray>▕ </><fg=magenta>    try {</>
<fg=red>  ➜ </>  7<fg=gray>▕ </><fg=magenta>        throw new \Exception(</><fg=gray>'Something went wrong'</><fg=magenta>);</>
    <fg=gray>  8</><fg=gray>▕ </><fg=magenta>    } catch (\Throwable </>$e<fg=magenta>) {</>
    <fg=gray>  9</><fg=gray>▕ </><fg=magenta>        </>report<fg=magenta>(</>$e<fg=magenta>);</>
    <fg=gray> 10</><fg=gray>▕ </><fg=magenta>    }</>
    <fg=gray> 11</><fg=gray>▕ </><fg=magenta>}</>
HTML
    );
});

it('renders the element with selected line', function () {
    $html = parse(<<<'HTML'
<div>
            <code line="7">
            &lt;?php

            /** @test */
            function sentryReport()
            {
                try {
                    throw new \Exception('Something went wrong');
                } catch (\Throwable $e) {
                    report($e);
                }
            }
            </code>
</div>
HTML
    );

    expect($html)->toBe(<<<'HTML'

    <fg=gray>  1</><fg=gray>▕ </><?php
    <fg=gray>  2</><fg=gray>▕ </>
    <fg=gray>  3</><fg=gray>▕ </><fg=gray>/** @test */</>
    <fg=gray>  4</><fg=gray>▕ </><fg=magenta>function </>sentryReport<fg=magenta>()</>
    <fg=gray>  5</><fg=gray>▕ </><fg=magenta>{</>
    <fg=gray>  6</><fg=gray>▕ </><fg=magenta>    try {</>
<fg=red>  ➜ </>  7<fg=gray>▕ </><fg=magenta>        throw new \Exception(</><fg=gray>'Something went wrong'</><fg=magenta>);</>
    <fg=gray>  8</><fg=gray>▕ </><fg=magenta>    } catch (\Throwable </>$e<fg=magenta>) {</>
    <fg=gray>  9</><fg=gray>▕ </><fg=magenta>        </>report<fg=magenta>(</>$e<fg=magenta>);</>
    <fg=gray> 10</><fg=gray>▕ </><fg=magenta>    }</>
    <fg=gray> 11</><fg=gray>▕ </><fg=magenta>}</>
HTML
    );
});

it('renders the element with selected line and started line', function () {
    $html = parse(<<<'HTML'
    <div>
        <code line="20" start-line="14">
            &lt;?php

            /** @test */
            function sentryReport()
            {
                try {
                    throw new \Exception('Something went wrong');
                } catch (\Throwable $e) {
                    report($e);
                }
            }
        </code>
    </div>
HTML
    );

    expect($html)->toBe(<<<'HTML'

    <fg=gray> 14</><fg=gray>▕ </><fg=blue>    </><?php
    <fg=gray> 15</><fg=gray>▕ </>
    <fg=gray> 16</><fg=gray>▕ </>    <fg=gray>/** @test */</>
    <fg=gray> 17</><fg=gray>▕ </><fg=gray>    </><fg=magenta>function </>sentryReport<fg=magenta>()</>
    <fg=gray> 18</><fg=gray>▕ </><fg=magenta>    {</>
    <fg=gray> 19</><fg=gray>▕ </><fg=magenta>        try {</>
<fg=red>  ➜ </> 20<fg=gray>▕ </><fg=magenta>            throw new \Exception(</><fg=gray>'Something went wrong'</><fg=magenta>);</>
    <fg=gray> 21</><fg=gray>▕ </><fg=magenta>        } catch (\Throwable </>$e<fg=magenta>) {</>
    <fg=gray> 22</><fg=gray>▕ </><fg=magenta>            </>report<fg=magenta>(</>$e<fg=magenta>);</>
    <fg=gray> 23</><fg=gray>▕ </><fg=magenta>        }</>
    <fg=gray> 24</><fg=gray>▕ </><fg=magenta>    }</>
HTML
    );
});