packages/lemon-parser/tests/Unit/Preprocessor/ExclusionTest.php

1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Preprocessor;
6
7use LemonParser\Preprocessor\Exclusion;
8use PHPUnit\Framework\Attributes\CoversClass;
9use PHPUnit\Framework\Attributes\Small;
10use PHPUnit\Framework\TestCase;
11
12#[CoversClass(Exclusion::class)]
13#[Small]
14final class ExclusionTest extends TestCase
15{
16    public function testDepth(): void
17    {
18        $exclusion = new Exclusion();
19
20        self::assertSame(0, $exclusion->depth());
21        $exclusion->enter(10, 2);
22        self::assertSame(1, $exclusion->depth());
23    }
24
25    public function testStart(): void
26    {
27        $exclusion = new Exclusion();
28        $exclusion->enter(10, 2);
29
30        self::assertSame(10, $exclusion->start());
31    }
32
33    public function testStartLine(): void
34    {
35        $exclusion = new Exclusion();
36        $exclusion->enter(10, 2);
37
38        self::assertSame(2, $exclusion->startLine());
39    }
40
41    public function testEnter(): void
42    {
43        $exclusion = new Exclusion();
44        $exclusion->enter(10, 2);
45        $exclusion->nest();
46
47        $exclusion->enter(20, 5);
48
49        self::assertSame([1, 20, 5], [$exclusion->depth(), $exclusion->start(), $exclusion->startLine()]);
50    }
51
52    public function testNest(): void
53    {
54        $exclusion = new Exclusion();
55        $exclusion->enter(10, 2);
56
57        $exclusion->nest();
58
59        self::assertSame(2, $exclusion->depth());
60    }
61
62    public function testLeave(): void
63    {
64        $exclusion = new Exclusion();
65        $exclusion->enter(10, 2);
66        $exclusion->nest();
67
68        self::assertFalse($exclusion->leave());
69        self::assertTrue($exclusion->leave());
70        self::assertSame(0, $exclusion->depth());
71    }
72}
73