Skip to content

Commit

Permalink
Add python unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdancondorachi committed May 16, 2024
1 parent 6de46b1 commit 14bd226
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/Languages/Python/PythonLanguageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\Tests\Languages\Python;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Tempest\Highlight\Highlighter;

class PythonLanguageTest extends TestCase
{
#[DataProvider('data')]
public function test_highlight(string $content, string $expected): void
{
$highlighter = new Highlighter();

$this->assertSame(

Check failure on line 18 in tests/Languages/Python/PythonLanguageTest.php

View workflow job for this annotation

GitHub Actions / Run Tests - P8.3 - prefer-stable - ubuntu-latest

Failed asserting that two strings are identical.
$expected,
$highlighter->parse($content, 'python'),
);

$this->assertSame(
$expected,
$highlighter->parse($content, 'py'),
);
}

public static function data(): array
{
return [
[<<<TXT
def fib(n): # write Fibonacci series up to n
"""Print a Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print(a, end=' ')
a, b = b, a+b
print()
# Now call the function we just defined:
fib(2000)
TXT,
<<<TXT
<span class="hl-keyword">def</span> <span class="hl-property">fib</span>(n): <span class="hl-comment"># write Fibonacci series up to n</span>
<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> 0, 1
<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>')
a, b <span class="hl-operator">=</span> b, a<span class="hl-operator">+</span>b
<span class="hl-type">print</span>()
<span class="hl-comment"># Now call the function we just defined:</span>
fib(2000)
TXT],
];
}
}

0 comments on commit 14bd226

Please sign in to comment.