Skip to content

Commit

Permalink
Merge pull request #149 from lemmon/strings-update
Browse files Browse the repository at this point in the history
Update strings for PHP and JavaScript
  • Loading branch information
brendt authored Oct 24, 2024
2 parents 2d119af + a299614 commit dc2e025
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

#[PatternTest(
input: 'return "hello"',
output: 'hello',
output: '"hello"',
)]
final readonly class JsDoubleQuoteValuePattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '"(?<match>.*?)"';
return '(?<match>"(\\\"|.)*?")';
}

public function getTokenType(): TokenTypeEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

#[PatternTest(
input: "return 'hello';",
output: 'hello',
output: "'hello'",
)]
final readonly class JsSingleQuoteValuePattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return "'(?<match>.*?)'";
return "(?<match>'(\\\'|.)*?')";
}

public function getTokenType(): TokenTypeEnum
Expand Down
4 changes: 2 additions & 2 deletions src/Languages/Php/Patterns/DoubleQuoteValuePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

#[PatternTest(
input: 'return "hello"',
output: 'hello',
output: '"hello"',
)]
final readonly class DoubleQuoteValuePattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '"(?<match>.*?)"';
return '(?<match>"(\\\"|.)*?")';
}

public function getTokenType(): TokenTypeEnum
Expand Down
12 changes: 10 additions & 2 deletions src/Languages/Php/Patterns/SingleQuoteValuePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,23 @@

#[PatternTest(
input: "return 'hello';",
output: 'hello',
output: "'hello'",
)]
#[PatternTest(
input: "echo 'Yo\\';",
output: "'Yo\\'",
)]
#[PatternTest(
input: "echo 'Very \'long\'\\\'annoying\' string';",
output: "'Very \'long\'\\\'annoying\' string'",
)]
final readonly class SingleQuoteValuePattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return "'(?<match>.*?)'";
return "(?<match>'(\\\'|.)*?')";
}

