-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6de46b1
commit 14bd226
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
$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">"""Print a Fibonacci series up to n."""</span> | ||
a, b <span class="hl-operator">=</span> 0, 1 | ||
<span class="hl-keyword">while</span> a <span class="hl-operator"><</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], | ||
]; | ||
} | ||
} |