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"><?php</code>
</div>
HTML
);
expect($html)->toBe(<<<'HTML'
<fg=gray>11400</><fg=gray>▕ </>[1m<?php[0m
HTML
);
});
it('renders the element with multiline code', function () {
$html = parse(<<<'HTML'
<div>
<code line="7">
<?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>▕ </>[1m<?php[0m
<fg=gray> 2</><fg=gray>▕ </>
<fg=gray> 3</><fg=gray>▕ </><fg=gray>[3m/** @test */[0m</>
<fg=gray> 4</><fg=gray>▕ </><fg=magenta>[1mfunction [0m</>[1msentryReport[0m<fg=magenta>[1m()[0m</>
<fg=gray> 5</><fg=gray>▕ </><fg=magenta>[1m{[0m</>
<fg=gray> 6</><fg=gray>▕ </><fg=magenta>[1m try {[0m</>
<fg=red>[1m ➜ [0m</>[1m[3m 7[0m[0m<fg=gray>▕ </><fg=magenta>[1m throw new \Exception([0m</><fg=gray>'Something went wrong'</><fg=magenta>[1m);[0m</>
<fg=gray> 8</><fg=gray>▕ </><fg=magenta>[1m } catch (\Throwable [0m</>[1m$e[0m<fg=magenta>[1m) {[0m</>
<fg=gray> 9</><fg=gray>▕ </><fg=magenta>[1m [0m</>[1mreport[0m<fg=magenta>[1m([0m</>[1m$e[0m<fg=magenta>[1m);[0m</>
<fg=gray> 10</><fg=gray>▕ </><fg=magenta>[1m }[0m</>
<fg=gray> 11</><fg=gray>▕ </><fg=magenta>[1m}[0m</>
HTML
);
});
it('renders the element with selected line', function () {
$html = parse(<<<'HTML'
<div>
<code line="7">
<?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>▕ </>[1m<?php[0m
<fg=gray> 2</><fg=gray>▕ </>
<fg=gray> 3</><fg=gray>▕ </><fg=gray>[3m/** @test */[0m</>
<fg=gray> 4</><fg=gray>▕ </><fg=magenta>[1mfunction [0m</>[1msentryReport[0m<fg=magenta>[1m()[0m</>
<fg=gray> 5</><fg=gray>▕ </><fg=magenta>[1m{[0m</>
<fg=gray> 6</><fg=gray>▕ </><fg=magenta>[1m try {[0m</>
<fg=red>[1m ➜ [0m</>[1m[3m 7[0m[0m<fg=gray>▕ </><fg=magenta>[1m throw new \Exception([0m</><fg=gray>'Something went wrong'</><fg=magenta>[1m);[0m</>
<fg=gray> 8</><fg=gray>▕ </><fg=magenta>[1m } catch (\Throwable [0m</>[1m$e[0m<fg=magenta>[1m) {[0m</>
<fg=gray> 9</><fg=gray>▕ </><fg=magenta>[1m [0m</>[1mreport[0m<fg=magenta>[1m([0m</>[1m$e[0m<fg=magenta>[1m);[0m</>
<fg=gray> 10</><fg=gray>▕ </><fg=magenta>[1m }[0m</>
<fg=gray> 11</><fg=gray>▕ </><fg=magenta>[1m}[0m</>
HTML
);
});
it('renders the element with selected line and started line', function () {
$html = parse(<<<'HTML'
<div>
<code line="20" start-line="14">
<?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>[1m [0m</>[1m<?php[0m
<fg=gray> 15</><fg=gray>▕ </>
<fg=gray> 16</><fg=gray>▕ </>[1m [0m<fg=gray>[3m/** @test */[0m</>
<fg=gray> 17</><fg=gray>▕ </><fg=gray>[3m [0m</><fg=magenta>[1mfunction [0m</>[1msentryReport[0m<fg=magenta>[1m()[0m</>
<fg=gray> 18</><fg=gray>▕ </><fg=magenta>[1m {[0m</>
<fg=gray> 19</><fg=gray>▕ </><fg=magenta>[1m try {[0m</>
<fg=red>[1m ➜ [0m</>[1m[3m 20[0m[0m<fg=gray>▕ </><fg=magenta>[1m throw new \Exception([0m</><fg=gray>'Something went wrong'</><fg=magenta>[1m);[0m</>
<fg=gray> 21</><fg=gray>▕ </><fg=magenta>[1m } catch (\Throwable [0m</>[1m$e[0m<fg=magenta>[1m) {[0m</>
<fg=gray> 22</><fg=gray>▕ </><fg=magenta>[1m [0m</>[1mreport[0m<fg=magenta>[1m([0m</>[1m$e[0m<fg=magenta>[1m);[0m</>
<fg=gray> 23</><fg=gray>▕ </><fg=magenta>[1m }[0m</>
<fg=gray> 24</><fg=gray>▕ </><fg=magenta>[1m }[0m</>
HTML
);
});
|