public function getTokenType(): TokenTypeEnum
Expand Down
6 changes: 3 additions & 3 deletions tests/Languages/Base/Injections/GutterInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public function test_gutter_injection(): void
<span class="hl-gutter"> 10</span><span class="hl-keyword">foreach</span> (<span class="hl-variable">$lines</span> <span class="hl-keyword">as</span> <span class="hl-variable">$i</span> =&gt; <span class="hl-variable">$line</span>) {
<span class="hl-gutter"> 11</span> <span class="hl-variable">$gutterNumber</span> = <span class="hl-variable">$gutterNumbers</span>[<span class="hl-variable">$i</span>];
<span class="hl-gutter"> 12</span>
<span class="hl-gutter"> 13</span> <span class="hl-variable">$gutterClass</span> = '<span class="hl-value">hl-gutter </span>' . (<span class="hl-variable">$this</span>-&gt;<span class="hl-property">classes</span>[<span class="hl-variable">$i</span> + 1] ?? '<span class="hl-value"></span>');
<span class="hl-gutter"> 13</span> <span class="hl-variable">$gutterClass</span> = <span class="hl-value">'hl-gutter '</span> . (<span class="hl-variable">$this</span>-&gt;<span class="hl-property">classes</span>[<span class="hl-variable">$i</span> + 1] ?? <span class="hl-value">''</span>);
<span class="hl-gutter hl-gutter-addition">14 +</span><span class="hl-addition"></span>
<span class="hl-gutter hl-gutter-addition">15 +</span><span class="hl-addition"> <span class="hl-variable">$lines</span>[<span class="hl-variable">$i</span>] = <span class="hl-property">sprintf</span>(</span>
<span class="hl-gutter hl-gutter-addition">16 +</span><span class="hl-addition"> <span class="hl-type">Escape</span>::<span class="hl-property">tokens</span>('<span class="hl-value">&lt;span class=&quot;%s&quot;&gt;%s&lt;/span&gt;%s</span>'),</span>
<span class="hl-gutter hl-gutter-addition">16 +</span><span class="hl-addition"> <span class="hl-type">Escape</span>::<span class="hl-property">tokens</span>(<span class="hl-value">'&lt;span class=&quot;%s&quot;&gt;%s&lt;/span&gt;%s'</span>),</span>
<span class="hl-gutter"> 17</span> <span class="hl-variable">$gutterClass</span>,
<span class="hl-gutter"> 18</span> <span class="hl-property">str_pad</span>(
<span class="hl-gutter hl-gutter-deletion">19 -</span> <span class="hl-property">string</span>: <span class="hl-deletion"><span class="hl-variable">$gutterNumber</span></span>,
Expand Down Expand Up @@ -128,7 +128,7 @@ public function test_gutter_injection_terminal(): void
TXT;

$expected = <<<'TXT'
ICAxMCAbWzM0bWZvcmVhY2gbWzBtICgbWzBtJGxpbmVzG1swbSAbWzM0bWFzG1swbSAbWzBtJGkbWzBtID0+IBtbMG0kbGluZRtbMG0pIHsKICAxMSAgICAgG1swbSRndXR0ZXJOdW1iZXIbWzBtID0gG1swbSRndXR0ZXJOdW1iZXJzG1swbVsbWzBtJGkbWzBtXTsKICAxMiAKICAxMyAgICAgG1swbSRndXR0ZXJDbGFzcxtbMG0gPSAnG1szMG1obC1ndXR0ZXIgG1swbScgLiAoG1swbSR0aGlzG1swbS0+G1szMm1jbGFzc2VzG1swbVsbWzBtJGkbWzBtICsgMV0gPz8gJxtbMzBtG1swbScpOwoxNCArIBtbMG0bWzBtCjE1ICsgICAgIBtbMG0kbGluZXMbWzBtWxtbMG0kaRtbMG1dID0gG1szMm1zcHJpbnRmG1swbSgKMTYgKyAgICAgICAgIBtbMzFtRXNjYXBlG1swbTo6G1szMm10b2tlbnMbWzBtKCcbWzMwbTxzcGFuIGNsYXNzPSIlcyI+JXM8L3NwYW4+JXMbWzBtJyksG1swbRtbMG0KICAxNyAgICAgICAgIBtbMG0kZ3V0dGVyQ2xhc3MbWzBtLAogIDE4ICAgICAgICAgG1szMm1zdHJfcGFkG1swbSgKMTkgLSAgICAgICAgICAgICAbWzMybXN0cmluZxtbMG06IBtbMG0bWzBtG1swbSRndXR0ZXJOdW1iZXIbWzBtG1swbRtbMG0sCiAgMjAgICAgICAgICAgICAgG1szMm1sZW5ndGgbWzBtOiAbWzBtJGd1dHRlcldpZHRoG1swbSwKICAyMSAgICAgICAgICAgICAbWzMybXBhZF90eXBlG1swbTogG1szMm1TV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7CiAgMjUgfQ==
TXT;

$highlighter = (new Highlighter(new LightTerminalTheme()))->withGutter(10);
Expand Down
20 changes: 10 additions & 10 deletions tests/Languages/JavaScript/JavaScriptLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ function getMandatedParams() {
<span class="hl-comment">// ...</span>
qq.<span class="hl-property">DeleteFileAjaxRequester</span> = <span class="hl-keyword">function</span>(o) {
&quot;<span class="hl-value">use strict</span>&quot;;
<span class="hl-value">&quot;use strict&quot;</span>;
<span class="hl-keyword">var</span> requester,
options = {
<span class="hl-property">method</span>: &quot;<span class="hl-value">DELETE</span>&quot;,
<span class="hl-property">uuidParamName</span>: &quot;<span class="hl-value">qquuid</span>&quot;,
<span class="hl-property">method</span>: <span class="hl-value">&quot;DELETE&quot;</span>,
<span class="hl-property">uuidParamName</span>: <span class="hl-value">&quot;qquuid&quot;</span>,
<span class="hl-property">endpointStore</span>: {},
<span class="hl-property">maxConnections</span>: 3,
<span class="hl-property">customHeaders</span>: <span class="hl-keyword">function</span>(id) {<span class="hl-keyword">return</span> {};},
Expand All @@ -148,18 +148,18 @@ function getMandatedParams() {
qq.<span class="hl-property">extend</span>(options, o);
<span class="hl-keyword">function</span> <span class="hl-property">getMandatedParams</span>() {
<span class="hl-keyword">if</span> (options.<span class="hl-property">method</span>.<span class="hl-property">toUpperCase</span>() === &quot;<span class="hl-value">POST</span>&quot;) {
<span class="hl-keyword">if</span> (options.<span class="hl-property">method</span>.<span class="hl-property">toUpperCase</span>() === <span class="hl-value">&quot;POST&quot;</span>) {
<span class="hl-keyword">return</span> {
<span class="hl-property">_method</span>: &quot;<span class="hl-value">DELETE</span>&quot;
<span class="hl-property">_method</span>: <span class="hl-value">&quot;DELETE&quot;</span>
};
}
<span class="hl-keyword">return</span> {};
}
requester = qq.<span class="hl-property">extend</span>(<span class="hl-keyword">this</span>, <span class="hl-keyword">new</span> qq.<span class="hl-type">AjaxRequester</span>({
<span class="hl-property">acceptHeader</span>: &quot;<span class="hl-value">application/json</span>&quot;,
<span class="hl-property">validMethods</span>: [&quot;<span class="hl-value">POST</span>&quot;, &quot;<span class="hl-value">DELETE</span>&quot;],
<span class="hl-property">acceptHeader</span>: <span class="hl-value">&quot;application/json&quot;</span>,
<span class="hl-property">validMethods</span>: [<span class="hl-value">&quot;POST&quot;</span>, <span class="hl-value">&quot;DELETE&quot;</span>],
<span class="hl-property">method</span>: options.<span class="hl-property">method</span>,
<span class="hl-property">endpointStore</span>: options.<span class="hl-property">endpointStore</span>,
<span class="hl-property">paramsStore</span>: options.<span class="hl-property">paramsStore</span>,
Expand All @@ -178,9 +178,9 @@ function getMandatedParams() {
<span class="hl-property">sendDelete</span>: <span class="hl-keyword">function</span>(id, uuid, additionalMandatedParams) {
<span class="hl-keyword">var</span> additionalOptions = additionalMandatedParams || {};
options.<span class="hl-property">log</span>(&quot;<span class="hl-value">Submitting delete file request for </span>&quot; + id);
options.<span class="hl-property">log</span>(<span class="hl-value">&quot;Submitting delete file request for &quot;</span> + id);
<span class="hl-keyword">if</span> (options.<span class="hl-property">method</span> === &quot;<span class="hl-value">DELETE</span>&quot;) {
<span class="hl-keyword">if</span> (options.<span class="hl-property">method</span> === <span class="hl-value">&quot;DELETE&quot;</span>) {
requester.<span class="hl-property">initTransport</span>(id)
.<span class="hl-property">withPath</span>(uuid)
.<span class="hl-property">withParams</span>(additionalOptions)
Expand Down Expand Up @@ -230,7 +230,7 @@ class Point {
<span class="hl-keyword">this</span>.<span class="hl-property">y</span> = y;
}
<span class="hl-keyword">static</span> <span class="hl-property">displayName</span> = &quot;<span class="hl-value">Point</span>&quot;;
<span class="hl-keyword">static</span> <span class="hl-property">displayName</span> = <span class="hl-value">&quot;Point&quot;</span>;
<span class="hl-keyword">static</span> <span class="hl-property">distance</span>(a, b) {
<span class="hl-keyword">const</span> dx = a.<span class="hl-property">x</span> - b.<span class="hl-property">x</span>;
<span class="hl-keyword">const</span> dy = a.<span class="hl-property">y</span> - b.<span class="hl-property">y</span>;
Expand Down
20 changes: 10 additions & 10 deletions tests/Languages/Php/PhpLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public function test_highlight(string $content, string $expected): void
public static function data(): array
{
return [
["'php()'", "'<span class=\"hl-value\">php()</span>'"],
["#[PatternTest(input: 'new Foo()', output: 'Foo')]", '<span class="hl-injection"><span class="hl-attribute">#[<span class="hl-type">PatternTest</span>(<span class="hl-property">input</span>: \'<span class="hl-value">new Foo()</span>\', <span class="hl-property">output</span>: \'<span class="hl-value">Foo</span>\')]</span></span>'],
["'php()'", "<span class=\"hl-value\">'php()'</span>"],
["#[PatternTest(input: 'new Foo()', output: 'Foo')]", '<span class="hl-injection"><span class="hl-attribute">#[<span class="hl-type">PatternTest</span>(<span class="hl-property">input</span>: <span class="hl-value">\'new Foo()\'</span>, <span class="hl-property">output</span>: <span class="hl-value">\'Foo\'</span>)]</span></span>'],
['$foo && $bar', '<span class="hl-variable">$foo</span> <span class="hl-operator">&amp;&amp;</span> <span class="hl-variable">$bar</span>'],
['$foo || $bar', '<span class="hl-variable">$foo</span> <span class="hl-operator">||</span> <span class="hl-variable">$bar</span>'],
['$foo <=> $bar', '<span class="hl-variable">$foo</span> <span class="hl-operator">&lt;=&gt;</span> <span class="hl-variable">$bar</span>'],
["public const string|\Stringable MESSAGE = 'hi';", '<span class="hl-keyword">public</span> <span class="hl-keyword">const</span> <span class="hl-type">string|\Stringable</span> <span class="hl-property">MESSAGE</span> = \'<span class="hl-value">hi</span>\';'],
["public const string|\Stringable MESSAGE = 'hi';", '<span class="hl-keyword">public</span> <span class="hl-keyword">const</span> <span class="hl-type">string|\Stringable</span> <span class="hl-property">MESSAGE</span> = <span class="hl-value">\'hi\'</span>;'],
["public string|\Stringable \$message;", '<span class="hl-keyword">public</span> <span class="hl-type">string|\Stringable</span> <span class="hl-property">$message</span>;'],
['for($x = 0; $x < 150; $x++) {', '<span class="hl-keyword">for</span>(<span class="hl-variable">$x</span> = 0; <span class="hl-variable">$x</span> &lt; 150; <span class="hl-variable">$x</span>++) {'],
["'namespace ';", "'<span class=\"hl-value\">namespace </span>';"],
["'namespace ';", "<span class=\"hl-value\">'namespace '</span>;"],
["static::foo()", '<span class="hl-keyword">static</span>::<span class="hl-property">foo</span>()'],
['$class', '<span class="hl-variable">$class</span>'],
['protected $resolved = [];', '<span class="hl-keyword">protected</span> <span class="hl-property">$resolved</span> = [];'],
Expand All @@ -50,7 +50,7 @@ public static function data(): array
['fn&(', '<span class="hl-keyword">fn</span>&amp;('],
['enum Foo: string', '<span class="hl-keyword">enum</span> <span class="hl-type">Foo</span>: <span class="hl-type">string</span>'],
['case Foo;', '<span class="hl-keyword">case</span> <span class="hl-property">Foo</span>;'],
['$this->extends("View/base.view.php");', '<span class="hl-variable">$this</span>-&gt;<span class="hl-property">extends</span>(&quot;<span class="hl-value">View/base.view.php</span>&quot;);'],
['$this->extends("View/base.view.php");', '<span class="hl-variable">$this</span>-&gt;<span class="hl-property">extends</span>(<span class="hl-value">&quot;View/base.view.php&quot;</span>);'],
['$foo = null;', '<span class="hl-variable">$foo</span> = <span class="hl-keyword">null</span>;'],
['$foo = true;', '<span class="hl-variable">$foo</span> = <span class="hl-keyword">true</span>;'],
['$foo = false;', '<span class="hl-variable">$foo</span> = <span class="hl-keyword">false</span>;'],
Expand All @@ -66,8 +66,8 @@ public static function data(): array
set (string $value) => $this->first . " " . $this->last;
}',
'<span class="hl-keyword">public</span> <span class="hl-type">string</span> <span class="hl-property">$fullName</span> {
<span class="hl-keyword">get</span> =&gt; <span class="hl-variable">$this</span>-&gt;<span class="hl-property">first</span> . &quot;<span class="hl-value"> </span>&quot; . <span class="hl-variable">$this</span>-&gt;<span class="hl-property">last</span>;
<span class="hl-keyword">set</span> (<span class="hl-type">string</span> <span class="hl-variable">$value</span>) =&gt; <span class="hl-variable">$this</span>-&gt;<span class="hl-property">first</span> . &quot;<span class="hl-value"> </span>&quot; . <span class="hl-variable">$this</span>-&gt;<span class="hl-property">last</span>;
<span class="hl-keyword">get</span> =&gt; <span class="hl-variable">$this</span>-&gt;<span class="hl-property">first</span> . <span class="hl-value">&quot; &quot;</span> . <span class="hl-variable">$this</span>-&gt;<span class="hl-property">last</span>;
<span class="hl-keyword">set</span> (<span class="hl-type">string</span> <span class="hl-variable">$value</span>) =&gt; <span class="hl-variable">$this</span>-&gt;<span class="hl-property">first</span> . <span class="hl-value">&quot; &quot;</span> . <span class="hl-variable">$this</span>-&gt;<span class="hl-property">last</span>;
}',
],
[
Expand All @@ -86,9 +86,9 @@ public function info(
<span class="hl-attribute">#[<span class="hl-type">ConsoleCommand</span>]</span>
<span class="hl-keyword">public</span> <span class="hl-keyword">function</span> <span class="hl-property">info</span>(<span class="hl-injection">
</span><span class="hl-injection"><span class="hl-attribute">#[<span class="hl-type">ConsoleArgument</span>(
<span class="hl-property">description</span>: '<span class="hl-value"><span class="hl-value">The name of the package</span></span>',
<span class="hl-property">help</span>: '<span class="hl-value"><span class="hl-value">Extended help text for this argument</span></span>',
<span class="hl-property">aliases</span>: ['<span class="hl-value"><span class="hl-value">n</span></span>'],
<span class="hl-property">description</span>: <span class="hl-value"><span class="hl-value">'The name of the package'</span></span>,
<span class="hl-property">help</span>: <span class="hl-value"><span class="hl-value">'Extended help text for this argument'</span></span>,
<span class="hl-property">aliases</span>: [<span class="hl-value"><span class="hl-value">'n'</span></span>],
)]</span></span><span class="hl-injection">
<span class="hl-type">string</span> $name
</span>): <span class="hl-type">void</span> {}
Expand Down
2 changes: 1 addition & 1 deletion tests/Languages/Python/PythonLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function data(): array
<span class="hl-value">&quot;&quot;&quot;Print a Fibonacci series up to n.&quot;&quot;&quot;</span>
a, b <span class="hl-operator">=</span> <span class="hl-number">0</span>, <span class="hl-number">1</span>
<span class="hl-keyword">while</span> a <span class="hl-operator">&lt;</span> n:
<span class="hl-type">print</span>(a, <span class="hl-variable">end</span><span class="hl-operator">=</span>'<span class="hl-value"> </span>')
<span class="hl-type">print</span>(a, <span class="hl-variable">end</span><span class="hl-operator">=</span><span class="hl-value">' '</span>)
a, b <span class="hl-operator">=</span> b, a<span class="hl-operator">+</span>b
<span class="hl-type">print</span>()
Expand Down
Loading

0 comments on commit dc2e025

Please sign in to comment.